-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
103 lines (88 loc) · 4.12 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
cmake_minimum_required(VERSION 2.8.12)
project("sdfparse")
message(STATUS "CMAKE_CONFIGURATION_TYPES: ${CMAKE_CONFIGURATION_TYPES}")
#
#
# Determine compiler configuration
#
#
#Set the default build type if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build: None, Debug, Release, RelWithDebInfo, MinSizeRel"
FORCE)
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
#We want assertions to stay on in release.
#Remove the DNDEBUG macro that cmake defines by default for release types.
set(NDEBUG_REGEX "[/-]D *NDEBUG")
foreach(flags_to_scrub CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO MAKE_CXX_FLAGS_MINSIZEREL)
string(REGEX REPLACE ${NDEBUG_REGEX} "" "${flags_to_scrub}" "${${flags_to_scrub}}")
endforeach()
#Compiler flag configuration checks
include(CheckCXXCompilerFlag)
#
# We require c++11 support
#
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11_FLAG)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X_FLAG)
if(COMPILER_SUPPORTS_CXX11_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(WARNING "Could not determine C++11 support for compiler ${CMAKE_CXX_COMPILER}. C++11 support is required.")
endif()
#
# Debug/Opt flags
#
#Support for optimization that don't interfere with debugging?
CHECK_CXX_COMPILER_FLAG("-Og" COMPILER_SUPPORTS_-Og)
if(COMPILER_SUPPORTS_-Og)
#Currently disable, Og still causes some variables to be optimized away
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
endif()
#Support for including non-inlined versions of inlined functions (useful for interactive debugging)
CHECK_CXX_COMPILER_FLAG("-fkeep-inline-functions" COMPILER_SUPPORTS_-fkeep-inline-functions)
if(COMPILER_SUPPORTS_-fkeep-inline-functions)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fkeep-inline-functions")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fkeep-inline-functions")
endif()
#
# Warning flags
#
set(WARN_FLAGS "") #The actual warning flags to be applied
set(WARN_FLAGS_TO_CHECK #The flags to check if the compiler supports
#GCC-like
"-Wall" #Most warnings, typically good
"-Wextra" #Extra warning, usually good
"-pedantic" #Ensure ISO compliance (i.e. no non-standard extensions)
"-Wcast-qual" #Warn if cast removes qualifier (e.g. const char* -> char*)
"-Wcast-align" #Warn if a cast causes memory alignment changes
"-Wshadow" #Warn if local variable shadows another variable
"-Wformat=2" #Sanity checks for printf-like formatting
"-Wlogical-op" #Checks for logical op when bit-wise expected
"-Wmissing-declarations" #Warn if a global function is defined with no delcaration in a header file
"-Wmissing-include-dirs" #Warn if a user include directory is missing
"-Wredundant-decls" #Warn if there are overlapping declarations
"-Wswitch-default" #Warn if a switch has no default
"-Wundef" #Warn if #if() preprocessor refers to an undefined directive
"-Wunused-variable" #Warn about variables that are not used
"-Wno-unused-parameter" #Don't worry about unused function parameters
#GCC-like optional
#"-Wsign-conversion" #Warn if a conversion may change the sign
#"-Wpadded" #Will warn if additional padding is introduced to a struct/class. Turn on if optimizing class memory layouts
)
#Check and see if the compiler supports the various warning flags,
#and add valid flags
foreach(flag ${WARN_FLAGS_TO_CHECK})
CHECK_CXX_COMPILER_FLAG(${flag} COMPILER_SUPPORTS_${flag})
if(COMPILER_SUPPORTS_${flag})
#Flag supported, so enable it
set(WARN_FLAGS "${WARN_FLAGS} ${flag}")
endif()
endforeach()
#Apply the warning flags to all build types
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
add_subdirectory(src)