-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
196 lines (163 loc) · 5.05 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
#
# Copyright (C) 2022 Embecosm Limited
#
# Contributor William Jones <[email protected]>
# Contributor Elliot Stein <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
cmake_minimum_required(VERSION 3.16)
project(dcEmb LANGUAGES CXX VERSION 1.0.1 DESCRIPTION "dcEmb, fast Dynamic Causal Modeling")
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
# Options
option(BUILD_PYTHON_BINDINGS "Build Python bindings using cython" ON)
option(BUILD_DOCS "Build docs using Sphinx and Doxygen" ON)
option(BUILD_TESTS "Build tests using googletest" ON)
option(STATIC_BUILD "Build a static library" OFF)
option(USE_OPENMP "Build with OpenMP for Eigen parallelisation" ON)
option(OPTIMIZE_FASTMATH_NATIVE "Build with -march=native and -ffast-math" ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Basic CMake setup
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
if(OPTIMIZE_FASTMATH_NATIVE)
set(FAST_MATH_FLAGS -ffast-math -fno-unsafe-math-optimizations)
CHECK_CXX_COMPILER_FLAG("${FAST_MATH_FLAGS}" COMPILER_SUPPORTS_FAST_MATH)
CHECK_CXX_COMPILER_FLAG(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)
if (COMPILER_SUPPORTS_FAST_MATH)
add_compile_options(${FAST_MATH_FLAGS})
endif()
if (COMPILER_SUPPORTS_MARCH_NATIVE)
add_compile_options(-march=native)
endif()
endif()
# Configure for OpenMP
if(USE_OPENMP)
find_package(OpenMP)
if(OpenMP_FOUND)
link_libraries(OpenMP::OpenMP_CXX)
add_compile_definitions(_GLIBCXX_PARALLEL)
endif()
endif()
find_package(Eigen3 3.4 REQUIRED)
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/include/3body
${CMAKE_SOURCE_DIR}/include/tests
${gtest_SOURCE_DIR}
${gtest_SOURCE_DIR}/include
)
# Library sources
set(SOURCES_DCM
src/dynamic_model.cc
src/utility.cc
)
# Test sources
set(SOURCES_TESTS
tests/utility_test.cc
src/3body/dynamic_3body_model.cc
tests/dynamic_3body_model_test.cc
)
# Library config
if(STATIC_BUILD)
add_library(dcEmb STATIC ${SOURCES_DCM})
else()
add_library(dcEmb SHARED ${SOURCES_DCM})
endif()
target_link_libraries(dcEmb PUBLIC Eigen3::Eigen)
target_include_directories(dcEmb
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
set_target_properties(dcEmb PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
)
# Tests config
if(BUILD_TESTS)
find_package(GTest REQUIRED)
enable_testing()
# Run short form tests
add_executable(run_tests ${SOURCES_TESTS})
# OpenMP is already added earlier if enabled
target_link_libraries(run_tests PUBLIC gtest gtest_main dcEmb Eigen3::Eigen)
endif()
# Installation config
install(TARGETS dcEmb EXPORT dcEmb
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES
include/dynamic_model.hh
include/bma_model.hh
include/bmr_model.hh
include/peb_model.hh
include/utility.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dcEmb
)
install(EXPORT dcEmb
DESTINATION cmake
FILE dcEmbConfig.cmake
)
# Python bindings
if(BUILD_PYTHON_BINDINGS)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python.stamp
COMMAND ${Python3_EXECUTABLE} setup.py build_ext
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/python.stamp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python
COMMENT "Building Python bindings to 'dcEmb' library"
)
add_custom_target(dcEmb-python-bindings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python.stamp)
endif()
if(BUILD_DOCS)
# look for Doxygen package
find_package(Doxygen)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/source/doxygen/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.out)
message(${DOXYGEN_IN})
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# Note: do not put "ALL" - this builds docs together with application EVERY TIME!
add_custom_target(doxy
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
else()
message("Doxygen need to be installed to generate the doxygen documentation")
endif()
include(UseSphinxDoc)
include(FindSphinx)
add_sphinx_doc(
SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/docs/source/sphinx/source
BUILD_DIR
${CMAKE_CURRENT_SOURCE_DIR}/docs/
CACHE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/docs/.doctrees
HTML_DIR
${CMAKE_CURRENT_SOURCE_DIR}/docs/
CONF_FILE
${CMAKE_CURRENT_SOURCE_DIR}/docs/source/sphinx/source/conf.py
TARGET_NAME
sphinx
COMMENT
"HTML documentation"
)
# Documentation
add_custom_target(docs)
add_dependencies(docs doxy sphinx)
endif()
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Embecosm") # required
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "1")
INCLUDE(CPack)