-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
235 lines (193 loc) · 6.39 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
##############
### Tomato ###
##############
# you can build tomato with command:
# cmake .
# -DCMAKE_BUILD_TYPE=RELEASE
# -DCMAKE_INSTALL_PREFIX="install"
# additionally for osx:
# -DCMAKE_MACOSX_RPATH=1
# additionally for windows:
# -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON
# additionally for linux:
# -DCMAKE_POSITION_INDEPENDENT_CODE=ON
# see .travis.yml and appveyor.yml for examples
#
# Konrad Werys
cmake_minimum_required(VERSION 2.8.12)
#set(ENV{SDKROOT} "/Library/Developer/CommandLineTools_clang12/SDKs/MacOSX10.15.sdk")
#set(CMAKE_OSX_DEPLOYMENT_TARGET CACHE STRING "10.15")
project(Tomato)
# The version number
set(Tomato_VERSION_MAJOR 0)
set(Tomato_VERSION_MINOR 6)
set(Tomato_VERSION_PATCH 6)
# Compiler flags
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 98 CACHE STRING "")
set(TOMATO_USES_CXX_STANDARD_98 OFF)
if(CMAKE_CXX_STANDARD EQUAL 98)
set(TOMATO_USES_CXX_STANDARD_98 ON) # flag used in the code
endif()
# needed for conan
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR} ${CMAKE_PREFIX_PATH})
#####################
### BUILD OPTIONS ###
#####################
set(USE_ITK ON CACHE BOOL "Do you want to use ITK?")
set(USE_VNL ON CACHE BOOL "Do you want to use VNL?")
set(USE_YAML ON CACHE BOOL "Do you want to use yaml?")
set(USE_LMFIT ON CACHE BOOL "Do you want to use LMFIT?")
set(BUILD_TESTING ON CACHE BOOL "Do you want to build Tomato tests?")
set(BUILD_APP ON CACHE BOOL "Do you want to build Tomato app?")
##################
### LIST FILES ###
##################
# list of source files TODO: do not use glob, as it is not recommended https://cmake.org/cmake/help/latest/command/file.html#filesystem
file(GLOB_RECURSE APP_FILES app/*.c* app/*.h* app/*.t*)
file(GLOB_RECURSE LIB_FILES lib/*.c* lib/*.h* lib/*.t*)
file(GLOB_RECURSE API_FILES lib/*.h app/*.h lib/KWUtil.hxx)
###########
### ITK ###
###########
if(USE_ITK)
set(USE_ITK OFF)
find_package(itk)
find_package(ITK HINTS ${PROJECT_SOURCE_DIR}/thirdParty/itk)
MESSAGE("ITK version:" ${ITK_VERSION})
if(ITK_FOUND)
set(USE_ITK ON)
set(USE_VNL ON)
include(${ITK_USE_FILE})
set(TOMATO_LIBS_TO_LINK ${TOMATO_LIBS_TO_LINK} ${ITK_LIBRARIES})
endif()
endif(USE_ITK)
###########
### VNL ###
###########
if (USE_VNL AND NOT USE_ITK)
find_package(vxl REQUIRED)
set(TOMATO_LIBS_TO_LINK ${TOMATO_LIBS_TO_LINK} vxl::vxl)
set(TOMATO_LIBS_TO_LINK ${TOMATO_LIBS_TO_LINK} ${vxl_LIBRARIES}) # linux linking problem
endif()
############
### YAML ###
############
if (USE_YAML)
set(USE_YAML OFF)
find_package(libyaml QUIET)
if(LIBYAML_FOUND)
set(USE_YAML ON)
set(TOMATO_LIBS_TO_LINK ${TOMATO_LIBS_TO_LINK} libyaml::libyaml)
endif()
endif()
#############
### LMFIT ###
#############
if (USE_LMFIT)
set(USE_LMFIT OFF)
find_package(lmfit QUIET)
if(LMFIT_FOUND)
set(USE_LMFIT ON)
set(TOMATO_LIBS_TO_LINK ${TOMATO_LIBS_TO_LINK} lmfit::lmfit)
endif()
endif()
###############
### PRIVATE ###
###############
# unfortunately I cannot publish numerical recipes code according to numerical recipes licence
set(PRIVATE_NR2_DIR ${PROJECT_SOURCE_DIR}/../tomato_private CACHE PATH "")
set(USE_PRIVATE_NR2 ON CACHE BOOL "")
if(USE_PRIVATE_NR2 AND EXISTS ${PRIVATE_NR2_DIR})
add_subdirectory(${PRIVATE_NR2_DIR} ${CMAKE_BINARY_DIR}/private)
else()
set(USE_PRIVATE_NR2 OFF)
endif()
#################
### TOMATOFIT ###
#################
include(cmake/tomatofit.cmake)
####################
### MAIN PROGRAM ###
####################
if (BUILD_APP)
if(NOT USE_ITK OR NOT USE_YAML)
set(BUILD_APP OFF)
endif()
endif()
MESSAGE("CMAKE_CXX_STANDARD: " ${CMAKE_CXX_STANDARD})
MESSAGE("USE_ITK: " ${USE_ITK})
MESSAGE("USE_VNL: " ${USE_VNL})
MESSAGE("USE_PRIVATE_NR2: " ${USE_PRIVATE_NR2})
MESSAGE("USE_LMFIT: " ${USE_LMFIT})
MESSAGE("USE_YAML: " ${USE_YAML})
MESSAGE("BUILD_APP: " ${BUILD_APP})
MESSAGE("BUILD_TESTING: " ${BUILD_TESTING})
MESSAGE("CMAKE_INSTALL_PREFIX: " ${CMAKE_INSTALL_PREFIX})
# configure a header file to pass some of the CMake settings to the source code
configure_file("${PROJECT_SOURCE_DIR}/cmake/CmakeConfigForTomato.h.in" "${PROJECT_BINARY_DIR}/CmakeConfigForTomato.h")
set(LIB_FILES ${LIB_FILES} "${PROJECT_BINARY_DIR}/CmakeConfigForTomato.h")
set(API_FILES ${API_FILES} "${PROJECT_BINARY_DIR}/CmakeConfigForTomato.h")
#################
### TOMATOLIB ###
#################
# target
add_library(TomatoLib ${LIB_FILES})
set_target_properties(TomatoLib PROPERTIES LINKER_LANGUAGE CXX)
# include
target_include_directories(TomatoLib PUBLIC lib)
target_include_directories(TomatoLib PUBLIC ${PRIVATE_NR2_DIR}/lib/)
target_include_directories(TomatoLib PUBLIC "${PROJECT_BINARY_DIR}") # for the configuration header
# link
target_link_libraries(TomatoLib ${TOMATO_LIBS_TO_LINK})
set(TOMATO_LIBS_TO_LINK ${TOMATO_LIBS_TO_LINK} TomatoLib)
# generating TomatoLib_export.h
include(GenerateExportHeader)
generate_export_header(TomatoLib)
set(API_FILES ${API_FILES} ${PROJECT_SOURCE_DIR}/cmake/tomatolib_export.h) # to make tomatolib_export.h available in installation step
#################
### TOMATOAPP ###
#################
if(BUILD_APP)
# target
add_executable(TomatoExe ${APP_FILES})
# include
target_include_directories(TomatoExe PUBLIC app)
# link
target_link_libraries(TomatoExe ${TOMATO_LIBS_TO_LINK})
# RPATH preparation for the executables
set_target_properties(TomatoExe PROPERTIES INSTALL_RPATH
@executable_path
@loader_path
$ORIGIN)
endif()
##################
### Installing ###
##################
install(TARGETS TomatoLib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES ${API_FILES} DESTINATION include) # headers
if(BUILD_APP)
install(TARGETS TomatoExe DESTINATION bin)
if(BUILD_SHARED_LIBS)
install(TARGETS TomatoLib DESTINATION bin)
endif()
endif()
###############
### TESTING ###
###############
if(BUILD_TESTING)
add_subdirectory(tests)
install(TARGETS TomatoLib DESTINATION tests)
endif()
##
#set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
##if(CMAKE_COMPILER_IS_GNUCXX)
# include(CodeCoverage)
# setup_target_for_coverage_lcov(
# NAME ${PROJECT_NAME}Coverage
# EXECUTABLE ${PROJECT_NAME}Tests)
#endif()