-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
115 lines (94 loc) · 3.53 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
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(sdf_text)
# Some general project setup and helper functions moved to a separate file.
include(helpers.cmake)
#
# Set some helper variables.
#
set(projectDir "${CMAKE_CURRENT_LIST_DIR}")
set(binDir "${projectDir}/bin")
# Build target name (Also the default output binary name).
# NOTE: if you change this you also need to change your Android activity Java code accordingly.
set(targetName "sdf_text")
# Define executable output dir.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${binDir}/${targetSystem}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${binDir}/${targetSystem}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${binDir}/${targetSystem}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${binDir}/${targetSystem}_debug")
#
# App sources and includes (relative to the project root dir).
#
set(projectSources
# Note: headers are only listed to show up in generated IDE projects.
# Only the C-files need to be compiled.
source/okwrapper/okapp.h
source/okwrapper/oklog.h
source/okwrapper/okgl.h
source/okwrapper/okgl_helper.h
source/okwrapper/okplatform.h
source/main.c
source/sdf_text_app.c
)
set(projectIncludeDirs ${projectIncludeDirs}
source
)
if(NOT MSVC)
# Link to the c math library (not when using msvc).
set(projectLinkLibs ${projectLinkLibs} m)
endif()
#
# Depencency: Fontstash (header only library).
#
set(projectIncludeDirs ${projectIncludeDirs} "external/fontstash/src")
#
# Depencency: GLEW (only when not using OpenGL ES).
#
if(NOT ANDROID AND NOT EMSCRIPTEN)
add_subdirectory("external/glew-2.1.0/build/cmake" EXCLUDE_FROM_ALL)
# Using static linking for now to remove one more lib to install.
set(projectLinkLibs ${projectLinkLibs} glew_s)
set(projectIncludeDirs ${projectIncludeDirs} "${projectDir}/external/glew-2.1.0/include")
endif()
#
# Depencency: SDL2.
#
if(TRUE)
# Use prebuilt SDL binaries.
add_subdirectory("external/SDL-prebuilt" EXCLUDE_FROM_ALL)
set(projectLinkLibs ${projectLinkLibs} SDL2-prebuilt)
else()
# Build SDL from source.
# TODO: not tested for a while.
# TODO: Emscripten requires static linking if using SDL sources.
add_subdirectory("external/SDL" EXCLUDE_FROM_ALL)
set(projectIncludeDirs ${projectIncludeDirs} "${projectDir}/external/SDL/include")
set(projectLinkLibs ${projectLinkLibs} SDL2main SDL2)
endif()
#
# Configure the application executable. ${targetName} is also the default name
# for the output binary.
#
if(ANDROID)
# On android the final binary is a shared library not an executable.
add_library(${targetName} SHARED ${projectSources})
else()
add_executable(${targetName} ${projectSources})
endif()
target_include_directories(${targetName} PUBLIC ${projectIncludeDirs})
target_link_libraries(${targetName} ${projectLinkLibs} )
# Using C99 standard.
set_property(TARGET ${targetName} PROPERTY C_STANDARD 99)
# Enabling/disabling compiler warnings.
if(CMAKE_COMPILER_IS_GNUCC)
target_compile_options(${targetName} PRIVATE "-Wall" "-Wextra" "-pedantic" "-Wno-unused-function" "-Wno-unused-parameter")
elseif(MSVC)
#target_compile_options(${targetName} PRIVATE "/W4")
# Disabling some MSVC warnings for now. Should go through these and fix sometime.
target_compile_definitions(${targetName} PRIVATE "_CRT_SECURE_NO_WARNINGS")
endif()
#
# This will automatically copy any predefined binary dependencies to the output dir
# (pretty much just here for windows dlls). It looks for a custom property in each
# target that list files that need to be copied.
#
target_copy_binary_dependencies(${targetName} "${projectLinkLibs}")