-
Notifications
You must be signed in to change notification settings - Fork 134
/
CMakeLists.txt
150 lines (120 loc) · 3.21 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
cmake_minimum_required(VERSION 3.1)
project(Milton)
if(WIN32)
set(DIRECTX 0)
endif()
add_executable(shadergen
src/shadergen.cc
)
set(SDL2DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/SDL2-2.0.8)
FILE (GLOB ShaderSources src/*.glsl third_party/*.glsl)
add_executable(Milton WIN32 MACOSX_BUNDLE
src/unity.cc
src/shaders.gen.h
)
target_include_directories(Milton PRIVATE
src
third_party
third_party/imgui
)
# Handle various switches, build types etc.
## Default build type to Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DMILTON_DEBUG=1)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DMILTON_DEBUG=0)
else()
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}. Supported build types: Release, Debug.")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
message(STATUS "Building ${CMAKE_BUILD_TYPE}")
if(UNIX)
set(UnixCFlags
-std=c++11
-Wno-missing-braces
-Wno-unused-function
-Wno-unused-variable
-Wno-unused-result
-Wno-write-strings
-Wno-c++11-compat-deprecated-writable-strings
-Wno-null-dereference
-Wno-format
-fno-strict-aliasing
-fno-omit-frame-pointer
-Wno-extern-c-compat
#-Werror
)
if (APPLE)
set(UnixCFlags "${UnixCFlags}" -ObjC++)
endif()
target_compile_options(shadergen PRIVATE
${UnixCFlags})
target_compile_options(Milton PRIVATE
${UnixCFlags})
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
find_package(OpenGL REQUIRED)
find_package(GTK2 2.6 REQUIRED gtk)
find_package(X11 REQUIRED)
find_library(XINPUT_LIBRARY libXi.so)
find_package(Threads REQUIRED)
if(XINPUT_LIBRARY STREQUAL "XINPUT_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Could not find libXi.so")
endif()
if(NOT OPENGL_FOUND)
message(FATAL_ERROR "Could not find OpenGl libraries")
endif()
if(NOT GTK2_FOUND)
message(FATAL_ERROR "Could not find GTK2.8 libraries")
endif()
if(NOT X11_FOUND)
message(FATAL_ERROR "Could not find X11 libraries")
endif()
target_include_directories(Milton PRIVATE
${GTK2_INCLUDE_DIRS}
${X11_INCLUDE_DIR}
${SDL2DIR}/build/linux64/include/SDL2
${OPENGL_INCLUDE_DIR}
)
target_link_libraries(Milton
${GTK2_LIBRARIES}
${X11_LIBRARIES}
${OPENGL_LIBRARIES}
${XINPUT_LIBRARY}
${SDL2DIR}/build/linux64/lib/libSDL2maind.a
${SDL2DIR}/build/linux64/lib/libSDL2d.a
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
else()
add_subdirectory(${SDL2DIR})
target_link_libraries(Milton SDL2-static)
endif()
if(APPLE)
target_link_libraries(Milton
"-framework OpenGL"
)
endif()
if(WIN32 OR APPLE)
target_include_directories(Milton PRIVATE
${SDL2DIR}/include
)
endif()
add_custom_command(TARGET Milton POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/milton_icon.ico
${CMAKE_CURRENT_LIST_DIR}/third_party/Carlito.ttf
${CMAKE_CURRENT_LIST_DIR}/third_party/Carlito.LICENSE
$<TARGET_FILE_DIR:Milton>
)
add_dependencies(Milton shadergen)
add_custom_command(
COMMAND $<TARGET_FILE:shadergen>
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${ShaderSources}
OUTPUT src/shaders.gen.h
)