-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
187 lines (160 loc) · 6.63 KB
/
CMakeLists.txt
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# our functions and macros
# logging_level_to_define()
# Gives the define corresponding to a global logging level.
#
# For example: The logging level 'INFO' corresponds to the define 'logINFO'.
#
# Parameters:
# LOGGING_LEVEL STRING One of the logging levels:
# NO_LOGGING, ERROR, WARNING, INFO, DEBUG, DEBUG1, (...), DEBUG4
# input parameter
#
# DEFINE STRING output parameter
#
MACRO(LOGGING_LEVEL_TO_DEFINE LOGGING_LEVEL DEFINE)
IF(${LOGGING_LEVEL} STREQUAL "NO_LOGGING")
SET(${DEFINE} "pgmlink::logNO_LOGGING")
ELSEIF(${LOGGING_LEVEL} STREQUAL "ERROR")
SET(${DEFINE} "pgmlink::logERROR")
ELSEIF(${LOGGING_LEVEL} STREQUAL "WARNING")
SET(${DEFINE} "pgmlink::logWARNING")
ELSEIF(${LOGGING_LEVEL} STREQUAL "INFO")
SET(${DEFINE} "pgmlink::logINFO")
ELSEIF(${LOGGING_LEVEL} STREQUAL "DEBUG")
SET(${DEFINE} "pgmlink::logDEBUG")
ELSEIF(${LOGGING_LEVEL} STREQUAL "DEBUG1")
SET(${DEFINE} "pgmlink::logDEBUG1")
ELSEIF(${LOGGING_LEVEL} STREQUAL "DEBUG2")
SET(${DEFINE} "pgmlink::logDEBUG2")
ELSEIF(${LOGGING_LEVEL} STREQUAL "DEBUG3")
SET(${DEFINE} "pgmlink::logDEBUG3")
ELSEIF(${LOGGING_LEVEL} STREQUAL "DEBUG4")
SET(${DEFINE} "pgmlink::logDEBUG4")
ELSE(${LOGGING_LEVEL} STREQUAL "NO_LOGGING")
MESSAGE(SEND_ERROR "Unknown LOGGING_LEVEL: ${LOGGING_LEVEL}. Default to INFO.")
SET(${DEFINE} "pgmlink::logINFO")
ENDIF(${LOGGING_LEVEL} STREQUAL "NO_LOGGING")
ENDMACRO(LOGGING_LEVEL_TO_DEFINE)
###########################################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(pgmlink)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_extensions/)
message( "\nConfiguring pgmlink:" )
# dependencies
find_package( ANN REQUIRED )
find_package( Cplex REQUIRED )
find_package( VIGRA REQUIRED )
find_package( Lemon REQUIRED )
find_package( Boost REQUIRED COMPONENTS serialization )
message(STATUS " found: ${Boost_LIBRARIES}")
if(WIN32)
# FindHDF5 is broken on Windows
# it wrongly discovers the dlls instead of the lib files
# see: www.cmake.org/Bug/bug_relationship_graph.php?bug_id=14111
# therefore we set the variable manually
find_library( HDF5_IMPORT_LIB hdf5dll )
find_library( HDF5_HL_IMPORT_LIB hdf5_hldll )
set( HDF5_LIBRARIES ${HDF5_IMPORT_LIB} ${HDF5_HL_IMPORT_LIB} )
message(STATUS "HDF5: autodiscovery is broken on WIN32; using global search paths")
message(STATUS "HDF5: found ${HDF5_LIBRARIES}")
else()
find_package( HDF5 REQUIRED COMPONENTS C HL)
endif()
include_directories(${PROJECT_SOURCE_DIR}/include/)
# include external headers as system includes so we do not have to cope with their warnings
include_directories(SYSTEM ${ANN_INCLUDE_DIR} ${CPLEX_INCLUDE_DIRS} ${VIGRA_INCLUDE_DIR} ${LEMON_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
# CPLEX switch to be compatible with STL
ADD_DEFINITIONS(-DIL_STD)
if(WIN32)
add_definitions(-DBOOST_ALL_DYN_LINK)
if("${Boost_LIBRARIES}" MATCHES "boost_serialization\\.lib")
ADD_DEFINITIONS(-DBOOST_AUTO_LINK_NOMANGLE)
endif()
endif()
## vigra defines
## assume that HDF5 is installed (for vigra random forest)
ADD_DEFINITIONS(-DHasHDF5)
# print out the dependencies
message(STATUS "Dependencies include dirs (you should check if they match the found libs):")
message(STATUS " ANN: ${ANN_INCLUDE_DIR}")
message(STATUS " Cplex: ${CPLEX_INCLUDE_DIR}")
message(STATUS " VIGRA: ${VIGRA_INCLUDE_DIR}")
message(STATUS " Lemon: ${LEMON_INCLUDE_DIR}")
message(STATUS " Boost: ${Boost_INCLUDE_DIRS}")
# hide these variables to have a cleaner interface
mark_as_advanced( Boost_DIR )
mark_as_advanced( HDF5_DIR ) # set by FindHDF5
# build options
# logging level
set(LOGGING_LEVEL "INFO" CACHE STRING "Choose a global logging level: NO_LOGGING, ERROR, WARNING, INFO, DEBUG, DEBUG1, ..., DEBUG4")
# unit tests
set(WITH_TESTS "False" CACHE BOOL "Build tests.")
# build type and compiler options
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Release Debug."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wfatal-errors -std=c++98 -pedantic -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Werror")
endif()
IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(WITH_CHECKED_STL "True" CACHE BOOL "Build with checked stl for more robust code (may degrade performance; gcc only).")
if(WITH_CHECKED_STL)
add_definitions(-D_GLIBCXX_DEBUG)
endif()
ENDIF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# global logging level
logging_level_to_define(LOGGING_LEVEL LOG_DEFINE)
add_definitions(-D FILELOG_MAX_LEVEL=${LOG_DEFINE})
# libpgmlink
include( GenerateExportHeader )
## only activate symbol export on Windows
if(NOT WIN32)
set(USE_COMPILER_HIDDEN_VISIBILITY OFF)
endif()
if(WIN32)
add_compiler_export_flags() # enable dynamic symbol export/import for shared libs (on Windows)
endif()
file(GLOB LIB_SOURCES src/*.cpp)
add_library(pgmlink SHARED ${LIB_SOURCES})
file( MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/pgmlink )
if(WIN32)
generate_export_header( pgmlink ) # generates pgmlink_export.h
file( RENAME ${CMAKE_CURRENT_BINARY_DIR}/pgmlink_export.h ${CMAKE_CURRENT_BINARY_DIR}/include/pgmlink/pgmlink_export.h )
else(WIN32)
configure_file(${CMAKE_SOURCE_DIR}/include/pgmlink/pgmlink_export.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/include/pgmlink/pgmlink_export.h
COPYONLY)
endif(WIN32)
include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include )
target_link_libraries(pgmlink ${ANN_LIBRARIES} ${Boost_LIBRARIES} ${CPLEX_LIBRARIES} ${VIGRA_IMPEX_LIBRARY} ${LEMON_LIBRARIES} ${HDF5_LIBRARIES} )
# Install target pgmlink
install(TARGETS pgmlink
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
# API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
else(DOXYGEN_FOUND)
MESSAGE(WARNING "Doxygen not found. Won't add 'doc' build target.")
endif(DOXYGEN_FOUND)
# Tests
if(WITH_TESTS)
enable_testing()
add_subdirectory(tests/)
endif()
# Python
SET(WITH_PYTHON true CACHE BOOL "Build with python wrapper.")
if(WITH_PYTHON)
add_subdirectory(python/)
endif()