-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
184 lines (152 loc) · 6.2 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# needed by the file function
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4)
PROJECT(SpeakEasy)
SET(INFO_MESSAGE "Build SpeakEasy")
# see full compilation lines
# SET(CMAKE_VERBOSE_MAKEFILE 1)
# add color on CMake output
SET(CMAKE_COLOR_MAKEFILE ON)
# set the default build type to Debug if no build type is set.
IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF()
IF(CMAKE_BUILD_TYPE)
SET(INFO_MESSAGE "${INFO_MESSAGE} (${CMAKE_BUILD_TYPE})")
ENDIF()
# Add a define to know when we want to compile a debug build
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSE_DEBUG")
# set the destination of the executable
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
################################################################################
# Build options
OPTION(BUILD_TESTS "Build Tests" ON)
OPTION(BUILD_DOCUMENTATION "Build Documentation" ON)
FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(Threads REQUIRED)
################################################################################
# Try to determine informations about the version we try to build
FIND_PACKAGE(Git) # OPTIONAL
IF(GIT_FOUND)
# launch the git binary we just found to get the latest revision SHA1
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} log -n 1 --date=short --no-color --format=git\ rev\ %h\ \(%ad\)
WORKING_DIRECTORY ${SpeakEasy_SOURCE_DIR}
OUTPUT_VARIABLE GIT_INFORMATIONS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
ENDIF()
IF(NOT GIT_INFORMATIONS)
# TODO set this information to the packaged version if needed
SET(GIT_INFORMATIONS "version unknown")
ENDIF()
################################################################################
################################################################################
# Documentation
IF(BUILD_DOCUMENTATION)
# add a target to generate API documentation with Doxygen
FIND_PACKAGE(Doxygen)
IF(DOXYGEN_FOUND)
SET(INFO_MESSAGE "${INFO_MESSAGE} - Doxygen target")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
ADD_CUSTOM_TARGET(doc
${DOXYGEN_EXECUTABLE}
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Doxygen" VERBATIM)
ENDIF()
ENDIF()
################################################################################
################################################################################
# Add the third parties
# @note: the folder is intentionally added before our compiler settings
ADD_SUBDIRECTORY(extern)
################################################################################
################################################################################
# Enable max compiler debugging output
IF(MSVC) # Visual Studio
SET(CMAKE_CXX_WARNING_LEVEL 4)
# Force it, because most of the time the above line is not enough
IF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4"
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ENDIF()
ENDIF()
IF(UNIX)
# Enable c++11
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Disable RTTI
ADD_DEFINITIONS(-fno-rtti)
# Disable Exceptions
ADD_DEFINITIONS(-fno-exceptions)
# Warnings as error
#ADD_DEFINITIONS(-Werror)
# Setup warnings
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Blacklist mode
ADD_DEFINITIONS(
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-date-time
)
ELSE()
# Whitelist mode
ADD_DEFINITIONS(
-Wall
-Wextra
-W
-Wpadded
-Wshadow
-Woverloaded-virtual
-Wwrite-strings
-Wnon-virtual-dtor
-Wunreachable-code
)
ENDIF()
ENDIF()
################################################################################
ADD_SUBDIRECTORY(src)
# TODO find a more elegant way to do that...
SET(SHADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/)
################################################################################
# generate a header file to inform the code of various settings
# set the edit warning message to be inserted in the header
SET(EDIT_WARNING "This file is autogenerated, please do not edit")
CONFIGURE_FILE(${SpeakEasy_SOURCE_DIR}/src/config.h.cmake
${SpeakEasy_BINARY_DIR}/src/config.h)
################################################################################
################################################################################
# CPack
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "1")
SET(CPACK_SOURCE_GENERATOR "TBZ2")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_SOURCE_IGNORE_FILES
"/build/;~$;/.git;kdev;${CPACK_SOURCE_IGNORE_FILES}")
# Must be included *AFTER* setting its properties
INCLUDE(CPack)
################################################################################
################################################################################
# Tests
IF(BUILD_TESTS)
SET(INFO_MESSAGE "${INFO_MESSAGE} - Unit Tests")
ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)
ENDIF()
################################################################################
################################################################################
# Status message
# These lines will generate a line of '*' the same length as info_message
STRING(LENGTH ${INFO_MESSAGE} INFO_MESSAGE_LENGTH)
STRING(SUBSTRING
"***********************************************************************"
0 ${INFO_MESSAGE_LENGTH}
STARS_MESSAGE)
MESSAGE(STATUS ${STARS_MESSAGE})
MESSAGE(STATUS ${INFO_MESSAGE})
MESSAGE(STATUS ${STARS_MESSAGE})
################################################################################