-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
139 lines (116 loc) · 5.97 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
#=============================================================================
# Setup project
#=============================================================================
project(mpl11 CXX)
cmake_minimum_required(VERSION 2.8)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(MPL11_IS_NESTED FALSE)
else()
set(MPL11_IS_NESTED TRUE)
endif()
#=============================================================================
# Setup CMake options
#=============================================================================
include(CMakeDependentOption)
option(MPL11_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(MPL11_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(MPL11_ENABLE_LIBCXX "Use the -stdlib=libc++ if the compiler supports it." ON)
CMAKE_DEPENDENT_OPTION(
MPL11_ENABLE_TESTS "Enable the `unit` target. To avoid target name conflicts and cluttering the list of targets, unit tests are disabled when the library is nested inside another project."
OFF "MPL11_IS_NESTED" # OFF when MPL11_IS_NESTED
ON # ON otherwise
)
CMAKE_DEPENDENT_OPTION(
MPL11_ENABLE_DOC "Enable the `doc` target. To avoid target name conflicts and cluttering the list of targets, this is disabled when the library is nested inside another project."
OFF "MPL11_IS_NESTED" # OFF when MPL11_IS_NESTED
ON # ON otherwise
)
CMAKE_DEPENDENT_OPTION(
MPL11_ENABLE_EXAMPLES "Enable the `example` target. To avoid target name conflicts and cluttering the list of targets, this is disabled when the library is nested inside another project."
OFF "MPL11_IS_NESTED" # OFF when MPL11_IS_NESTED
ON # ON otherwise
)
#=============================================================================
# Check available compiler flags
#=============================================================================
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-ftemplate-backtrace-limit=0 MPL11_HAS_FTEMPLATE_BACKTRACE_LIMIT_0)
check_cxx_compiler_flag(-pedantic MPL11_HAS_PEDANTIC_FLAG)
check_cxx_compiler_flag(-std=c++1y MPL11_HAS_STDCXX1Y_FLAG)
check_cxx_compiler_flag(-stdlib=libc++ MPL11_HAS_STDLIB_LIBCXX_FLAG)
check_cxx_compiler_flag(-W MPL11_HAS_W_FLAG)
check_cxx_compiler_flag(-Wall MPL11_HAS_WALL_FLAG)
check_cxx_compiler_flag(-Werror MPL11_HAS_WERROR_FLAG)
check_cxx_compiler_flag(-Wextra MPL11_HAS_WEXTRA_FLAG)
check_cxx_compiler_flag(-Wno-long-long MPL11_HAS_WNO_LONG_LONG_FLAG)
check_cxx_compiler_flag(-Wno-unused-local-typedefs MPL11_HAS_WNO_UNUSED_LOCAL_TYPEDEFS_FLAG)
check_cxx_compiler_flag(-Wno-unused-parameter MPL11_HAS_WNO_UNUSED_PARAMETER_FLAG)
check_cxx_compiler_flag(-Wwrite-strings MPL11_HAS_WWRITE_STRINGS_FLAG)
#=============================================================================
# Setup warning flags
#=============================================================================
macro(append_if condition lst var)
if (${condition})
list(APPEND ${lst} ${var})
endif()
endmacro()
append_if(MPL11_HAS_WALL_FLAG MPL11_CXX_WARNING_FLAGS -Wall)
append_if(MPL11_HAS_WEXTRA_FLAG MPL11_CXX_WARNING_FLAGS -Wextra)
append_if(MPL11_HAS_W_FLAG MPL11_CXX_WARNING_FLAGS -W)
append_if(MPL11_HAS_WNO_UNUSED_LOCAL_TYPEDEFS_FLAG MPL11_CXX_WARNING_FLAGS -Wno-unused-local-typedefs)
append_if(MPL11_HAS_WNO_UNUSED_PARAMETER_FLAG MPL11_CXX_WARNING_FLAGS -Wno-unused-parameter)
append_if(MPL11_HAS_WWRITE_STRINGS_FLAG MPL11_CXX_WARNING_FLAGS -Wwrite-strings)
append_if(MPL11_HAS_WNO_LONG_LONG_FLAG MPL11_CXX_WARNING_FLAGS -Wno-long-long)
append_if(MPL11_HAS_FTEMPLATE_BACKTRACE_LIMIT_0 MPL11_CXX_WARNING_FLAGS -ftemplate-backtrace-limit=0)
if (MPL11_ENABLE_WERROR)
append_if(MPL11_HAS_WERROR_FLAG MPL11_CXX_WARNING_FLAGS -Werror)
append_if(MPL11_HAS_WX_FLAG MPL11_CXX_WARNING_FLAGS -WX)
endif()
if (MPL11_ENABLE_PEDANTIC)
append_if(MPL11_HAS_PEDANTIC_FLAG MPL11_CXX_WARNING_FLAGS -pedantic)
endif()
#=============================================================================
# Setup feature flags
#=============================================================================
append_if(MPL11_HAS_STDCXX1Y_FLAG MPL11_CXX_FEATURE_FLAGS -std=c++1y)
if (MPL11_ENABLE_LIBCXX AND MPL11_HAS_STDLIB_LIBCXX_FLAG)
list(APPEND MPL11_CXX_FEATURE_FLAGS -stdlib=libc++)
endif()
# This is the only place where add_definitions is called. Other properties
# are set on a per-target basis.
add_definitions(
${MPL11_CXX_WARNING_FLAGS}
${MPL11_CXX_FEATURE_FLAGS}
)
#=============================================================================
# Search for packages.
#
# Behavior when the package is found or not is customized at the
# point where the package is required.
#=============================================================================
find_package(Boost)
find_package(Doxygen)
find_package(Gnuplot)
find_package(Ruby 2)
#=============================================================================
# Setup the library
#=============================================================================
include_directories(include)
#=============================================================================
# Setup the documentation
#=============================================================================
if (MPL11_ENABLE_DOC)
add_subdirectory(doc)
endif()
#=============================================================================
# Setup tests
#=============================================================================
if (MPL11_ENABLE_TESTS)
add_subdirectory(test)
endif()
#=============================================================================
# Setup examples
#=============================================================================
if (MPL11_ENABLE_EXAMPLES)
add_subdirectory(example)
endif()