-
Notifications
You must be signed in to change notification settings - Fork 7
/
BuildOptions.cmake
93 lines (77 loc) · 4.72 KB
/
BuildOptions.cmake
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
#
# Setup the build type and compiler options.
#
# To set the build type, run the following command with a build type of DEBUG, RELEASE, or MINSIZEREL:
# cmake <path-to-source> -DCMAKE_BUILD_TYPE=<build-type>
#
# If no build type is specified by specifying it on the command line, default to debug.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: DEBUG, RELEASE, or MINSIZEREL." FORCE)
message("No build type specified, defaulting to Release.")
endif()
# Verify the build type is valid.
set(buildTypes DEBUG RELEASE MINSIZEREL)
string(TOUPPER "${CMAKE_BUILD_TYPE}" buildType)
list(FIND buildTypes "${buildType}" buildTypeFound)
if (buildTypeFound EQUAL -1)
string(LENGTH "${CMAKE_BUILD_TYPE}" buildTypeLen)
math(EXPR buildTypePadLen "72 - ${buildTypeLen}")
if (buildTypePadLen GREATER 0)
string(RANDOM LENGTH "${buildTypePadLen}" ALPHABET " " buildTypePad)
endif()
message("###############################################################################")
message("# #")
message("# ERROR: #")
message("# Unknown build type selected. Please select from DEBUG, RELEASE, or #")
message("# MINSIZEREL. #")
message("# #")
message("# Build Type: #")
message("# ${buildType}${buildTypePad}#")
message("# #")
message("###############################################################################")
message(FATAL_ERROR "Unknown build type ${buildType}. Please select from DEBUG, RELEASE, or MINSIZEREL. Quitting!")
else()
message("Creating the build directory for the ${PROJECT_NAME} with build type: ${buildType}")
endif()
# Set up the compiler flags.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--disable-new-dtags")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")
endif()
# Determine the platform and compiler dependent flags.
if (UNIX OR CMAKE_COMPILER_IS_GNUCXX)
set(CXX_PLATFORM_DEPENDENT_FLAGS_DEBUG "-DDEBUG -Wall -Wsign-compare -g")
set(CXX_PLATFORM_DEPENDENT_FLAGS_RELEASE "-DNDEBUG -Wall -O2")
set(CXX_PLATFORM_DEPENDENT_FLAGS_MINSIZEREL "-DNDEBUG -Wall -Os")
if (CMAKE_COMPILER_IS_GNUCXX AND (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0")))
set(CXX_PLATFORM_DEPENDENT_FLAGS_DEBUG "${CXX_PLATFORM_DEPENDENT_FLAGS_DEBUG} -Wno-error=class-memaccess")
set(CXX_PLATFORM_DEPENDENT_FLAGS_RELEASE "${CXX_PLATFORM_DEPENDENT_FLAGS_RELEASE} -Wno-error=class-memaccess")
set(CXX_PLATFORM_DEPENDENT_FLAGS_MINSIZEREL "${CXX_PLATFORM_DEPENDENT_FLAGS_MINSIZEREL} -Wno-error=class-memaccess")
endif()
elseif(MSVC)
set(CXX_PLATFORM_DEPENDENT_FLAGS_DEBUG "/DDEBUG /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING /W4 /Zi /VZ /ZW /Od /MDd")
set(CXX_PLATFORM_DEPENDENT_FLAGS_RELEASE "/DNDEBUG /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING /W4 /O2 /VZ /ZW /MD")
set(CXX_PLATFORM_DEPENDENT_FLAGS_MINSIZEREL "/DNDEBUG /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING /W4 /O1 /VZ /ZW /MD")
add_definitions("-DNOMINMAX")
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
#set_property(DIRECTORY
# PROPERTY
# CMAKE_SYSTEM_NAME WindowsStore)
#set_property(DIRECTORY
# PROPERTY
# CMAKE_SYSTEM_VERSION 10.0)
#set(BUILD_SHARED_LIBS TRUE CACHE BOOL "Avoid unit tests link error in MSVC")
endif()
# Debug build, default.
set(CMAKE_CXX_FLAGS_DEBUG "${CXX_PLATFORM_DEPENDENT_FLAGS_DEBUG} -DRAPIDJSON_HAS_STDSTRING" CACHE INTERNAL "Flags used for DEBUG builds" FORCE)
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE INTERNAL "Flags used for DEBUG builds" FORCE)
# Release build.
set(CMAKE_CXX_FLAGS_RELEASE "${CXX_PLATFORM_DEPENDENT_FLAGS_RELEASE} -DRAPIDJSON_HAS_STDSTRING" CACHE INTERNAL "Flags used for RELEASE builds" FORCE)
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE INTERNAL "Flags used for RELEASE builds" FORCE)
# Minimum sized release build.
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CXX_PLATFORM_DEPENDENT_FLAGS_MINSIZEREL} -DRAPIDJSON_HAS_STDSTRING" CACHE INTERNAL "Flags used for minimum sized RELEASE builds" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_RELEASE} CACHE INTERNAL "Flags used for minimum sized RELEASE builds" FORCE)