summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: ec3eb11cc273cf9ea33261e53d78f406f0034e28 (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
#################################################
#
#  (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.6 )


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

project( libr )
set( PACKAGE libr )
set( VERSION 0.6.0 )


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

include( FindPkgConfig )
include( CheckIncludeFile )


##### 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 )
    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 )
    set( BACKEND_LIBRARIES "-lbfd" )
    set( LIBR_BACKEND "bfd" )
    set( BACKEND_NAME "libbfd" )

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( 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()