-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
126 lines (102 loc) · 4.59 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
cmake_minimum_required(VERSION 2.8.8)
include(ExternalProject)
include(FindPkgConfig)
project(g1)
find_package(OpenGL REQUIRED)
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
find_package(Lua REQUIRED)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer)
pkg_search_module(LIBEPOXY REQUIRED epoxy)
if (("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR
("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD"))
pkg_search_module(HIDAPI OPTIONAL hidapi-libusb)
else ()
pkg_search_module(HIDAPI OPTIONAL hidapi)
endif ()
find_library(LIBTXC_DXTN txc_dxtn)
if (${LUA_VERSION_MAJOR} LESS 5 OR (${LUA_VERSION_MAJOR} EQUAL 5 AND
${LUA_VERSION_MINOR} LESS 2))
message(FATAL_ERROR "Lua 5.2+ required \
(${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} found)")
endif ()
if (NOT LIBTXC_DXTN)
message(FATAL_ERROR "libtxc_dxtn not found!")
endif (NOT LIBTXC_DXTN)
if (NOT TARGET_ARCHITECTURE)
set(MARCH -march=native)
set(MTUNE -mtune=native)
elseif ("${TARGET_ARCHITECTURE}" STREQUAL "generic")
set(MARCH -march=x86-64)
set(MTUNE -mtune=generic)
else ()
set(MARCH -march=${TARGET_ARCHITECTURE})
set(MTUNE -mtune=${TARGET_ARCHITECTURE})
endif ()
ExternalProject_Add(
dake_source
GIT_REPOSITORY git://github.com/XanClic/dake.git
GIT_TAG origin/master
SOURCE_DIR dake
CMAKE_COMMAND true
BUILD_COMMAND ${CMAKE_MAKE_PROGRAM}
"CC=${CMAKE_C_COMPILER}"
"CXX=${CMAKE_CXX_COMPILER}"
"MARCH=${MARCH}"
"MTUNE=${MTUNE}"
libdake.a
BINARY_DIR dake
INSTALL_COMMAND true
)
ExternalProject_Get_Property(dake_source binary_dir)
set(dake_dir "${binary_dir}")
add_library(dake IMPORTED STATIC)
add_dependencies(dake dake_source)
set_property(TARGET dake APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(dake PROPERTIES IMPORTED_LOCATION_NOCONFIG "${binary_dir}/libdake.a")
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/include"
COMMAND mkdir -p "${CMAKE_BINARY_DIR}/include")
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/include/json-structs.hpp" "${CMAKE_BINARY_DIR}/serializer.cpp"
COMMAND "${CMAKE_SOURCE_DIR}/tools/generate-serializer.rb" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}"
DEPENDS json-structs/* json-enums/* "${CMAKE_BINARY_DIR}/include")
# This is stupid. The STL can use any library it wants for implementing
# std::thread, but there is no way for us to query the necessary compile and
# link options. And that is utterly stupid. But I guess that's just what I get
# for using C++. I was stupid and now I have to deal with this stupidity.
set(THREAD_CXXFLAGS -pthread)
set(THREAD_LIBS pthread)
include_directories(include "${CMAKE_BINARY_DIR}/include" "${dake_dir}/include"
${SDL2_INCLUDE_DIRS} ${SDL2_MIXER_INCLUDE_DIRS}
${LUA_INCLUDE_DIR} ${HIDAPI_INCLUDE_DIRS}
${LIBEPOXY_INCLUDE_DIRS})
link_directories("${dake_dir}")
if (HIDAPI_FOUND)
set(SC_FILES src/steam_controller.cpp)
set(SC_CXXFLAGS -DHAS_HIDAPI)
else (HIDAPI_FOUND)
set(SC_FILES)
set(SC_CXXFLAGS)
endif (HIDAPI_FOUND)
add_executable(g1 src/main.cpp src/ui.cpp src/main_loop.cpp src/graphics.cpp
src/physics.cpp src/environment.cpp src/cockpit.cpp
src/gltf.cpp src/software.cpp src/localize.cpp src/text.cpp
src/menu.cpp src/aurora.cpp src/generic-data.cpp src/json.cpp
src/ship_types.cpp src/ship.cpp src/weapons.cpp
src/particles.cpp src/runge-kutta-4.cpp src/radar.cpp
${SC_FILES} src/sound.cpp
"${CMAKE_BINARY_DIR}/serializer.cpp"
"${CMAKE_BINARY_DIR}/include/json-structs.hpp")
target_link_libraries(g1 dake ${OPENGL_LIBRARIES} ${PNG_LIBRARIES}
${JPEG_LIBRARIES} ${SDL2_LIBRARIES}
${SDL2_MIXER_LIBRARIES} ${LUA_LIBRARIES}
${HIDAPI_LIBRARIES} ${LIBTXC_DXTN}
${LIBEPOXY_LIBRARIES} ${THREAD_LIBS} m)
add_executable(create-sphere tools/create-sphere.cpp)
target_link_libraries(create-sphere dake m)
add_executable(polar-to-cube tools/polar-to-cube.cpp)
target_link_libraries(polar-to-cube dake ${PNG_LIBRARIES} ${JPEG_LIBRARIES}
txc_dxtn m)
set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -g2 -Wall -Wextra -Wshadow ${SC_CXXFLAGS} \
${MARCH} ${MTUNE} -fno-math-errno \
-fomit-frame-pointer -flto ${THREAD_CXXFLAGS}")