-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
219 lines (177 loc) · 6.84 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Copyright (c) 2019-2020 Reed A. Cartwright <[email protected]>
#
# 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.12)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0074 NEW)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds not allowed. Please run CMake from the './build' directory. You may need to remove CMakeCache.txt.")
endif()
################################################################################
# Project Configuration
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
set(CMAKE_BUILD_TYPE_INIT "RelWithDebInfo")
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
################################################################################
# Init Project
project(mcberepair VERSION 0.2
DESCRIPTION "Minecraft Bedrock Utilities"
HOMEPAGE_URL "https://github.com/reedacartwright/mcberepair/"
LANGUAGES CXX
)
## Enable Developer CMake Flags
include("conf/devopt.cmake")
# Gitmeta data and semantic versioning
include("conf/gitmeta.cmake")
include("conf/semver.cmake")
add_semver_file(${CMAKE_PROJECT_NAME} METADATA_GIT)
option(LEVELDB_BUILD_TESTS OFF)
option(LEVELDB_INSTALL OFF)
add_subdirectory(leveldb-mcpe)
# GOOGLE disables RTTI for leveldb so we will do the same
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Disable RTTI.
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
else()
# Disable RTTI.
string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()
## Turn on unit and executable testing
enable_testing()
#include("conf/doctest.cmake")
set(pretest_all ALL)
if(DEVOPT_EXCLUDE_PRETEST_FROM_ALL)
set(pretest_all)
endif()
add_custom_target(pretest ${pretest_all})
add_dependencies(pretest configure)
add_subdirectory(tests)
################################################################################
# Installation Information
string(TOLOWER ${CMAKE_PROJECT_NAME} basename_for_install)
set(CMAKE_DATA_DIR "share/${basename_for_install}" CACHE STRING
"Install location for data (relative to prefix).")
set(CMAKE_DOC_DIR "doc/${basename_for_install}" CACHE STRING
"Install location for documentation (relative to prefix).")
set(CMAKE_MAN_DIR "man" CACHE STRING
"Install location for man pages (relative to prefix).")
mark_as_advanced(CMAKE_DATA_DIR CMAKE_DOC_DIR CMAKE_MAN_DIR)
install(FILES README.md LICENSE DESTINATION ${CMAKE_DOC_DIR})
################################################################################
# Building binary
add_executable(mcberepair
main.cpp
listkeys.cpp
rmkeys.cpp
dumpkey.cpp
writekey.cpp
repair.cpp
copyall.cpp
db.hpp
mcbekey.hpp
perenc.hpp
slurp.hpp
)
target_link_libraries(mcberepair leveldb)
target_include_directories(mcberepair PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
# Enable Warnings
target_compile_options(mcberepair PUBLIC
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra>
$<$<CXX_COMPILER_ID:MSVC>:/W4>)
add_dependencies(mcberepair configure-version.h)
install(TARGETS mcberepair RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
# copy any dlls installed by vcpkg on windows
if(VCPKG_APPLOCAL_DEPS AND VCPKG_TARGET_TRIPLET MATCHES "windows|uwp")
install(DIRECTORY $<TARGET_FILE_DIR:mcberepair>/
TYPE BIN FILES_MATCHING PATTERN "*.dll")
endif()
# developer tools
clang_format_target(mcberepair)
clang_tidy_target(mcberepair)
target_link_libraries(mcberepair devopt_coverage)
# Setup a target that will build version.h.in -> version.h
set(configure_script_code "
include(\"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.version\")\n
")
add_configured_file(version.h
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/version.h.in"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/version.h"
EXTRA_DEPS "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.version"
VARIABLES ${CMAKE_PROJECT_NAME}_SEMVER_VERSION
${CMAKE_PROJECT_NAME}_SEMVER_INTEGER
${CMAKE_PROJECT_NAME}_SEMVER_MAJOR
${CMAKE_PROJECT_NAME}_SEMVER_MINOR
${CMAKE_PROJECT_NAME}_SEMVER_PATCH
)
add_dependencies(configure-version.h configure-${CMAKE_PROJECT_NAME}.version)
unset(configure_script_code)
# Add Project File for sublime
configure_file(${CMAKE_PROJECT_NAME}.sublime-project.in ${CMAKE_PROJECT_NAME}.sublime-project @ONLY)
################################################################################
# Packaging
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VENDOR "Reed A. Cartwright, PhD")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Commandline tools for Minecraft: Bedrock Edition.")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(mcberepair_package_version
${mcberepair_VERSION_MAJOR}
${mcberepair_VERSION_MINOR}
${mcberepair_VERSION_PATCH}
)
if("${mcberepair_VERSION_PATCH}" STREQUAL "")
list(APPEND mcberepair_package_version "0-prerelease")
endif()
list(JOIN mcberepair_package_version "." CPACK_PACKAGE_VERSION)
set(CPACK_PACKAGE_CHECKSUM "SHA256")
IF(WIN32 AND NOT UNIX)
set(CPACK_GENERATOR "ZIP")
set(CPACK_SOURCE_GENERATOR "ZIP")
ELSE()
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
ENDIF()
set(CPACK_SOURCE_IGNORE_FILES
# Files specific to version control.
"/\\\\.git/"
"/\\\\.gitattributes$"
"/\\\\.gitmodules$"
"/\\\\.github/"
"/\\\\.gitignore$"
"/\\\\.hooks-config$"
# Build directory contents
"/\\\\build/.+"
# Development
"/\\\\.circleci/"
"/\\\\.clang-format$"
"/\\\\.clang-tidy$"
"/\\\\.codecov.yml$"
# Temporary files.
"\\\\.swp$"
"\\\\.#"
"/#"
"~$"
)
include(CPack)