-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
116 lines (96 loc) · 3.05 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
cmake_minimum_required(VERSION 3.10)
# set the project name and version
project(HatchGameEngine VERSION 1.0)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Set up CMake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
file(GLOB_RECURSE C_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "source/*.c")
file(GLOB_RECURSE CPP_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "source/*.cpp")
set(HATCH_SOURCES ${C_SOURCES} ${CPP_SOURCES})
set(HATCH_TARGET_NAME ${PROJECT_NAME})
IF(TARGET_NAME)
set(HATCH_TARGET_NAME ${TARGET_NAME})
endif()
IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_definitions(-DLINUX -DTARGET_NAME=\"${HATCH_TARGET_NAME}\"
-DUSING_FREETYPE
-DNO_LIBAV
)
else()
# Cross compiling a Windows executable
add_definitions(-DWIN32 -DTARGET_NAME=\"${HATCH_TARGET_NAME}\"
-DNO_LIBAV
-DGLEW_STATIC
-D_WINDOWS
)
endif()
# Build options
option(ENABLE_SCRIPT_COMPILING "Enable script compiling" ON)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
option(WINDOWS_USE_RESOURCE_FILE "Use resource file (Windows)" ON)
endif()
if(NOT ENABLE_SCRIPT_COMPILING)
add_definitions(-DNO_SCRIPT_COMPILING)
endif()
add_custom_target(makeheaders ALL
COMMAND ${CMAKE_SOURCE_DIR}/tools/lmakeheaders source/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS "${CMAKE_SOURCE_DIR}/makeheaders.bin" "${CMAKE_SOURCE_DIR}/include/Engine"
COMMENT "Generating header files")
add_executable(${PROJECT_NAME} ${HATCH_SOURCES})
add_dependencies(${PROJECT_NAME} makeheaders)
set(OUT_EXEC_NAME ${PROJECT_NAME})
# Change executable name
IF(EXECUTABLE_NAME)
set(OUT_EXEC_NAME ${EXECUTABLE_NAME})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${OUT_EXEC_NAME}-${CMAKE_BUILD_TYPE}")
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WIN_RES_FILE meta/win/icon.rc)
if(RESOURCE_FILE)
set(WIN_RES_FILE ${RESOURCE_FILE})
endif()
endif()
# Find the includes
IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
find_package(SDL2 REQUIRED)
find_package(Freetype REQUIRED)
else()
set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/meta/win/include/SDL2/")
endif()
# Add needed directories
include_directories(
include
source
${SDL2_INCLUDE_DIRS}
)
# Include libraries
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# Add all of the Windows include files
include_directories(
meta/win/include
)
if(WINDOWS_USE_RESOURCE_FILE)
target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/${WIN_RES_FILE})
endif()
else()
include_directories(
${FREETYPE_INCLUDE_DIRS}
)
endif()
# Add libraries
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/mingw/${TOOLCHAIN_PREFIX}/libSDL2.a"
-static -mwindows -lmingw32 -lm -ldinput8 -ldxguid -ldxerr8
-luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32
-lversion -luuid -lhid -lsetupapi -lws2_32)
add_definitions(-DSDL_MAIN_HANDLED)
else()
target_link_libraries(${PROJECT_NAME}
${SDL2_LIBRARIES}
${FREETYPE_LIBRARIES}
)
endif()