-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
184 lines (157 loc) · 4.76 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
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
cmake_minimum_required(VERSION 3.10)
project(robin
VERSION 0.1
DESCRIPTION "Robust outlier rejection based on measurement compatibility graphs"
LANGUAGES CXX
)
#
# Disable in-tree building
#
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree built. Create a build folder outside source instead.")
endif ()
#
# Default build type to debug
#
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
#
# Update CMake module path
#
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(DownloadExternal)
#
# Build options
#
option(BUILD_DOCS "Build documentation." OFF)
option(BUILD_TESTS "Enable testing with ctest." ON)
option(BUILD_PYTHON_BINDINGS "Build python bindings." ON)
option(BUILD_MATLAB_BINDINGS "Build MATLAB bindings" OFF)
option(USE_ASAN "Enable address sanitizer" OFF)
option(ENABLE_DIAGNOSTIC_PRINT "Enable printing of diagnostic messages" OFF)
if (ENABLE_DIAGNOSTIC_PRINT)
message(STATUS "Enable printing of diagnostic messages.")
add_definitions(-DROBIN_DIAG_PRINT)
endif ()
#
# Dependencies
#
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_package(Eigen3 3.3 QUIET REQUIRED NO_MODULE)
find_package(OpenMP QUIET REQUIRED)
robin_download_pmc()
robin_download_xenium()
add_subdirectory(${pmc_SOURCE_DIR} ${pmc_BINARY_DIR})
#
# Add robin target
#
include(GNUInstallDirs)
file(GLOB
SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/*.cpp)
add_library(robin STATIC ${SOURCE_FILES})
add_library(robin::robin ALIAS robin)
target_link_libraries(robin
PUBLIC Eigen3::Eigen
xenium
PRIVATE OpenMP::OpenMP_CXX
PRIVATE pmc)
target_include_directories(
robin
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if (USE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fPIC")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif ()
#
# Install Robin
#
include(CMakePackageConfigHelpers)
install(
TARGETS robin
EXPORT robinTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
write_basic_package_version_file(
robinConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/robinConfig.cmake.in
${PROJECT_BINARY_DIR}/robinConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
export(
EXPORT robinTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/robinTargets.cmake
NAMESPACE robin::
)
install(
TARGETS xenium pmc
EXPORT robinTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
EXPORT robinTargets
FILE robinTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NAMESPACE robin::
)
install(
FILES
${PROJECT_BINARY_DIR}/robinConfig.cmake
${PROJECT_BINARY_DIR}/robinConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(DIRECTORY include/robin DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# To set forcibly xeniumConfig.cmake
install(FILES cmake/xeniumConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xenium
)
export(PACKAGE robin)
# Tests
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif ()
# Python bindings
if (BUILD_PYTHON_BINDINGS)
robin_download_pybind11()
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
add_subdirectory(python)
endif ()
# MATLAB bindings
if (BUILD_MATLAB_BINDINGS)
if (USE_ASAN)
message(WARNING "MATLAB binding might not work with USE_ASAN=ON. Consider turning it off by -DUSE_ASAN=OFF.")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_subdirectory(matlab)
endif ()
# Documentation
if (BUILD_DOCS)
find_package(Doxygen 1.8)
if (DOXYGEN_FOUND)
add_subdirectory(docs)
else ()
set(BUILD_DOCS OFF)
endif ()
endif ()
# Summary of configuration
message(STATUS "===============================================================")
message(STATUS "============= Robin Configuration Options =====================")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "BUILD_DOCS: ${BUILD_DOCS}")
message(STATUS "BUILD_PYTHON_BINDINGS: ${BUILD_PYTHON_BINDINGS}")
message(STATUS "BUILD_MATLAB_BINDINGS: ${BUILD_MATLAB_BINDINGS}")
message(STATUS "USE_ASAN: ${USE_ASAN}")
message(STATUS "ENABLE_DIAGNOSTIC_PRINT: ${ENABLE_DIAGNOSTIC_PRINT}")
message(STATUS "===============================================================")