-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
135 lines (125 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
# Copyright (c) 2018–2021 SplineLib
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
# Project
project(
BSplineLib
VERSION 1.0.0
LANGUAGES CXX)
set(namespace "${PROJECT_NAME}::")
set(targets_export_name "${PROJECT_NAME}Targets")
option(BSPLINELIB_SHARED "Build shared library" OFF)
option(BSPLINELIB_BUILD_TOOLS "Build tools" OFF)
# Overwrite some options if this is for splinepy
if(SPLINEPY_BUILD_BSPLINELIB)
set(BSPLINELIB_SHARED OFF)
set(BSPLINELIB_BUILD_TOOLS OFF)
endif()
# Setup
set(include_install_directory "include")
set(include_install_directory_headers
"${include_install_directory}/${PROJECT_NAME}")
set(INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Sources>
$<INSTALL_INTERFACE:${include_install_directory_headers}>)
set(library_install_directory "lib")
set(executable_install_directory "bin")
set(configuration_install_directory "lib/cmake/${PROJECT_NAME}")
# Compilation
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OPTIMIZATION_FLAGS $<$<NOT:$<CONFIG:Debug>>:-O3>)
set(PARALLELIZATION_FLAGS)
set(RUNTIME_CHECKS_DEBUG)
set(WARNING_FLAGS
-Wall
-Wextra
-Wmost
-Wextra
-Wpedantic
-Wunreachable-code
-Wshadow
-Wfloat-equal
-Weffc++
$<$<NOT:$<CONFIG:Debug>>:-Wno-unused-parameter>
$<$<NOT:$<CONFIG:Debug>>:-Wno-unused-variable>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(OPTIMIZATION_FLAGS $<$<NOT:$<CONFIG:Debug>>:-O3>)
set(PARALLELIZATION_FLAGS)
set(RUNTIME_CHECKS_DEBUG)
set(WARNING_FLAGS -Wall -Wextra -Wpedantic -Wzero-as-null-pointer-constant
$<$<NOT:$<CONFIG:Debug>>:-Wno-unused>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(OPTIMIZATION_FLAGS -fast)
set(PARALLELIZATION_FLAGS -vec -parallel)
set(RUNTIME_CHECKS_DEBUG -fp-trap=all -fp-trap-all=all -ftrapuv)
set(WARNING_FLAGS -Wall -Wextra -Wcheck -Weffc++)
else()
message(WARNING "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
set(COMPILE_DEFINITIONS $<$<BOOL:${BSPLINELIB_SHARED}>:BSPLINELIB_SHARED>)
set(COMPILE_OPTIONS
${OPTIMIZATION_FLAGS} $<IF:$<CONFIG:Release>,${PARALLELIZATION_FLAGS},
${RUNTIME_CHECKS_DEBUG}> ${WARNING_FLAGS} ${SPLINEPY_FLAGS})
message(STATUS "Compile using ${CMAKE_CXX_COMPILER_ID} compiler!")
set(CMAKE_DEBUG_POSTFIX "d")
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Build debug!")
set(BSPLINELIB_COMPILE_FEATURES cxx_std_20)
else()
message(STATUS "Build release!")
# MSVC has issues evaluating constexpr @ string_operation.inc l.125 with c++17
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(BSPLINELIB_COMPILE_FEATURES cxx_std_20)
else()
set(BSPLINELIB_COMPILE_FEATURES cxx_std_17)
endif()
endif()
if(BSPLINELIB_SHARED)
message(STATUS "Build shared!")
set(BUILD_SHARED_LIBS ON)
else()
message(STATUS "Build static!")
set(BUILD_SHARED_LIBS OFF)
endif()
# Content
add_subdirectory(Sources/BSplineLib)
if(BSPLINELIB_BUILD_TOOLS)
add_subdirectory(Tools)
endif()
# Packaging
set(generated_directory ${CMAKE_CURRENT_BINARY_DIR}/Generated)
set(version_configuration
${generated_directory}/${PROJECT_NAME}ConfigVersion.cmake)
set(project_configuration ${generated_directory}/${PROJECT_NAME}Config.cmake)
include(CMakePackageConfigHelpers)
configure_package_config_file(
CMake/config.cmake.in ${project_configuration}
INSTALL_DESTINATION ${configuration_install_directory})
write_basic_package_version_file(${version_configuration}
COMPATIBILITY SameMajorVersion)
install(FILES ${project_configuration} ${version_configuration}
DESTINATION ${configuration_install_directory})
install(
EXPORT ${targets_export_name}
NAMESPACE ${namespace}
DESTINATION ${configuration_install_directory})