forked from suikki/simpleSDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
108 lines (84 loc) · 2.72 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
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(simpleSDL C CXX)
#
# Set some helper variables.
#
string(TOLOWER "${CMAKE_SYSTEM_NAME}" targetSystem)
set(projectDir "${CMAKE_CURRENT_LIST_DIR}")
set(sourceDir "${projectDir}/source")
set(targetName "SimpleExample")
set(binDir "${projectDir}/bin")
# 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")
#
# Dependencies:
# Using SDL as a subproject for simplicity.
# NOTE: This means that CMAKE_C_FLAGS set anywhere here are also passed to SDL.
#
if(MINGW)
set(VIDEO_OPENGLES OFF CACHE STRING "")
endif()
set(sdlDir "${projectDir}/contrib/SDL")
add_subdirectory(${sdlDir} EXCLUDE_FROM_ALL)
set(SDL2MAIN_LIBRARY SDL2main)
set(SDL2_LIBRARY SDL2)
# Joysticks were causing trouble on android.
add_definitions(-DSDL_JOYSTICK=0)
#
# Sources (relative to the project root dir).
#
set(projectSources
source/main.c
# Use this instead for an opengl example
#source/main_opengl.c
)
# Include dirs.
set(projectIncludeDirs ${projectIncludeDirs}
"${sdlDir}/include"
)
message(" Sources: ${projectSources}\n")
message("Include dirs: ${projectIncludeDirs}\n")
#
# Platform dependent stuff.
#
if(NOT ANDROID)
find_package(OpenGL REQUIRED)
endif()
if(MINGW)
# -Link standard libs statically to reduce dll clutter.
# -lmingw32 is needed to make WinMain not disappear when linking.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -static-libgcc -lmingw32")
# Only show the console in debug builds and also strip unused dependencies on MinSizeRel.
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-mconsole")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-mwindows")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-mwindows -s")
endif()
if(EMSCRIPTEN)
# This makes emscripten build a html page in addition to the js code.
set(CMAKE_EXECUTABLE_SUFFIX ".html")
# Embedding and mapping files at from_path@to_path
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ../../assets@/")
# Emscripten requires static linking.
set(SDL2_LIBRARY SDL2-static)
endif()
#
# Build the 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_link_libraries(${targetName}
${SDL2MAIN_LIBRARY}
${SDL2_LIBRARY}
${OPENGL_LIBRARY}
)
target_include_directories(${targetName}
PUBLIC ${projectIncludeDirs}
)