summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: f07b74601b3efb75da6b826fae22339aff43498b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#################################################
#
#  (C) 2014 Slávek Banko
#  slavek (DOT) banko (AT) axis.cz
#
#  Improvements and feedback are welcome
#
#  This file is released under GPL >= 2
#
#################################################

cmake_minimum_required( VERSION 2.8.12 )


##### general package setup #####################

project( libr )
set( PACKAGE libr )
set( VERSION R14.1.0 )
set( PACKAGE_VERSION 0.6.0 )


##### include essential cmake modules ###########

include( FindPkgConfig )
include( CheckIncludeFile )
include( CheckFunctionExists )
include( CheckLibraryExists )
include( CheckSymbolExists )


##### include our cmake modules #################

set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" )
include( TDEMacros )


##### setup install paths #######################

include( TDESetupPaths )
tde_setup_paths( )


##### optional stuff ############################

option( WITH_BACKEND_LIBBFD "Build with libbfd backend" "ON" )
option( WITH_BACKEND_LIBELF "Build with libelf backend" "OFF" )
option( WITH_BACKEND_READONLY "Build with read-only backend" "OFF" )


#### configure checks ###########################

if( WITH_BACKEND_LIBBFD )
    tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "-DPACKAGE" "-DPACKAGE_VERSION" )
    check_include_file( bfd.h HAVE_BFD_H )
    if( NOT HAVE_BFD_H )
        tde_message_fatal( "Could not find libbfd header file (bfd.h)!\nThis file is usually included in the package binutils-dev." )
    endif( NOT HAVE_BFD_H )
    tde_save_and_set( CMAKE_REQUIRED_LIBRARIES "bfd" )
    check_symbol_exists( bfd_asymbol_section bfd.h HAVE_BFD_2_34 )
    tde_restore( CMAKE_REQUIRED_DEFINITIONS )
    tde_restore( CMAKE_REQUIRED_LIBRARIES )
    set( BACKEND_LIBRARIES "-lbfd" )
    set( LIBR_BACKEND "bfd" )
    set( BACKEND_NAME "libbfd" )

    check_include_file( libiberty.h HAVE_LIBIBERTY_H )
    if( HAVE_LIBIBERTY_H )
        list( APPEND BACKEND_LIBRARIES "-liberty" )
    endif( HAVE_LIBIBERTY_H )

elseif( WITH_BACKEND_LIBELF )
    # Is libelf 0.8.2 safe enough? testing is currently on 0.8.6
    pkg_search_module( BACKEND libelf>=0.8.2 )
    if( NOT BACKEND_FOUND )
        tde_message_fatal( "libelf >= 0.8.2 are required, but not found on your system" )
    endif( NOT BACKEND_FOUND )
    set( LIBR_BACKEND "elf" )
    set( BACKEND_NAME "libelf" )

elseif( WITH_BACKEND_READONLY )
    set( BACKEND_NAME "readonly" )
    set( LIBR_BACKEND "ro" )

else( )
    tde_message_fatal( "Backend is not selected, cannot build." )
endif( )


find_package( ZLIB )
if( NOT ZLIB_FOUND )
    tde_message_fatal( "zlib are required, but not found on your system" )
endif( NOT ZLIB_FOUND )

pkg_search_module( LIBGLADE libglade-2.0>=2.0.0 )
if( NOT LIBGLADE_FOUND )
    tde_message_fatal( "libglade-2.0 are required, but not found on your system" )
endif( NOT LIBGLADE_FOUND )

set( DL_LIBRARIES dl )
check_library_exists( ${DL_LIBRARIES} dlopen /lib HAVE_LIBDL )
if( NOT HAVE_LIBDL )
  unset( DL_LIBRARIES )
  check_function_exists( dlopen HAVE_DLOPEN )
  if( HAVE_DLOPEN )
    set( HAVE_LIBDL 1 )
  endif( HAVE_DLOPEN )
endif( NOT HAVE_LIBDL )

set( EXTRA_LIBRARIES "-lm -lpthread" )
if( UNIX )
  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden" )
endif( UNIX )

message( STATUS "Ready to build with backend ${BACKEND_NAME}" )


#### pkg-config #################################

set( prefix      ${CMAKE_INSTALL_PREFIX} )
set( exec_prefix ${EXEC_INSTALL_PREFIX} )
set( libdir      ${LIB_INSTALL_DIR} )
set( includedir  ${INCLUDE_INSTALL_DIR}/libr )

configure_file( libr.pc.in libr.pc @ONLY )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libr.pc
         DESTINATION ${PKGCONFIG_INSTALL_DIR} )


##### build #####################################

tde_auto_add_subdirectories()


##### write configure files #####################

configure_file( src/config.h.cmake config.h @ONLY )
configure_file( doc/libr.cfg.cmake doc/libr.cfg @ONLY )