-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
93 lines (82 loc) · 2.53 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
cmake_minimum_required(VERSION 3.16)
project(
phetdam-math
VERSION 0.1.0
DESCRIPTION "Accompanying code for my independent mathematical work."
HOMEPAGE_URL "https://github.com/phetdam/math"
LANGUAGES CXX
)
# build debug by default; we set -DCMAKE_BUILD_TYPE=Release for release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# debug and release flags, handle MSVC case specifically
if(MSVC)
add_compile_options(
/Wall
/wd4265
/wd4514
/wd4625
/wd4626
/wd4820
/wd5026
/wd5027
/wd5045
)
# MSVC issues C4996 due to use of std::iterator in Boost
add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
if(CMAKE_BUILD_TYPE STREQUAL Release)
add_compile_options(/O2)
else()
add_compile_options(/Od /DEBUG)
endif()
else()
add_compile_options(-Wall -Wextra)
if(CMAKE_BUILD_TYPE STREQUAL Release)
add_compile_options(-O3)
else()
add_compile_options(-O0 -ggdb)
endif()
endif()
# macros to define based on release type
if(CMAKE_BUILD_TYPE STREQUAL Release)
add_compile_definitions(EIGEN_NO_DEBUG)
endif()
# minimum versions for dependencies
set(BOOST_MIN_VERSION 1.71.0)
set(EIGEN_MIN_VERSION 3.4)
set(GTEST_MIN_VERSION 1.10.0)
find_package(Boost ${BOOST_MIN_VERSION} REQUIRED)
# https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html indicates NO_MODULE
# (equivalent to CONFIG) should be specified
find_package(Eigen3 ${EIGEN_MIN_VERSION} REQUIRED CONFIG)
find_package(GTest ${GTEST_MIN_VERSION})
# base include for this repo
set(PDMATH_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include")
include_directories(
${PDMATH_INCLUDE}
# in case Boost and GoogleTest were found using BOOST_ROOT, GTEST_ROOT.
# the SYSTEM prefix tells compilers to skip warnings not in our control
SYSTEM ${Boost_INCLUDE_DIR}
SYSTEM ${GTEST_INCLUDE_DIRS}
SYSTEM ${EIGEN3_DIR}
)
add_subdirectory(src)
add_subdirectory(examples)
# only build tests and enable testing if compatible GoogleTest is found.
# note: on Windows, GTest_VERSION doesn't seem to be locatable if built static,
# so there is a bit of hack here to ignore the version on Windows
if(
GTest_FOUND AND
(WIN32 OR GTest_VERSION VERSION_GREATER_EQUAL ${GTEST_MIN_VERSION})
)
enable_testing()
add_subdirectory(test)
else()
message(
STATUS
"GoogleTest >=${GTEST_MIN_VERSION} not satisfied. No tests to build"
)
endif()