-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
159 lines (142 loc) · 4.38 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
155
156
157
158
159
cmake_minimum_required(VERSION 3.5)
project(ca C CXX)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
OPTION(OPENMP "Use OpenMP for thread detection")
OPTION(STEAM "Steam support")
IF (OPENMP)
find_package(OpenMP REQUIRED)
add_compile_definitions(WITH_OPENMP=1)
ENDIF()
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build raylib shared library")
add_subdirectory(third_party/raylib)
add_subdirectory(third_party/nativefiledialog-extended)
# there's also a "rolling" tag but that jams up any sha256 effort
SET(LUAJIT_VERSION 2.1.0-beta3)
SET(LUAJIT_SHA256 409f7fe570d3c16558e594421c47bdd130238323c9d6fd6c83dedd2aaeb082a8)
IF (NOT IS_DIRECTORY ${CMAKE_SOURCE_DIR}/LuaJIT/src)
FILE(DOWNLOAD
https://github.com/LuaJIT/LuaJIT/archive/v${LUAJIT_VERSION}.tar.gz
${CMAKE_SOURCE_DIR}/third_party/LuaJIT-${LUAJIT_VERSION}.tar.gz
STATUS luajit_fetch
EXPECTED_HASH SHA256=${LUAJIT_SHA256}
)
LIST(GET luajit_fetch 0 luajit_fetch_status)
IF (NOT ${luajit_fetch_status} EQUAL 0)
message(FATAL_ERROR "LuaJIT fetch did not shake out := ${luajit_fetch}")
ENDIF()
FILE(ARCHIVE_EXTRACT
INPUT ${CMAKE_SOURCE_DIR}/third_party/LuaJIT-${LUAJIT_VERSION}.tar.gz
DESTINATION ${CMAKE_SOURCE_DIR}/third_party/.luajit
)
FILE(RENAME
${CMAKE_SOURCE_DIR}/third_party/.luajit/LuaJIT-${LUAJIT_VERSION}
${CMAKE_SOURCE_DIR}/LuaJIT
)
FILE(REMOVE_RECURSE ${CMAKE_SOURCE_DIR}/third_party/.luajit)
ENDIF()
IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/LuaJIT/src/lua.h)
message(FATAL_ERROR "The LuaJIT unpack did not shake out, lua.h is missing")
ENDIF()
add_custom_command(
# in my tarball, it always generates .so but we'll need to double check what happens on (WIN32)
OUTPUT ${CMAKE_SOURCE_DIR}/LuaJIT/src/libluajit.so
# that nonsense is because it does actually build the .so
# but barfs linking luajit binary due to dwarf symbols
COMMAND make --ignore-errors
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/LuaJIT
VERBATIM
)
link_directories(LuaJIT/src)
IF (STEAM)
link_directories(third_party/redistributable_bin/win64/)
SET(steam_libs steam_api64)
add_compile_definitions(WITH_STEAM=1)
ENDIF()
add_compile_definitions(CLIP_ENABLE_IMAGE=1)
SET(ca_src
src/brush.c
src/paint.c
src/filedialog.c
src/colors.c
src/tiling.c
src/msg.c
src/minimap.c
src/api.c
src/font.c
src/rect_int.c
src/rendering.c
src/pyramid.c
src/widgets.c
src/sim.c
src/utils.c
src/img.c
src/hist.c
src/ui.c
src/w_about.c
src/w_main.c
src/w_levels.c
src/w_text.c
src/w_tutorial.c
src/w_dialog.c
src/clip_api.cpp
src/steam.cpp
# Stuff for copy-paste
third_party/clip/image.cpp
third_party/clip/clip.cpp
)
IF (WIN32)
SET(ca_src ${ca_src}
third_party/clip/clip_win.cpp
third_party/clip/clip_win_wic.cpp
third_party/clip/clip_win_bmp.cpp
)
ELSEIF (APPLE)
SET(ca_src ${ca_src}
third_party/clip/clip_osx.mm
)
ELSEIF (UNIX)
ADD_COMPILE_DEFINITIONS(HAVE_XCB_XLIB_H=1)
SET(clip_libs xcb pthread)
SET(ca_src ${ca_src}
third_party/clip/clip_x11.cpp
)
ENDIF()
add_library(calib STATIC ${ca_src})
target_include_directories(calib PRIVATE
src
third_party
third_party/clip
third_party/nativefiledialog-extended/src/include
LuaJIT/src
)
# shlwapi is only for win32
IF(WIN32)
SET(shlwapi_lib shlwapi)
# mingw32-make cooks lua51.dll for some reason :-(
SET(luajit_lib lua51)
ELSE ()
SET(luajit_lib luajit)
ENDIF()
IF (OPENMP)
SET(openmp_lib OpenMP::OpenMP_C OpenMP::OpenMP_CXX)
ENDIF ()
target_link_libraries(calib raylib ${shlwapi_lib} nfd ${openmp_lib} ${luajit_lib} ${clip_libs} ${steam_libs})
add_executable(ca src/main.c)
target_link_libraries(ca calib)
IF (UNIX AND NOT APPLE)
# Need this command so luajit can access the C API from ffi
SET_PROPERTY(TARGET ca PROPERTY ENABLE_EXPORTS ON)
ENDIF()
# In Windows I create 2 executables: one without the console window (ca.exe)
# and one with the console window (ca_console.exe).
# The idea is that one would use ca_console.exe on windows to develop lua
# scripts to see logs and error messages, while the default version is used as
# main entrypoint of steam.
IF (WIN32)
add_executable(ca_console src/main.c)
target_link_libraries(ca_console calib)
target_compile_definitions(ca_console PRIVATE CA_SHOW_CONSOLE=1)
ENDIF()