-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
145 lines (114 loc) · 4.47 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
cmake_minimum_required(VERSION 3.17)
set(LIBNAME "ImageStreamIO")
set(SRCNAME "ImageStreamIO")
message("")
message(" SRCNAME = ${SRCNAME} -> LIBNAME = ${LIBNAME}")
option(build_python_module "Compile Python Wrappers" OFF)
option(gtest_build_tests "Build Unit Tests" OFF)
project(${LIBNAME} LANGUAGES C)
# Version number
set ( VERSION_MAJOR 2 )
set ( VERSION_MINOR 00 )
set ( VERSION_PATCH 00 )
set ( VERSION_OPTION "" )
set ( PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
configure_file (
"${PROJECT_SOURCE_DIR}/${PROJECT_NAME}_config.h.in"
"${PROJECT_SOURCE_DIR}//${PROJECT_NAME}_config.h"
)
message(" VERSION = ${PROJECT_VERSION}")
add_compile_options(-Ofast)
add_library(${LIBNAME} SHARED ${SRCNAME}.c)
# set -C99 flag for 'for' loop initial declartaions
set_property(TARGET ${LIBNAME} PROPERTY C_STANDARD 99)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CFITSIO cfitsio)
if(${CFITSIO_FOUND})
link_directories(${CFITSIO_LIBRARY_DIRS})
target_compile_definitions(${LIBNAME} PUBLIC USE_CFITSIO=1)
target_include_directories(${LIBNAME} PUBLIC ${CFITSIO_INCLUDE_DIRS})
target_link_directories(${LIBNAME} PUBLIC ${CFITSIO_INCLUDE_DIRS})
endif()
target_include_directories(${LIBNAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/${SRCNAME}>
$<INSTALL_INTERFACE:include>)
if(USE_CUDA)
find_package(CUDAToolkit 9.0 REQUIRED)
message(STATUS "Found CUDA ${CUDAToolkit_VERSION} at ${CUDAToolkit_LIBRARY_DIR}")
message("---- CUDA_INCLUDE_DIRS = ${CUDAToolkit_INCLUDE_DIRS}")
target_include_directories(${LIBNAME} PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
target_link_libraries(${LIBNAME} PRIVATE CUDA::toolkit CUDA::cudart)
target_compile_options(${LIBNAME} PUBLIC -DHAVE_CUDA)
set(BUILD_FLAGS "${BUILD_FLAGS} -DHAVE_CUDA" )
endif(USE_CUDA)
if(DAO_COMPAT)
target_compile_options(${LIBNAME} PUBLIC -DDAO_COMPAT)
endif(DAO_COMPAT)
#
# Python wrap.
#
# The python wrapper is not built by default. To build it, set the build_python_module
# option to ON. You can do it by running ccmake or specifying the
# -Dbuild_python_module=ON flag when running cmake.
if(build_python_module)
add_subdirectory(python_module)
endif()
########################################################################
#
# 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 ${LIBNAME}Targets
FILE "${LIBNAME}Targets.cmake"
NAMESPACE ${LIBNAME}::
DESTINATION lib/cmake
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}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}/${LIBNAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}ConfigVersion.cmake"
DESTINATION lib/cmake
)
########################################################################
#
# pkg-config
#
string(APPEND LINKSTRING "-l${LIBNAME} ")
set(INSTALL_PKGCONFIG_DIR "lib/pkgconfig"
CACHE PATH "Installation directory for pkgconfig (.pc) files")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${LIBNAME}.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}.pc
DESTINATION "${INSTALL_PKGCONFIG_DIR}")
########################################################################
#
# Google Test.
#
# The tests are not built by default. To build them, set the
# gtest_build_tests option to ON. You can do it by running ccmake
# or specifying the -Dgtest_build_tests=ON flag when running cmake.
if (gtest_build_tests)
# This must be set in the root directory for the tests to be run by
# 'make test' or ctest.
enable_testing()
add_subdirectory(tests)
endif()
install(TARGETS ${LIBNAME} EXPORT ${LIBNAME}Targets DESTINATION lib)
install(FILES ${SRCNAME}.h DESTINATION include/${SRCNAME})
install(FILES ImageStruct.h ImageStreamIOError.h DESTINATION include/${SRCNAME})