forked from TrenchBroom/TrenchBroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
132 lines (107 loc) · 4.9 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
IF(MSVC EQUAL 1)
cmake_minimum_required (VERSION 3.10)
ELSE()
cmake_minimum_required (VERSION 3.1)
ENDIF()
# Configure CCache if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
MESSAGE(STATUS "Using CCache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
# Fix warning with Ninja and cotire (see https://github.com/sakra/cotire/issues/81)
if(POLICY CMP0058)
cmake_policy(SET CMP0058 NEW)
endif()
# SET(CMAKE_VERBOSE_MAKEFILE ON)
INCLUDE(cmake/Utils.cmake)
# Using C and CXX because GLEW is C
PROJECT(TrenchBroom C CXX)
# Compiler detection
SET(COMPILER_IS_CLANG FALSE)
SET(COMPILER_IS_GNU FALSE)
SET(COMPILER_IS_MSVC FALSE)
IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
SET(COMPILER_IS_CLANG TRUE)
ENDIF()
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_IS_GNU TRUE)
ENDIF()
IF(MSVC EQUAL 1)
SET(COMPILER_IS_MSVC TRUE)
ENDIF()
# Compiler configuration
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Mac OS X specific configuration. In theory must be done before the PROJECT directive, but that doesn't actually work.
# These settings are ignored on other platforms
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
# Library configuration
SET(LIB_DIR "${CMAKE_SOURCE_DIR}/lib")
SET(LIB_BIN_DIR "${LIB_DIR}/bin")
SET(LIB_INCLUDE_DIR "${LIB_DIR}/include")
SET(LIB_SOURCE_DIR "${LIB_DIR}/src")
# Required wxWidgets version
SET(TB_MIN_wxWidgets_VERSION_MAJOR 3)
SET(TB_MIN_wxWidgets_VERSION_MINOR 1)
SET(TB_MIN_wxWidgets_VERSION_PATCH 1)
IF(COMPILER_IS_CLANG)
MESSAGE(STATUS "Compiler is Clang")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Weverything -pedantic -Wno-format -Wno-variadic-macros -Wno-c99-extensions -Wno-padded -Wno-unused-parameter -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-weak-template-vtables -Wno-float-equal -Wno-used-but-marked-unused -Wno-format-nonliteral -Wno-missing-noreturn -Wno-unused-local-typedef -Wno-double-promotion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-implicit-fallthrough -Wno-zero-as-null-pointer-constant")
ELSEIF(COMPILER_IS_GNU)
MESSAGE(STATUS "Compiler is GNU")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-format -Wno-variadic-macros -Wno-padded -Wno-unused-parameter -Wno-float-equal -Wno-format-nonliteral -Wno-missing-noreturn -Wno-zero-as-null-pointer-constant -Wno-error=maybe-uninitialized")
ELSEIF(COMPILER_IS_MSVC)
MESSAGE(STATUS "Compiler is MSVC")
STRING(REGEX REPLACE "/W |/W$" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
STRING(REGEX REPLACE "/W |/W$" "/W3" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
# Generate debug symbols even for Release; we build a stripped pdb in Release mode, see TrenchBroomApp.cmake
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
ELSE()
MESSAGE(FATAL_ERROR "Unsupported compiler detected.")
ENDIF()
IF(TB_ENABLE_ASAN)
MESSAGE(STATUS "AddressSanitizer requested via TB_ENABLE_ASAN cmake variable")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
# Workaround for false positives on macOS
IF(COMPILER_IS_CLANG)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LIBCPP_HAS_NO_ASAN")
ENDIF()
ENDIF()
IF(CMAKE_GENERATOR STREQUAL "Xcode")
# Xcode requires these flags to allow debugging
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -O0 -fno-inline")
# Xcode should treat the library header files as system headers
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${LIB_INCLUDE_DIR}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${LIB_INCLUDE_DIR}")
ELSE()
INCLUDE_DIRECTORIES(SYSTEM "${LIB_INCLUDE_DIR}")
ENDIF()
# Set debug mode directives
IF(CMAKE_BUILD_TYPE MATCHES "Debug")
ADD_DEFINITIONS(-DWXDEBUG -DDEBUG)
ENDIF()
INCLUDE(cmake/wxWidgets.cmake)
INCLUDE(cmake/FreeType.cmake)
INCLUDE(cmake/FreeImage.cmake)
# Should be changed to use per directory CMakeList.txt and ADD_SUBDIRECTORY
INCLUDE(cmake/GTest.cmake)
INCLUDE(cmake/GMock.cmake)
INCLUDE(cmake/Glew.cmake)
INCLUDE(cmake/tinyxml2.cmake)
INCLUDE(cmake/vecmath.cmake)
INCLUDE(cmake/Common.cmake)
INCLUDE(cmake/StackWalker.cmake)
INCLUDE(cmake/miniz.cmake)
INCLUDE(cmake/TrenchBroomApp.cmake)
INCLUDE(cmake/TrenchBroomTest.cmake)