-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
105 lines (91 loc) · 3.42 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
# Copyright (c) 2020 Miku AuahDark
#
# 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_minimum_required(VERSION 3.1)
###############
# Some checks #
###############
# Prevent in-tree build.
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree build!")
endif()
# Check source/header files
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/luawrap/cs2dluafunc.h")
message(FATAL_ERROR "CS2D Lua Wrapper is missing. Clone the submodule correctly!")
endif()
# TODO: Remove
if (APPLE)
message(FATAL_ERROR "Patches welcome for macOS!")
endif()
###########
# Project #
###########
project(cs2djit LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Check bitness
if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT APPLE)
message(FATAL_ERROR "Only support 32-bit target. Maybe add CLFAGS=-m32 or use 32-bit toolchain?")
endif()
find_package(LuaJIT REQUIRED)
message(STATUS "LuaJIT include: ${LUAJIT_INCLUDE_DIR}")
message(STATUS "LuaJIT lib: ${LUAJIT_LIBRARY}")
if (WIN32)
# For Windows, we have cs2djitwrapper.exe and cs2djit.dll
# cs2djit.dll
add_library(cs2djit MODULE
src/cs2djitbase.c
src/cs2djitmem.c
src/cs2djitwin.c
)
set_target_properties(cs2djit PROPERTIES PREFIX "")
target_include_directories(cs2djit PRIVATE ${LUAJIT_INCLUDE_DIR})
target_link_libraries(cs2djit ${LUAJIT_LIBRARY})
install(TARGETS cs2djit DESTINATION bin)
# cs2djitwrapper.exe
add_executable(cs2djitwrapper src/cs2djitwin.c)
target_compile_definitions(cs2djitwrapper PRIVATE CS2DJIT_EXE)
install(TARGETS cs2djitwrapper DESTINATION bin)
if (MINGW)
# Why do I have to bother with libgcc_s_dw2-1.dll?
target_link_options(cs2djit PRIVATE -static-libgcc)
target_link_options(cs2djitwrapper PRIVATE -static-libgcc)
endif()
return()
elseif (APPLE)
# TODO
message(FATAL_ERROR "Patches welcome for macOS!")
else ()
# For Linux, use shared object LD_PRELOAD method
add_library(cs2djit MODULE
src/cs2djitbase.c
src/cs2djitlinux.c
src/cs2djitmem.c
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13.0)
target_link_options(cs2djit PRIVATE -Wl,--no-undefined)
else ()
list(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
endif()
target_include_directories(cs2djit PRIVATE ${LUAJIT_INCLUDE_DIR})
target_link_libraries(cs2djit ${LUAJIT_LIBRARY})
install(TARGETS cs2djit DESTINATION bin)
install(PROGRAMS cs2djit.sh DESTINATION bin)
return()
endif()
message(FATAL_ERROR "Unknown target OS")