-
Notifications
You must be signed in to change notification settings - Fork 21
/
CMakeLists.txt
170 lines (146 loc) · 6.34 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
160
161
162
163
164
165
166
167
168
169
170
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
cmake_policy(SET CMP0048 NEW) # VERSION variables
cmake_policy(SET CMP0091 NEW) # CMAKE_MSVC_RUNTIME_LIBRARY
# Get the version number from Decompiler/Version.hpp
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/Decompiler/Version.hpp" CHAMPOLLION_VERSION_FILE)
string(REGEX MATCH "define CHAMPOLLION_VERSION_MAJOR ([0-9]*)" _ ${CHAMPOLLION_VERSION_FILE})
math(EXPR CHAMPOLLION_VERSION_MAJOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "define CHAMPOLLION_VERSION_MINOR ([0-9]*)" _ ${CHAMPOLLION_VERSION_FILE})
math(EXPR CHAMPOLLION_VERSION_MINOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "define CHAMPOLLION_VERSION_PATCH ([0-9]*)" _ ${CHAMPOLLION_VERSION_FILE})
math(EXPR CHAMPOLLION_VERSION_PATCH "${CMAKE_MATCH_1}")
#Get the Champollion version as a semver number literal, not as a string
set(CHAMPOLLION_VERSION ${CHAMPOLLION_VERSION_MAJOR}.${CHAMPOLLION_VERSION_MINOR}.${CHAMPOLLION_VERSION_PATCH})
message(STATUS "Champollion version: ${CHAMPOLLION_VERSION}")
# package information
set(PACKAGE_NAME "Champollion")
set(PACKAGE_VERSION "${CHAMPOLLION_VERSION}")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/Orvid/champollion/issues")
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
project(${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES CXX)
include(GNUInstallDirs)
option(CHAMPOLLION_STATIC_LIBRARY "Build Champollion as a static library" OFF)
option(CHAMPOLLION_USE_STATIC_RUNTIME "Compile Champollion with static runtime" OFF)
if (NOT CHAMPOLLION_STATIC_LIBRARY)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
# Automatically create source_group directives for the sources passed in.
function(auto_source_group rootName rootDir)
file(TO_CMAKE_PATH "${rootDir}" rootDir)
string(LENGTH "${rootDir}" rootDirLength)
set(sourceGroups)
foreach (fil ${ARGN})
file(TO_CMAKE_PATH "${fil}" filePath)
string(FIND "${filePath}" "/" rIdx REVERSE)
if (rIdx EQUAL -1)
message(FATAL_ERROR "Unable to locate the final forward slash in '${filePath}'!")
endif()
string(SUBSTRING "${filePath}" 0 ${rIdx} filePath)
string(LENGTH "${filePath}" filePathLength)
string(FIND "${filePath}" "${rootDir}" rIdx)
if (NOT rIdx EQUAL 0)
continue()
#message(FATAL_ERROR "Source '${fil}' is outside of the root directory, '${rootDir}', that was passed to auto_source_group!")
endif()
math(EXPR filePathLength "${filePathLength} - ${rootDirLength}")
string(SUBSTRING "${filePath}" ${rootDirLength} ${filePathLength} fileGroup)
string(REPLACE "/" "\\" fileGroup "${fileGroup}")
set(fileGroup "\\${rootName}${fileGroup}")
list(FIND sourceGroups "${fileGroup}" rIdx)
if (rIdx EQUAL -1)
list(APPEND sourceGroups "${fileGroup}")
source_group("${fileGroup}" REGULAR_EXPRESSION "${filePath}/[^/.]+(.(idl|tab|yy))?.(c|cc|cpp|h|hpp|json|ll|php|tcc|y)$")
endif()
endforeach()
endfunction()
if (CHAMPOLLION_USE_STATIC_RUNTIME)
if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY})
else()
set(USE_STATIC_RUNTIME ON)
endif()
endif()
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(CHAMPOLLION_TARGET_NAME ${PROJECT_NAME})
set(CHAMPOLLION_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
set(CHAMPOLLION_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/Champollion")
set(CHAMPOLLION_TARGETS_EXPORT_NAME "${PROJECT_NAME}-targets")
set(CHAMPOLLION_CMAKE_CONFIG_TEMPLATE "cmake/Config.cmake.in")
set(CHAMPOLLION_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(CHAMPOLLION_CMAKE_VERSION_CONFIG_FILE "${CHAMPOLLION_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(CHAMPOLLION_CMAKE_PROJECT_CONFIG_FILE "${CHAMPOLLION_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(CHAMPOLLION_CMAKE_PROJECT_TARGETS_FILE "${CHAMPOLLION_CMAKE_CONFIG_DIR}/${PROJECT_NAME}-targets.cmake")
if(CHAMPOLLION_STATIC_LIBRARY)
file(GLOB DECOMPILER_HEADER_FILES "Decompiler/*.hpp")
file(GLOB PEX_HEADER_FILES "Pex/*.hpp")
file(GLOB NODE_HEADER_FILES "Decompiler/Node/*.hpp")
list(APPEND ALL_HEADERS ${DECOMPILER_HEADER_FILES} ${PEX_HEADER_FILES} ${NODE_HEADER_FILES})
file(GLOB SOURCE_FILES "Pex/*.cpp" "Decompiler/*.cpp" "Decompiler/Node/*.cpp")
add_library("${PROJECT_NAME}" STATIC ${ALL_HEADERS} ${SOURCE_FILES})
target_include_directories(
"${PROJECT_NAME}"
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CHAMPOLLION_INCLUDE_INSTALL_DIR}>
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CHAMPOLLION_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMinorVersion
)
configure_package_config_file(
${CHAMPOLLION_CMAKE_CONFIG_TEMPLATE}
"${CHAMPOLLION_CMAKE_PROJECT_CONFIG_FILE}"
INSTALL_DESTINATION ${CHAMPOLLION_CONFIG_INSTALL_DIR}
)
install(
TARGETS "${CHAMPOLLION_TARGET_NAME}"
EXPORT "${CHAMPOLLION_TARGETS_EXPORT_NAME}"
)
install(
EXPORT "${CHAMPOLLION_TARGETS_EXPORT_NAME}"
NAMESPACE "${CHAMPOLLION_TARGET_NAME}::"
DESTINATION "${CHAMPOLLION_CONFIG_INSTALL_DIR}"
)
install(
FILES ${DECOMPILER_HEADER_FILES}
DESTINATION "${CHAMPOLLION_INCLUDE_INSTALL_DIR}/Decompiler"
)
install(
FILES ${PEX_HEADER_FILES}
DESTINATION "${CHAMPOLLION_INCLUDE_INSTALL_DIR}/Pex"
)
install(
FILES ${NODE_HEADER_FILES}
DESTINATION "${CHAMPOLLION_INCLUDE_INSTALL_DIR}/Decompiler/Node"
)
install(FILES ${CHAMPOLLION_CMAKE_VERSION_CONFIG_FILE} ${CHAMPOLLION_CMAKE_PROJECT_CONFIG_FILE}
DESTINATION ${CHAMPOLLION_CONFIG_INSTALL_DIR})
else()
if (VCPKG_TARGET_TRIPLET MATCHES "static")
if(NOT MSVC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
endif()
find_package(Boost REQUIRED COMPONENTS program_options)
find_package(fmt CONFIG REQUIRED)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${Boost_INCLUDE_DIRS}
)
add_subdirectory(Decompiler)
add_subdirectory(Pex)
add_subdirectory(Champollion)
target_link_libraries(Champollion fmt::fmt)
install(
TARGETS Champollion
)
endif()