forked from poncateam/ponca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
176 lines (143 loc) · 6.57 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
cmake_minimum_required(VERSION 3.10)
####################################################################################################
## Do not edit this file, but rather configure cmake according to your need
## USER OPTIONS
##
OPTION( PONCA_CONFIGURE_EXAMPLES "Include compilation rules for built-in examples" ON)
OPTION( PONCA_CONFIGURE_DOC "Include compilation rules for built-in documentation" ON)
OPTION( PONCA_CONFIGURE_TESTS "Include compilation rules for built-in tests" ON)
OPTION( PONCA_GENERATE_IDE_TARGETS "Generate targets to show source files in IDEs" ON)
##
## END USER OPTIONS
####################################################################################################
if(POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
# add this options before PROJECT keyword
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
project(Ponca LANGUAGES CXX VERSION 1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# guard against bad build-type strings (source: Eigen)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
if( NOT cmake_build_type_tolower STREQUAL "debug"
AND NOT cmake_build_type_tolower STREQUAL "release"
AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
endif()
# get changeset id
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${Ponca_SOURCE_DIR}
OUTPUT_VARIABLE GIT_CHANGESET)
endif()
################################################################################
## Dependencies
################################################################################
find_package(Eigen3 3.4 QUIET)
if( NOT Eigen3_FOUND )
message(STATUS "Cannot find Eigen, use submodule (disable transitive linking)")
if( NOT EXISTS ${EIGEN_SUBMODULE_ROOT_PATH}/signature_of_eigen3_matrix_library )
execute_process(COMMAND git submodule update --init -- ${EIGEN_SUBMODULE_ROOT_PATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(EIGEN3_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/eigen" PARENT_SCOPE)
message(STATUS "Make EIGEN3_INCLUDE_DIRS available to parent project.")
else()
set(EIGEN3_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/eigen")
endif()
include_directories(${EIGEN3_INCLUDE_DIRS})
endif()
macro(ponca_handle_eigen_dependency TARGETNAME)
## Should be retrieved by transitive linking, however it seems to fails with older cmake versions
if(Eigen3_FOUND)
get_target_property(MODULE Fitting INTERFACE_LINK_LIBRARIES )
if ("${MODULE}" STREQUAL "Eigen3::Eigen")
target_link_libraries(${TARGETNAME} PUBLIC Eigen3::Eigen)
endif()
endif()
endmacro()
################################################################################
# Generate install target #
################################################################################
set(Ponca_EXPORT_TARGET_DIR \${CMAKE_CURRENT_LIST_DIR})
set(config_install_dir "${CMAKE_INSTALL_PREFIX}/lib/cmake/")
set(include_install_dir "${CMAKE_INSTALL_PREFIX}/include")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
## Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
#set(targets_export_name "${PROJECT_NAME}Targets")
#et(namespace "${PROJECT_NAME}::")
## Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Note: PROJECT_VERSION is used as a VERSION
write_basic_package_version_file(
"${version_config}"
VERSION ${Ponca_VERSION}
COMPATIBILITY AnyNewerVersion
)
## Configure '<PROJECT-NAME>Config.cmake'
## version to be installed
## Use variables:
## * targets_export_name
## * PROJECT_NAME
## Used by Config.cmake.in
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
################################################################################
# Add code source, so it is visible in dev environements #
################################################################################
set(PONCA_src_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/")
include(PoncaConfigureFitting)
include(PoncaConfigureCommon)
include(PoncaConfigureSpatialPartitioning)
install(DIRECTORY ${PONCA_src_ROOT}/Ponca
DESTINATION include/
PATTERN "*~" EXCLUDE)
################################################################################
# API documentation with Doxygen #
################################################################################
if(PONCA_CONFIGURE_DOC)
add_subdirectory(doc)
endif()
################################################################################
# tests and examples #
################################################################################
if(PONCA_CONFIGURE_EXAMPLES)
add_subdirectory(examples EXCLUDE_FROM_ALL)
endif()
################################################################################
# Tests #
################################################################################
if(PONCA_CONFIGURE_TESTS)
include(CTest)
set (BUILD_TESTING ON)
option(PONCA_COVERAGE_TESTING "Enable coverage reporting" OFF)
add_custom_target(buildtests)
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif(PONCA_CONFIGURE_TESTS)
################################################################################
# Add custom target for Continuous Integration scripts #
################################################################################
add_custom_target(ponca-ci SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/.travis.yml
${CMAKE_CURRENT_SOURCE_DIR}/.github/workflows/ContinuousTest.yml
${CMAKE_CURRENT_SOURCE_DIR}/.github/workflows/stale.yml)