-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
143 lines (125 loc) · 6.04 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
# Minimum version required
cmake_minimum_required(VERSION 3.12.4)
# Set the build version (specify a tweak version to indicated post-release if needed)
set(BUILD_VERSION 1.8.8)
# MSVC runtime library flags are defined by 'CMAKE_MSVC_RUNTIME_LIBRARY'
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15.7)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
endif()
# Set find_package strategy to look for both upper-case and case-preserved variables
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0)
cmake_policy(SET CMP0144 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0144 NEW)
endif()
# Keep relying on CMake FindBoost module instead of the one shipping with Boost itself.
# Required by our "hack" to support a mix of shared and static boost components.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.30.0)
cmake_policy(SET CMP0167 OLD)
set(CMAKE_POLICY_DEFAULT_CMP0167 OLD)
endif()
# Set compatibility
set(COMPATIBILITY_VERSION SameMinorVersion)
# Enforce generation of `compile_commands.json`.
# This file is used by various tools such as code or clang-tidy to resolve imports.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
# Extract major, minor and patch version
string(REPLACE "." ";" _VERSION "${BUILD_VERSION}")
list(GET _VERSION 0 BUILD_VERSION_MAJOR)
list(GET _VERSION 1 BUILD_VERSION_MINOR)
# Add definition of Jiminy version for C++ headers
add_definitions("-DJIMINY_VERSION=\"${BUILD_VERSION}\"")
# Project and library name
project(jiminy VERSION ${BUILD_VERSION})
set(LIBRARY_NAME ${PROJECT_NAME})
set(PYTHON_LIBRARY_NAME "core")
# Enable C++ language
enable_language(CXX)
# Set build environment and standard dependencies
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/base.cmake)
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/docs.cmake)
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/boostPythonDocstring.cmake)
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/exportCmakeConfigFiles.cmake)
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/buildPythonWheel.cmake)
# Set the compilation flags.
# Not using `add_compile_options` because it does not propagate to external projects.
if(NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "$ENV{CMAKE_CXX_FLAGS}")
endif()
string(REGEX MATCHALL "(^| )-DEIGEN_[A-Z0-9_]+=?[0-9]*( |$)" EIGEN_DEFINITIONS "${CMAKE_CXX_FLAGS}")
list(TRANSFORM EIGEN_DEFINITIONS STRIP)
list(REMOVE_DUPLICATES EIGEN_DEFINITIONS)
list(TRANSFORM EIGEN_DEFINITIONS REPLACE "^-D" "")
if(EIGEN_DEFINITIONS)
message(STATUS "Eigen preprocessor directives: ${EIGEN_DEFINITIONS}")
endif()
if(MSVC)
string(REGEX MATCH "/arch:[a-zA-Z0-9_-]*" CMAKE_CXX_ARCH "${CMAKE_CXX_FLAGS}")
if(CMAKE_CXX_ARCH MATCHES "AVX[0-9]+")
# Eigen<3.4 relies on __FMA__ definition to detect if FMA is available,
# which is not set automatically by MSVC.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FMA__")
if(MSVC_VERSION GREATER 1930)
# Floating-point contractions are not generated by default on MSVC > 2019.
# After this point, it is necessary to pass `/fp:contract`. Following the
# same paradigm as Eigen>3.4, we enable it if AVX2+ is required.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:contract")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
/MP /EHsc /bigobj /Gy /Zc:inline /Zc:preprocessor /Zc:__cplusplus /permissive- /DWIN32 \
/D_USE_MATH_DEFINES /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /DNOMINMAX")
set(CMAKE_CXX_FLAGS_DEBUG "/Zi /Od")
set(CMAKE_CXX_FLAGS_RELEASE "/DNDEBUG /O2 /Ob3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
foreach(TARGET_TYPE IN ITEMS "EXE" "SHARED")
set(CMAKE_${TARGET_TYPE}_LINKER_FLAGS_DEBUG "${CMAKE_${TARGET_TYPE}_LINKER_FLAGS} /DEBUG:FULL /INCREMENTAL:NO /OPT:REF /OPT:ICF")
set(CMAKE_${TARGET_TYPE}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${TARGET_TYPE}_LINKER_FLAGS_DEBUG}")
endforeach()
else()
string(REGEX MATCHALL "(^| )-m[a-z0-9\.-]+=?[a-zA-Z0-9_-]*( |$)" CMAKE_CXX_ARCH "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-DBOOST_PYTHON_DEBUG -g -O0 -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -Wfatal-errors -Werror")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-omit-frame-pointer -fno-sanitize-recover")
foreach(TARGET_TYPE IN ITEMS "EXE" "SHARED")
set(CMAKE_${TARGET_TYPE}_LINKER_FLAGS_DEBUG "${CMAKE_${TARGET_TYPE}_LINKER_FLAGS} -fno-omit-frame-pointer")
set(CMAKE_${TARGET_TYPE}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${TARGET_TYPE}_LINKER_FLAGS_DEBUG}")
endforeach()
endif()
list(REMOVE_DUPLICATES CMAKE_CXX_ARCH)
list(TRANSFORM CMAKE_CXX_ARCH STRIP)
if(CMAKE_CXX_ARCH)
message(STATUS "Instruction sets: ${CMAKE_CXX_ARCH}")
endif()
# Configure MSVC multithreading library to link against.
# Somehow, setting `MSVC_RUNTIME_LIBRARY` target property is not working.
if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
endif()
# Export symbols to enable building extension module
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEXPORT_SYMBOLS")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# Sub-projects
add_subdirectory(soup)
add_subdirectory(core)
option(BUILD_PYTHON_INTERFACE "Build and install the Python packages." ON)
if(BUILD_PYTHON_INTERFACE)
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/setupPython.cmake)
add_subdirectory(python)
endif()
# Create 'docs' optional cmake component to generate documentation
create_component_docs()
# Install the source cmake files
file(GLOB_RECURSE SOURCE_CMAKE_FILES "${CMAKE_SOURCE_DIR}/build_tools/cmake/Find*.cmake")
install(FILES ${SOURCE_CMAKE_FILES}
DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}/cmake"
)
install(FILES ${CMAKE_SOURCE_DIR}/build_tools/cmake/base.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}/cmake"
RENAME ${LIBRARY_NAME}_base.cmake
)
install(FILES ${CMAKE_SOURCE_DIR}/build_tools/cmake/boostPythonDocstring.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}/cmake"
)