-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
425 lines (307 loc) · 12.3 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
cmake_minimum_required(VERSION 3.17)
project(milk LANGUAGES C)
# Examples :
# cmake .. -DUSE_CUDA=ON -DINSTALLMAKEDEFAULT=ON
# cmake .. -DUSE_CUDA=ON -DUSE_MAGMA=ON
# cmake .. -DCMAKE_BUILD_TYPE=Debug
option(build_python_module "Compile Python Wrappers" OFF)
include(CheckLanguage)
# =======================================
# GPU ACCELERATION
# =======================================
# options
option(DEBUG "Enable Debug library" OFF)
if(DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
endif()
option(USE_CUDA "Use CUDA library" OFF)
option(USE_MAGMA "Use MAGMA library" OFF)
if(USE_CUDA)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
#message(FATAL_ERROR "No CUDA support")
message(WARNING "No CUDA support found")
set(CMAKE_CUDA_COMPILER "/usr/bin/nvcc")
message(" setting CMAKE_CUDA_COMPILER to ${CMAKE_CUDA_COMPILER}")
endif()
endif(USE_CUDA)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
#find_package(MKL CONFIG)
pkg_check_modules(OPENBLAS openblas)
pkg_check_modules(MKL mkl-sdl)
#pkg_check_modules(MKL mkl-static-ilp64-gomp)
enable_language(C)
# Version number
set ( VERSION_MAJOR 1 )
set ( VERSION_MINOR 03 )
set ( VERSION_PATCH 00 )
set ( MILK_VERSION_OPTION "" )
set ( PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
set ( PROJECT_DESCRIPTION "Modular Image processing tooLKit" )
option ( INSTALLMAKEDEFAULT "Make this installation the system default" OFF )
# turn VERBOSE ON
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_LINK_DEPENDS_NO_SHARED true)
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/milk-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
# Configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/src/milk_config.h.in"
"${PROJECT_SOURCE_DIR}/src/milk_config.h"
)
configure_file (
"${PROJECT_SOURCE_DIR}/src/config.h.in"
"${PROJECT_SOURCE_DIR}/src/config.h"
)
# select most recent version available
SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
#
# main libraries
# linked to executable by default
#
# =======================================
# MODULES INCLUDED
# =======================================
# modules are added to two lists:
# libsrcdir : source code directory
# libname : shared object name
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/src/ImageStreamIO/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
list(APPEND libsrcdir src/CommandLineInterface)
list(APPEND libname CLIcore)
list(APPEND libsrcdir src/ImageStreamIO)
list(APPEND libname ImageStreamIO m)
list(APPEND modulelist COREMOD_arith COREMOD_iofits COREMOD_memory COREMOD_tools)
foreach(mname IN LISTS modulelist)
string(REPLACE "_" "" mname1 "${mname}")
list(APPEND libsrcdir src/${mname})
list(APPEND libname milk${mname1})
message("======= adding module ${mname}")
endforeach()
# =======================================
# BUILD TYPE
# =======================================
# Set Release build flags
# cmake -DCMAKE_BUILD_TYPE=Debug
# option: add -fanalyzer if gcc10+ (warning: this will take a while to run)
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wall -Wextra")
# Set Release build flags
# cmake -DCMAKE_BUILD_TYPE=Release
set(CMAKE_C_FLAGS_RELEASE "-Ofast -DNDEBUG")
# Set a default build type if none was specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}")
endif()
message("CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}")
# =======================================
# COMPILE OPTIONS
# =======================================
add_compile_options($<$<COMPILE_LANGUAGE:C>:-march=native>)
# link-time optimizer
add_compile_options($<$<COMPILE_LANGUAGE:C>:-flto=auto>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fwhole-program>)
#add_compile_options(-fwhole-program)
# NOTE: -fstack-usage is incompatible with link-time optimizer
#add_compile_options(-fstack-usage)
# A common flag is -pipe. This flag has no effect on the generated code,
# but it makes the compilation process faster. It tells the compiler
# to use pipes instead of temporary files during the different stages
# of compilation, which uses more memory. On systems with low memory,
# GCC might get killed. In those cases do not use this flag.
add_compile_options($<$<COMPILE_LANGUAGE:C>:-pipe>)
message("COMPILE_OPTIONS: ${COMPILE_OPTIONS}")
message("====================================================")
message("VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
message("====================================================")
message("CMAKE_THREAD_LIBS_INIT : ${CMAKE_THREAD_LIBS_INIT}")
message("PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
message("PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}")
message("CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
message("USE_CUDA = ${USE_CUDA}")
message("USE_MAGMA = ${USE_MAGMA}")
message("EXTRAMODULES = ${EXTRAMODULES}")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# ADD SOURCE DIRECTORIES
# recursively add libraries to be compiled
execute_process(COMMAND bash -c "find ${PROJECT_SOURCE_DIR}/plugins -mindepth 2 -maxdepth 2 -type d | grep -v .git | grep -v .vscode"
OUTPUT_VARIABLE libextradir)
string(REGEX REPLACE "\n" "; " libextradir "${libextradir}")
foreach(lsrcdir IN LISTS libsrcdir libextradir)
string(REGEX REPLACE " " "" lsrcdir "${lsrcdir}")
if (NOT ${lsrcdir} EQUAL "")
message("ADDING SUBDIR = ${lsrcdir}")
add_subdirectory ( ${lsrcdir} )
endif()
endforeach()
# add example module
add_subdirectory(src/milk_module_example)
# add isio-tools
add_subdirectory(src/isio-tools)
# main
add_executable(milk src/CLImain.c)
# note: set -SOURCEDIR=\\\"${CMAKE_INSTALL_PREFIX}\\\" for autoload
set(BUILD_FLAGS "-DPACKAGE_NAME=\\\"milk\\\" -DCONFIGDIR=\\\"${PROJECT_SOURCE_DIR}/config\\\" -DINSTALLDIR=\\\"${CMAKE_INSTALL_PREFIX}\\\" -DSOURCEDIR=\\\"${PROJECT_SOURCE_DIR}\\\" -DABSSRCTOPDIR=\\\"${PROJECT_SOURCE_DIR}\\\" -DPACKAGE_BUGREPORT=\\\"https://github.com/milk-org/milk/issues\\\"" )
target_link_libraries(milk PUBLIC ${libname})
if(USE_CUDA)
# Link CUDA globally to the executable rather than per module.
find_package(CUDAToolkit 9.0 REQUIRED)
target_link_libraries(milk PUBLIC CUDA::toolkit
PUBLIC CUDA::cusolver
PUBLIC CUDA::cudart
PUBLIC CUDA::cublas)
set(BUILD_FLAGS "${BUILD_FLAGS} -DHAVE_CUDA" )
endif(USE_CUDA)
set_target_properties(milk PROPERTIES COMPILE_FLAGS "${BUILD_FLAGS}" )
message("====================================================")
get_target_property(milkcompopts milk COMPILE_OPTIONS)
message("BUILD_FLAGS : ${BUILD_FLAGS}")
message("COMPILE_FLAGS : ${COMPILE_FLAGS}")
message("COMPILE_OPTIONS : ${milkcompopts}")
message("CMAKE_EXE_LINKER_FLAGS : ${CMAKE_EXE_LINKER_FLAGS}")
message("CMAKE_C_FLAGS : ${CMAKE_C_FLAGS}")
message("CMAKE_CXX_FLAGS : ${CMAKE_CXX_FLAGS}")
message("CMAKE_C_FLAGS_DEBUG : ${CMAKE_C_FLAGS_DEBUG}")
message("CMAKE_C_FLAGS_RELEASE : ${CMAKE_C_FLAGS_RELEASE}")
message("CMAKE_C_FLAGS_RELWITHDEBINFO : ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
message("CMAKE_C_FLAGS_MINSIZEREL : ${CMAKE_C_FLAGS_MINSIZEREL}")
message("CMAKE_CURRENT_SOURCE_DIR : ${CMAKE_CURRENT_SOURCE_DIR}")
message("CMAKE_CURRENT_BINARY_DIR : ${CMAKE_CURRENT_BINARY_DIR}")
message("INSTALL_PKGCONFIG_DIR : ${INSTALL_PKGCONFIG_DIR}")
message("====================================================")
set(PROGRAM_PERMISSIONS_DEFAULT
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
install(TARGETS milk
DESTINATION bin
PERMISSIONS ${PROGRAM_PERMISSIONS_DEFAULT} SETUID)
# =======================================
# MAKE DEFAULT
# =======================================
set(CMAKE_INSTALL_PREFIX_LINK "/usr/local/${PROJECT_NAME}")
if(INSTALLMAKEDEFAULT)
install(CODE "
EXECUTE_PROCESS(COMMAND ln -snf ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX_LINK})
")
endif(INSTALLMAKEDEFAULT)
# =======================================
# CONFIG.CMAKE
# =======================================
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include
CACHE PATH "Location of header files" )
set(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib
CACHE PATH "Location of libraries" )
# Export the targets to a file for use in the Config.cmake file
install(EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake
)
# Set alias for collective milk::milk_all target as well
add_library(${PROJECT_NAME}_all INTERFACE)
target_link_libraries(${PROJECT_NAME}_all INTERFACE ${libname})
target_include_directories(${PROJECT_NAME}_all INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
install(TARGETS ${PROJECT_NAME}_all EXPORT milkTargets)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION lib/cmake
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR
)
# Install the Config.cmake and ConfigVersion.cmake files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake
)
# =======================================
# PKG-CONFIG
# =======================================
foreach(lname IN LISTS libname)
string(APPEND LINKSTRING "-l${lname} ")
endforeach()
message("LINKSTRING: ${LINKSTRING}")
set(INSTALL_PKGCONFIG_DIR "lib/pkgconfig"
CACHE PATH "Installation directory for pkgconfig (.pc) files")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/milk.pc.in
${CMAKE_CURRENT_BINARY_DIR}/milk.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/milk.pc
DESTINATION "${INSTALL_PKGCONFIG_DIR}")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/milk_config.h
${CMAKE_CURRENT_SOURCE_DIR}/src/config.h
DESTINATION include
)
if(build_python_module)
add_subdirectory (python_module)
endif()
install(TARGETS CLIcore DESTINATION bin)
install(PROGRAMS
scripts/milk-all
scripts/milk-argparse
scripts/milk-check
scripts/milk-commands
scripts/milk-cubeslice2shm
scripts/milk-exec
scripts/milk-fpslist-addentry
scripts/milk-streamCTRL
scripts/milk-procCTRL
scripts/milk-fpsCTRL
scripts/milk-cr2tofits
scripts/milk-FITS2shm
scripts/milk-fpsmkcmd
scripts/milk-fpsinit
scripts/milk-logshim
scripts/milk-logshimkill
scripts/milk-logshimoff
scripts/milk-logshimon
scripts/milk-logshimstat
scripts/milk-makecsetandrt
scripts/merge3DfitsTelemetry
scripts/milk-images-merge
scripts/milk-scriptexample
scripts/milk-script-std-config
scripts/milk-streamlink
scripts/milk-stream-scan
scripts/milk-shm2FITS
scripts/milk-shm2FITSloop
scripts/milk-shmim-rm
scripts/milk-shmim-zero
scripts/tmuxkillall
scripts/tmuxsessionname
scripts/waitforfile
DESTINATION bin)
# ====================================
# TESTING
# ====================================
include(CTest)