This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
141 lines (116 loc) · 4.89 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
CMAKE_MINIMUM_REQUIRED (VERSION 3.0)
PROJECT (lua_co_await)
SET (STDLIB stdc++)
ENABLE_TESTING ()
MESSAGE (STATUS "Current platform: ${CMAKE_GENERATOR_PLATFORM}")
SET (COND_VLD WIN32 AND (${CMAKE_GENERATOR_PLATFORM} EQUAL "x64" OR ${CMAKE_GENERATOR_PLATFORM} EQUAL "Win32"))
IF (COND_VLD)
OPTION (ENABLE_VLD "Enable Visual Leak Detector" OFF)
IF (ENABLE_VLD)
ADD_COMPILE_DEFINITIONS (USE_VLD)
# cmake does not allow parentheses in environment variable, so $ENV{ProgramFiles(x86)} is prohibited
FILE (TO_CMAKE_PATH "$ENV{ProgramFiles} (x86)" PROGRAM_FILES)
INCLUDE_DIRECTORIES ("${PROGRAM_FILES}/Visual Leak Detector/include")
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
LINK_DIRECTORIES ("${PROGRAM_FILES}/Visual Leak Detector/lib/Win64")
ELSE (CMAKE_SIZEOF_VOID_P EQUAL 8)
LINK_DIRECTORIES ("${PROGRAM_FILES}/Visual Leak Detector/lib/Win32")
ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 8)
ENDIF (ENABLE_VLD)
ENDIF (COND_VLD)
SET (USE_LUA_VERSION "Builtin" CACHE STRING "Lua version")
SET_PROPERTY (CACHE USE_LUA_VERSION PROPERTY STRINGS "Builtin" "LuaJIT" "5.1" "5.2" "5.3" "5.4")
SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
SET (CMAKE_CXX_STANDARD 20)
STRING (REPLACE "/" "\\" LOCAL_SOURCE_DIR "${PROJECT_SOURCE_DIR}")
INCLUDE_DIRECTORIES ("${PROJECT_BINARY_DIR}")
FILE (GLOB_RECURSE LUA_CO_AWAIT_SRC
"${PROJECT_SOURCE_DIR}/src/*.h"
"${PROJECT_SOURCE_DIR}/src/*.cpp"
"${PROJECT_SOURCE_DIR}/src/*.inl"
)
FOREACH (FILE ${LUA_CO_AWAIT_SRC})
GET_FILENAME_COMPONENT (PARENT_DIR "${FILE}" PATH)
# skip src or include and changes /'s to \\'s
STRING (REGEX REPLACE "(\\./)?(src|include)/?" "" GROUP "${PARENT_DIR}")
STRING (REPLACE "/" "\\" GROUP "${GROUP}")
STRING (REPLACE "${LOCAL_SOURCE_DIR}" "" GROUP "${GROUP}")
SOURCE_GROUP ("${GROUP}" FILES "${FILE}")
ENDFOREACH (FILE ${LUA_CO_AWAIT_SRC})
IF (${USE_LUA_VERSION} STREQUAL "Builtin")
SET (ENABLE_LUA_BUILTIN ON)
ELSE (${USE_LUA_VERSION} STREQUAL "Builtin")
SET (ENABLE_LUA_BUILTIN OFF)
ENDIF (${USE_LUA_VERSION} STREQUAL "Builtin")
IF (ENABLE_LUA_BUILTIN)
MESSAGE (STATUS "Use built-in lua version.")
# BUILD LUA
FILE (GLOB_RECURSE LUA_EXE_SRC
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lauxlib.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lua.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/luaconf.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lualib.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lua.c"
)
FILE (GLOB_RECURSE LUA_LIB_SRC
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/*.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/*.hpp"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/*.c"
)
LIST (REMOVE_ITEM LUA_LIB_SRC "${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/luac.c")
LIST (REMOVE_ITEM LUA_LIB_SRC "${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lua.c")
ADD_LIBRARY (lua54 SHARED ${LUA_LIB_SRC})
IF (MSVC)
TARGET_COMPILE_DEFINITIONS (lua54 PRIVATE LUA_BUILD_AS_DLL)
ELSE (MSVC)
TARGET_COMPILE_DEFINITIONS (lua54 PRIVATE LUA_USE_LINUX)
TARGET_LINK_LIBRARIES (lua54 m dl)
ENDIF (MSVC)
ADD_EXECUTABLE (lua ${LUA_EXE_SRC})
TARGET_LINK_LIBRARIES (lua lua54)
SET (LUA_CORE_LIB lua54)
FILE (GLOB_RECURSE LUA_CORE_SRC
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lauxlib.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lua.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lua.hpp"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/luaconf.h"
"${PROJECT_SOURCE_DIR}/ref/iris/src/lua/src/lualib.h"
)
FOREACH (FILE ${LUA_CORE_SRC})
GET_FILENAME_COMPONENT(PARENT_DIR "${FILE}" PATH)
# skip src or include and changes /'s to \\'s
STRING (REGEX REPLACE "(\\./)?(src|include)/?" "" GROUP "${PARENT_DIR}")
STRING (REPLACE "/" "\\" GROUP "${GROUP}")
STRING (REPLACE "${LOCAL_SOURCE_DIR}" "" GROUP "${GROUP}")
SOURCE_GROUP ("${GROUP}" FILES "${FILE}")
ENDFOREACH (FILE ${LUA_CORE_SRC})
ELSE (ENABLE_LUA_BUILTIN)
IF (${USE_LUA_VERSION} STREQUAL "LuaJIT")
FIND_PACKAGE (LuaJIT)
ELSE (${USE_LUA_VERSION} STREQUAL "LuaJIT")
FIND_PACKAGE (Lua ${USE_LUA_VERSION} REQUIRED)
ENDIF (${USE_LUA_VERSION} STREQUAL "LuaJIT")
IF (LUA_FOUND OR LUAJIT_FOUND)
MESSAGE (STATUS "Find lua version " ${USE_LUA_VERSION})
FILE (GLOB_RECURSE LUA_CORE_SRC
"${LUA_INCLUDE_DIR}/*.h"
"${LUA_INCLUDE_DIR}/*.hpp"
)
SET (LUA_CORE_LIB ${LUA_LIBRARIES})
ELSE (LUA_FOUND OR LUAJIT_FOUND)
MESSAGE (FATAL_ERROR "Unable to find lua with version " ${USE_LUA_VERSION})
ENDIF (LUA_FOUND OR LUAJIT_FOUND)
ENDIF (ENABLE_LUA_BUILTIN)
IF (MSVC)
SET (EXTRA_DEFINES LUA_BUILD_AS_DLL)
ELSE (MSVC)
SET (EXTRA_DEFINES)
ENDIF (MSVC)
SET (TARGET_NAME lua_co_await)
ADD_LIBRARY (${TARGET_NAME} SHARED ${LUA_CO_AWAIT_SRC} ${LUA_CORE_SRC})
TARGET_INCLUDE_DIRECTORIES (${TARGET_NAME} PRIVATE ${LUA_INCLUDE_DIR})
IF (NOT ENABLE_LUA_BUILTIN)
TARGET_COMPILE_DEFINITIONS (${TARGET_NAME} PRIVATE USE_LUA_LIBRARY ${EXTRA_DEFINES})
ENDIF (NOT ENABLE_LUA_BUILTIN)
TARGET_LINK_LIBRARIES (${TARGET_NAME} ${LUA_CORE_LIB})
SET_TARGET_PROPERTIES (${TARGET_NAME} PROPERTIES PREFIX "")