forked from serge-rgb/milton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
192 lines (157 loc) · 4.08 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
cmake_minimum_required(VERSION 3.1)
project(Milton)
if(WIN32)
set(DIRECTX 0)
endif()
add_executable(shadergen
src/shadergen.cc
)
FILE (GLOB ShaderSources src/*.glsl third_party/*.glsl)
add_executable(Milton WIN32 MACOSX_BUNDLE
src/milton.cc
src/memory.cc
src/gui.cc
src/persist.cc
src/color.cc
src/canvas.cc
src/profiler.cc
src/gl_helpers.cc
src/localization.cc
src/renderer.cc
src/utils.cc
src/vector.cc
src/sdl_milton.cc
src/StrokeList.cc
src/third_party_libs.cc
src/shaders.gen.h
)
target_include_directories(Milton PRIVATE
src
third_party
third_party/imgui
)
# Handle various switches, build types etc.
## Helps to know that we're compiling using cmake in milton_configuration.h
add_definitions(-DIS_USING_CMAKE=1)
if(TRY_GL2)
message(STATUS "Compiling for OpenGL2.1")
add_definitions(-DCMAKE_TRY_GL2=1)
elseif(TRY_GL3)
message(STATUS "Compiling for OpenGL3.2")
add_definitions(-DCMAKE_TRY_GL3=1)
endif()
## 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}")
# Platform specific stuff
if(WIN32)
target_sources(Milton PRIVATE
src/platform_windows.cc
)
endif()
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
)
target_sources(Milton PRIVATE
src/platform_unix.cc
)
target_compile_options(shadergen PRIVATE
${UnixCFlags})
target_compile_options(Milton PRIVATE
${UnixCFlags})
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_sources(Milton PRIVATE
src/platform_linux.cc
)
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(GTK2 2.6 REQUIRED gtk)
find_package(X11 REQUIRED)
find_library(XINPUT_LIBRARY libXi.so)
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()
if(NOT SDL2_FOUND)
message(FATAL_ERROR "Could not find SDL2 libraries")
endif()
# on ubuntu 16.04 LTS CMake complains about the -lSDL2 link switch
# having trailing/leading spaces.
# string(STRIP a b) will remove those spaces.
string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES)
target_include_directories(Milton PRIVATE
${GTK2_INCLUDE_DIRS}
${X11_INCLUDE_DIR}
${SDL2_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIR}
)
target_link_libraries(Milton
${GTK2_LIBRARIES}
${X11_LIBRARIES}
${SDL2_LIBRARIES}
${OPENGL_LIBRARIES}
${XINPUT_LIBRARY})
else()
add_subdirectory(third_party/SDL2-2.0.3)
target_link_libraries(Milton SDL2-static)
endif()
if(APPLE)
target_sources(Milton PRIVATE
src/platform_mac.mm
)
target_link_libraries(Milton
"-framework OpenGL"
)
endif()
if(WIN32 OR APPLE)
target_include_directories(Milton PRIVATE
third_party/SDL2-2.0.3/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
)