forked from lunarmodules/busted
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
170 lines (150 loc) · 7.65 KB
/
CMakeLists.txt
File metadata and controls
170 lines (150 loc) · 7.65 KB
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
160
161
162
163
164
165
166
167
168
169
170
# MIT License
#
# Copyright (c) 2012-2020 Olivine Labs, LLC.
# Copyright (c) 2026 The OneLuaPro project authors.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ------------------------------------------------------------------------------
# CMake for busted
# ------------------------------------------------------------------------------
# Setup with Visual Studio 17 2022 generator for x64
# ------------------------------------------------------------------------------
# Visual Studio is a mutlti-configuration generator
# https://stackoverflow.com/questions/24460486/
#
# Basic instructions for out-of-source build
# ------------------------------------------
# mkdir build && cd build
# cmake .. -G "Visual Studio 17 2022" -A x64
# cmake --build . --config Release
# cmake --install . --config Release
#
# Available architectures (-A ...) are: Win32, x64, ARM, ARM64
#
# Note: As busted does not comprise any files to be compiled and linked (just
# files to be installed properly) the mention of architecture or config is
# somewhat arbitrary.
# ------------------------------------------------------------------------------
# General definitions
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
# ------------------------------------------------------------------------------
# find liblua installation and version info
if(NOT LUA_HINTS)
if(WIN32)
set(LUA_HINTS "c:/Apps")
endif()
endif()
find_package(liblua REQUIRED HINTS ${LUA_HINTS})
if(liblua_FOUND)
message(STATUS "liblua version : ${liblua_VERSION}")
message(STATUS "liblua install prefix : ${LIBLUA_INSTALLDIR}")
message(STATUS "liblua include dir : ${LIBLUA_INCLUDEDIR}")
message(STATUS "liblua lib dir : ${LIBLUA_LIBDIR}")
else()
message(FATAL_ERROR "Unable to find liblua version ${liblua_VERSION}.")
endif()
# Note: liblua_VERSION is set by find_package() directly. LIBLUA_INSTALLDIR,
# LIBLUA_INCLUDEDIR and LIBLUA_LIBDIR are set by libluaConfigVersion.cmake in
# <prefix>/share/cmake/liblua.
# ------------------------------------------------------------------------------
# Installation prefix directory - automatically set from find_package()
# Needs to be defined before project definition statement - for whatever reason
if(NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${LIBLUA_INSTALLDIR})
endif()
# ------------------------------------------------------------------------------
# Project defintion
project(busted CXX)
# ------------------------------------------------------------------------------
# Other settings
set(CMAKE_VERBOSE_MAKEFILE ON)
# ------------------------------------------------------------------------------
# Setup GNU-alike installatin directories
include (GNUInstallDirs)
set(INSTALL_BINDIR
${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables")
set(INSTALL_DOCDIR
${CMAKE_INSTALL_DOCDIR} CACHE PATH "Installation directory for documentation")
set(INSTALL_DATAROOTDIR
${CMAKE_INSTALL_DATAROOTDIR} CACHE PATH "Installation directory for data")
# Lua-specific installation dirs
set(INSTALL_TOP_LDIR
${INSTALL_DATAROOTDIR}/lua/${liblua_VERSION_MAJOR}.${liblua_VERSION_MINOR})
# ------------------------------------------------------------------------------
# busted Launcher (.exe instead of .bat)
if(WIN32)
# User option (Default: OFF for Windows 7 compatibility)
option(USE_PATHCCH "Use modern PathCch Library (requires Windows 8+)" OFF)
# Define absolute paths for the input Lua script and the generated C++ header
set(BUSTED_INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/bin/busted")
set(BUSTED_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/generated/busted_source.h")
# Define the generation rule: Converts the Lua script into a C-style hex array.
# This avoids encoding issues and delimiter conflicts in C++ string literals.
# Ensure the header is rebuilt if the Lua script or the converter script changes
# VERBATIM ensures correct argument escaping for the Windows Shell/MSBuild
add_custom_command(
OUTPUT "${BUSTED_HEADER_FILE}"
COMMAND ${CMAKE_COMMAND}
-DINPUT_FILE=${BUSTED_INPUT_FILE}
-DOUTPUT_FILE=${BUSTED_HEADER_FILE}
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/convert_lua_to_hex.cmake"
DEPENDS "${BUSTED_INPUT_FILE}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/convert_lua_to_hex.cmake"
COMMENT "Converting bin/busted to hex header..."
VERBATIM
)
# Define the executable target
add_executable(BustedLauncher
logo/lua-logo-olp-dist.rc # Windows resource file (icon/metadata)
bin/busted.cpp # Main C++ launcher logic
"${BUSTED_HEADER_FILE}" # Listing the header here makes it visible to MSBuild's dependency scanner
)
# Mark the file as generated so CMake doesn't look for it during the initial configuration
set_source_files_properties("${BUSTED_HEADER_FILE}" PROPERTIES GENERATED TRUE)
# Crucial for MSVC/MSBuild: Tells the compiler that busted.cpp MUST be recompiled
# whenever busted_source.h is updated. This bridges the gap between the custom command and the C++ build.
set_source_files_properties(busted.cpp PROPERTIES OBJECT_DEPENDS "${BUSTED_HEADER_FILE}")
# Include directories: ensure the compiler finds both Lua headers and our generated hex header
target_include_directories(BustedLauncher PRIVATE ${LIBLUA_INCLUDEDIR})
target_include_directories(BustedLauncher PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Linker: Set path for the Lua library
target_link_directories(BustedLauncher PRIVATE ${LIBLUA_LIBDIR})
# Enable DELAYLOAD
target_link_options(BustedLauncher PRIVATE "LINKER:/DELAYLOAD:lua.dll" "LINKER:/DEPENDENTLOADFLAG:0x0")
target_link_libraries(BustedLauncher PRIVATE delayimp.lib)
# Link dependencies: liblua for the interpreter and pathcch for Windows path handling
if(USE_PATHCCH)
# pathcch requires Windows 8 and upwards
target_compile_definitions(BustedLauncher PRIVATE USE_PATHCCH _CRT_SECURE_NO_WARNINGS)
target_link_libraries(BustedLauncher PRIVATE liblua.lib pathcch.lib)
else()
# Shlwapi is for Windows 7 upwards compatible
target_compile_definitions(BustedLauncher PRIVATE _CRT_SECURE_NO_WARNINGS)
target_link_libraries(BustedLauncher PRIVATE liblua.lib shlwapi.lib)
endif()
# Rename the final binary to 'busted.exe' (default would be BustedLauncher.exe)
set_target_properties(BustedLauncher PROPERTIES OUTPUT_NAME "busted")
# Define the installation rule for the resulting binary
install(TARGETS BustedLauncher RUNTIME DESTINATION ${INSTALL_BINDIR})
endif()
# ------------------------------------------------------------------------------
# Install busted files and docs
install(FILES busted.lua DESTINATION ${INSTALL_TOP_LDIR})
install(DIRECTORY busted DESTINATION ${INSTALL_TOP_LDIR})
install(DIRECTORY doc/ DESTINATION ${INSTALL_DOCDIR})