-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
154 lines (129 loc) · 5.18 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
CMAKE_MINIMUM_REQUIRED( VERSION 3.13 )
SET( PROJECT_NAME GLSMAC )
PROJECT( ${PROJECT_NAME} LANGUAGES CXX )
SET( CMAKE_MODULE_PATH "." )
SET( EXECUTABLE_OUTPUT_PATH "bin" )
SET( SRC "" )
SET( PWD "." )
ADD_CUSTOM_TARGET( glsmac_version )
IF ( NOT WIN32 )
ADD_CUSTOM_COMMAND(
TARGET glsmac_version PRE_BUILD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND git show -s --format='\#define GLSMAC_LAST_COMMIT \"%h\"' > ${PROJECT_SOURCE_DIR}/src/tmp/last_commit.h
DEPENDS .git/COMMIT_EDITMSG
)
ENDIF ()
FUNCTION( SUBDIR DIR )
SET( PWD "${PWD}/${DIR}" )
ADD_SUBDIRECTORY( ${DIR} )
SET( SRC ${SRC} PARENT_SCOPE )
ENDFUNCTION( SUBDIR )
SUBDIR( src )
ADD_EXECUTABLE( ${PROJECT_NAME}
${SRC}
)
IF ( NOT WIN32 )
TARGET_COMPILE_DEFINITIONS( ${PROJECT_NAME} PRIVATE TMP_LAST_COMMIT_H_GENERATED=1 )
ENDIF ()
IF ( CMAKE_BUILD_TYPE STREQUAL "" )
SET( CMAKE_BUILD_TYPE "Release" ) # release by default
ENDIF ()
# not using -Og for debug builds because it optimizes some variables out
IF ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
TARGET_COMPILE_DEFINITIONS( ${PROJECT_NAME} PRIVATE DEBUG=1 )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -O0" )
ELSE ()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
IF ( CMAKE_BUILD_TYPE STREQUAL "Portable" )
MESSAGE( FATAL_ERROR "Portable target is deprecated, please use Portable32 or Portable64 instead" )
ELSEIF ( CMAKE_BUILD_TYPE STREQUAL "Portable64" OR CMAKE_BUILD_TYPE STREQUAL "Portable32" )
TARGET_COMPILE_DEFINITIONS( ${PROJECT_NAME} PRIVATE PORTABLE=1 )
SET( VENDORED_DEPENDENCIES 1 ) # for static linking
IF ( WIN32 )
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -static ) # this won't work on linux because there may be binary video drivers without static libraries
ELSE ()
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -static-libgcc -static-libstdc++ )
ENDIF ()
IF ( CMAKE_BUILD_TYPE STREQUAL "Portable32" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -march=i686 -mtune=i686" )
ELSEIF ( CMAKE_BUILD_TYPE STREQUAL "Portable64" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -march=x86-64 -mtune=k8" )
ENDIF ()
ELSEIF ( CMAKE_BUILD_TYPE STREQUAL "Release" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" )
ELSE ()
MESSAGE( FATAL_ERROR "Invalid CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\", use one of: \nDebug\nRelease\nPortable32\nPortable64" )
ENDIF ()
ENDIF ()
INCLUDE_DIRECTORIES( "src" )
IF ( VISUAL_STUDIO ) # (Provided in CMakePresets)
ADD_COMPILE_DEFINITIONS( _ITERATOR_DEBUG_LEVEL=0 )
ADD_COMPILE_DEFINITIONS( VISUAL_STUDIO )
ELSEIF ( WIN32 ) # probably mingw or github runner
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE wsock32 )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE ws2_32 )
ENDIF ()
# needed for some uncommon IDE and OS combinations
FIND_LIBRARY( LIBCPP_LIBRARY NAMES libc++.so libc++.a )
IF ( LIBCPP_LIBRARY )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE -lc++ )
ENDIF ()
FIND_LIBRARY( LIBM_LIBRARY NAMES libm.so libm.a )
IF ( LIBM_LIBRARY )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE -lm )
ENDIF ()
IF ( VENDORED_DEPENDENCIES )
ADD_SUBDIRECTORY( dependencies )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE libglew_static )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE freetype )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE SDL2-static )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE SDL2_image )
IF ( NOT WIN32 ) # TODO: make it buildable on windows
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE ossp-uuid )
ENDIF ()
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE yaml-cpp )
ADD_COMPILE_DEFINITIONS( VENDORED_DEPENDENCIES )
TARGET_INCLUDE_DIRECTORIES( ${PROJECT_NAME} PUBLIC
"${glew_SOURCE_DIR}/include"
"${OSSP_UUID_INCLUDE_DIR}"
"${YAML_CPP_SOURCE_DIR}/include"
)
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PUBLIC
"${OSSP_UUID_LINK_OPTIONS}"
"${YAML_CPP_LINK_OPTIONS}"
)
ELSE ()
INCLUDE( FindPkgConfig )
PKG_SEARCH_MODULE( FT2 REQUIRED freetype2 )
PKG_SEARCH_MODULE( SDL2 REQUIRED sdl2 )
PKG_SEARCH_MODULE( SDL2IMAGE REQUIRED SDL2_image>=2.0.0 )
PKG_SEARCH_MODULE( GLEW REQUIRED glew )
IF ( NOT APPLE )
PKG_SEARCH_MODULE( OSSPUUID REQUIRED ossp-uuid )
ELSE ()
PKG_SEARCH_MODULE( OSSPUUID REQUIRED uuid )
ENDIF ()
PKG_SEARCH_MODULE( YAMLCPP REQUIRED yaml-cpp )
INCLUDE_DIRECTORIES( ${FT2_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${OSSPUUID_INCLUDE_DIRS} ${YAMLCPP_INCLUDE_DIRS} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE ${FT2_LIBRARIES} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${GLEW_LIBRARIES} ${OSSPUUID_LIBRARIES} ${YAMLCPP_LIBRARIES} )
ENDIF ()
IF ( NOT WIN32 )
ADD_DEPENDENCIES( ${PROJECT_NAME} glsmac_version )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE ${FT2_LDFLAGS} ${GLEW_LDFLAGS} ${SDL2_LDFLAGS} ${SDL2IMAGE_LDFLAGS} )
ENDIF ()
IF ( APPLE )
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -framework OpenGL )
ENDIF ()
IF ( WIN32 )
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -lws2_32 )
ENDIF()
SET( CMAKE_CXX_FLAGS " -std=c++17 ${CMAKE_CXX_FLAGS} -Wno-pointer-arith -Wno-vla-cxx-extension" )
IF (
CMAKE_BUILD_TYPE STREQUAL "Release" OR
CMAKE_BUILD_TYPE STREQUAL "Portable64" OR
CMAKE_BUILD_TYPE STREQUAL "Portable32"
)
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE "-s" )
ENDIF ()