forked from JoshParnell/ltheory-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
205 lines (159 loc) · 5.26 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
cmake_minimum_required (VERSION 3.0)
project(LTheory)
find_package(OpenGL REQUIRED)
# force SFML to build as a static lib to minimize pain
set(BUILD_SHARED_LIBS FALSE CACHE BOOL "" FORCE)
add_subdirectory(ext/SFML)
function (configure_output_dir target)
set_target_properties (${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
foreach (config ${CMAKE_CONFIGURATION_TYPES})
string (TOUPPER ${config} config)
set_target_properties (${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${config} "${CMAKE_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY_${config} "${CMAKE_SOURCE_DIR}/bin"
ARCHIVE_OUTPUT_DIRECTORY_${config} "${CMAKE_SOURCE_DIR}/bin")
endforeach (config)
endfunction ()
# Set build path
set(BUILD_DIR ${CMAKE_BINARY_DIR})
set(EXECUTABLE_OUTPUT_PATH ${BUILD_DIR} CACHE PATH "Build directory" FORCE)
set(LIBRARY_OUTPUT_PATH ${BUILD_DIR} CACHE PATH "Build directory" FORCE)
# Detect OS
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(LINUX 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MAC 1)
else()
message(FATAL_ERROR "Unsupported operating system")
return()
endif()
# Detect Architecture
include(CheckTypeSize)
check_type_size(void* SIZEOF_VOID_PTR)
if("${SIZEOF_VOID_PTR}" STREQUAL "4")
set(ARCH_32 1)
elseif("${SIZEOF_VOID_PTR}" STREQUAL "8")
set(ARCH_64 1)
else()
message(FATAL_ERROR "Unsupported architecture")
return()
endif()
# Get ext includes
include_directories(src/liblt
include
include/FreeType
ext/SFML/include)
# Get ext libraries
if(WINDOWS)
file(GLOB_RECURSE EXTLIB extlib/win32/*.lib)
set(LINK_LIBRARIES
${GLEW_GLEW_LIBRARY}
sfml-graphics
sfml-network
sfml-system
sfml-window)
elseif(MAC)
set(LINK_LIBRARIES
# enet
fmodex
fmodevent
freetype
GLEW
sfml-graphics
sfml-network
sfml-system
sfml-window
)
link_directories(${PROJECT_SOURCE_DIR}/extbin/osx)
elseif(LINUX)
set(LINK_LIBRARIES
dl
# enet
freetype
sfml-graphics
sfml-network
sfml-system
sfml-window
GLEW)
if(ARCH_32)
set(LINK_LIBRARIES ${LINK_LIBRARIES} fmodex fmodevent)
link_directories(${PROJECT_SOURCE_DIR}/extbin/linux32)
elseif(ARCH_64)
set(LINK_LIBRARIES ${LINK_LIBRARIES} fmodex64 fmodevent64)
link_directories(${PROJECT_SOURCE_DIR}/extbin/linux64)
endif()
endif()
set(LINK_LIBRARIES ${LINK_LIBRARIES} ${OPENGL_LIBRARIES})
# Build shared libary
file(GLOB_RECURSE LIBLT_SRC src/liblt/*.cpp)
add_library(lt SHARED ${LIBLT_SRC})
target_link_libraries(lt ${LINK_LIBRARIES} ${EXTLIB})
configure_output_dir(lt)
# Post-build step to copy DLLs to bin folder
if (MSVC)
file(GLOB_RECURSE RUNTIME_BINARIES extbin/win32/*.dll)
foreach(X ${RUNTIME_BINARIES})
add_custom_command (TARGET lt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${X} $<TARGET_FILE_DIR:lt>)
endforeach(X)
endif()
# Build binaries
set(TARGETS
launch)
foreach(TARGET ${TARGETS})
add_executable(${TARGET} ${PROJECT_SOURCE_DIR}/src/${TARGET}/${TARGET}.cpp src/resources.rc)
target_link_libraries(${TARGET} ${LINK_LIBRARIES})
configure_output_dir(${TARGET})
endforeach(TARGET)
# Link dynamic targets to the shared lib
foreach(TARGET ${TARGETS})
target_link_libraries(${TARGET} lt)
endforeach(TARGET)
# Set target properties
if(WINDOWS)
# No exception handling
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs")
# Multi-threaded compilation
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
# No libcmt warnings
set_target_properties(lt PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libcmt")
foreach(TARGET ${EXECUTABLES})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libcmt")
endforeach(TARGET)
# The updater requires administrator privileges to run
# set_target_properties(updater PROPERTIES LINK_FLAGS "/level='requireAdministrator' /uiAccess='false'")
else()
# Gold linker
if (LINUX)
set(CMAKE_LINKER "/usr/bin/gold")
endif()
# No exception handling
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
# Enable C++0x features
add_definitions("-std=c++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g")
# Enable lots of warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-const-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-tautological-compare")
# Stop on errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-conversion")
# Enable SSE / SSE2
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2")
endif()