|
1 | | -set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (by default Debug)") |
2 | | - |
3 | | -cmake_minimum_required(VERSION 2.8) |
4 | | - |
5 | | -project(int2ssl) |
6 | | - |
7 | | -set(SOURCES main.cpp |
8 | | -Hacks/CMap.h |
9 | | -Namespace.h |
10 | | -Namespace.cpp |
11 | | -Node.h |
12 | | -Node.cpp |
13 | | -ObjectAttributes.h |
14 | | -Opcode.h |
15 | | -ProcTable.h |
16 | | -ProcTable.cpp |
17 | | -Utility.h |
18 | | -Utility.cpp |
19 | | -FalloutScript.h |
20 | | -FalloutScript.cpp |
21 | | -FalloutScriptDecompile.cpp |
22 | | -FalloutScriptDefObject.cpp |
23 | | -FalloutScriptDump.cpp |
24 | | -FalloutScriptStore.cpp |
25 | | -OpcodeAttributes.cpp |
26 | | -Opcode.cpp |
27 | | -StartupCode.h |
28 | | -StartupCode.cpp |
29 | | -XGetopt.h |
30 | | -XGetopt.cpp |
| 1 | +cmake_minimum_required(VERSION 3.18.4 FATAL_ERROR) |
| 2 | + |
| 3 | +set(CMAKE_CXX_STANDARD 11) |
| 4 | +set(CMAKE_CXX_STANDARD_REQUIRED YES) |
| 5 | +set(CMAKE_SKIP_INSTALL_RULES TRUE) |
| 6 | + |
| 7 | +# |
| 8 | +# NOTE: If you're building int2ssl using add_subdirectory() command, |
| 9 | +# see bottom of the file for the list of exported variables |
| 10 | +# |
| 11 | + |
| 12 | +set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (default: Debug)") |
| 13 | +option(INT2SSL_BINARY "If disabled, building int2ssl executable will be skipped" ON) |
| 14 | +option(INT2SSL_BINARY_STATIC "If enabled, int2ssl will be built as static executable (UNIX only)" OFF) |
| 15 | +option(INT2SSL_STRICT "If enabled, compiler warnings are promoted to errors (UNIX only)" OFF) |
| 16 | + |
| 17 | +project(int2ssl |
| 18 | + DESCRIPTION "Script decompiler for Fallout 1 / Fallout 2 / sfall scripts" |
| 19 | + HOMEPAGE_URL "https://github.com/sfall-team/int2ssl/" |
| 20 | + LANGUAGES CXX) |
| 21 | + |
| 22 | +# |
| 23 | +# Misc |
| 24 | +# |
| 25 | + |
| 26 | +# Base targets names |
| 27 | +set(INT2SSL_BIN ${PROJECT_NAME}) |
| 28 | +set(INT2SSL_LIB ${INT2SSL_BIN}-lib) |
| 29 | + |
| 30 | +include(CheckCXXCompilerFlag) |
| 31 | +include(CheckLinkerFlag) |
| 32 | + |
| 33 | +# int2ssl_build_option( target type guard required flag var ) |
| 34 | +# target ...... name of the the target |
| 35 | +# type ........ string describing which CMake functions should be used to test and add <flag> to <target> |
| 36 | +# "compile" ... test: check_cxx_compiler_flag() add: target_compile_options() |
| 37 | +# "link" ...... test: check_linker_flag() add: target_link_options() |
| 38 | +# guard .....,. name of variable used to test if given flag should be tested |
| 39 | +# if variable resolves to FALSE, function does nothing |
| 40 | +# required .... name of variable used to test if given flag is mandatory |
| 41 | +# if flag is not found and variable resolves to TRUE, configuration stops with error message |
| 42 | +# flag, var ... see CMake documentation |
| 43 | +# https://cmake.org/cmake/help/v3.18/module/CheckCXXCompilerFlag.html |
| 44 | +# https://cmake.org/cmake/help/v3.18/module/CheckLinkerFlag.html |
| 45 | +function(int2ssl_build_option target type guard required flag var) |
| 46 | + if(NOT ${guard}) |
| 47 | + return() |
| 48 | + endif() |
| 49 | + |
| 50 | + if("${type}" STREQUAL "compile") |
| 51 | + check_cxx_compiler_flag(${flag} ${var}) |
| 52 | + elseif("${type}" STREQUAL "link") |
| 53 | + check_linker_flag(CXX ${flag} ${var}) |
| 54 | + else() |
| 55 | + message(AUTHOR_WARNING "Unknown flag type: ${type}") |
| 56 | + message(AUTHOR_WARNING "Valid flag types: compile, link") |
| 57 | + return() |
| 58 | + endif() |
| 59 | + |
| 60 | + if(${var}) |
| 61 | + if("${type}" STREQUAL "compile") |
| 62 | + target_compile_options(${target} PRIVATE ${flag}) |
| 63 | + elseif("${type}" STREQUAL "link") |
| 64 | + target_link_options(${target} PRIVATE ${flag}) |
| 65 | + endif() |
| 66 | + else() |
| 67 | + if(${required}) |
| 68 | + message(FATAL_ERROR "Required ${type} flag ${flag} not found") |
| 69 | + return() |
| 70 | + endif() |
| 71 | + endif() |
| 72 | +endfunction() |
| 73 | + |
| 74 | +# Add out-of-source build directory to git ignore list |
| 75 | +if(NOT "${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}" AND NOT EXISTS "${PROJECT_BINARY_DIR}/.gitignore") |
| 76 | + file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/.gitignore" CONTENT "*") |
| 77 | +endif() |
| 78 | + |
| 79 | +# |
| 80 | +# Library |
| 81 | +# |
| 82 | + |
| 83 | +add_library(${INT2SSL_LIB} STATIC) |
| 84 | +target_sources(${INT2SSL_LIB} |
| 85 | + PUBLIC |
| 86 | + FalloutScript.h |
| 87 | + |
| 88 | + PRIVATE |
| 89 | + ${CMAKE_CURRENT_LIST_FILE} |
| 90 | + |
| 91 | + FalloutScript.cpp |
| 92 | + FalloutScriptDecompile.cpp |
| 93 | + FalloutScriptDefObject.cpp |
| 94 | + FalloutScriptDump.cpp |
| 95 | + FalloutScriptStore.cpp |
| 96 | + Namespace.cpp |
| 97 | + Namespace.h |
| 98 | + Node.cpp |
| 99 | + Node.h |
| 100 | + ObjectAttributes.h |
| 101 | + Opcode.cpp |
| 102 | + Opcode.h |
| 103 | + OpcodeAttributes.cpp |
| 104 | + ProcTable.cpp |
| 105 | + ProcTable.h |
| 106 | + StartupCode.cpp |
| 107 | + StartupCode.h |
| 108 | + Utility.cpp |
| 109 | + Utility.h |
| 110 | + |
| 111 | + Hacks/CMap.h |
31 | 112 | ) |
32 | 113 |
|
33 | | -add_definitions (-Wall) |
| 114 | +# |
| 115 | +# Library test |
| 116 | +# Used to check if external applications are able to safely link library target |
| 117 | +# |
| 118 | + |
| 119 | +if(NOT "${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") |
| 120 | + file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/${INT2SSL_LIB}-test.cpp" CONTENT "#include <FalloutScript.h>\nint main(){ CFalloutScript script; return 0; }\n") |
| 121 | + add_executable(${INT2SSL_LIB}-test EXCLUDE_FROM_ALL "${PROJECT_BINARY_DIR}/${INT2SSL_LIB}-test.cpp") |
| 122 | + target_include_directories(${INT2SSL_LIB}-test PRIVATE "${CMAKE_CURRENT_LIST_DIR}") |
| 123 | + target_link_libraries(${INT2SSL_LIB}-test PRIVATE ${INT2SSL_LIB}) |
| 124 | +endif() |
| 125 | + |
| 126 | +# |
| 127 | +# Executable (optional) |
| 128 | +# |
| 129 | + |
| 130 | +if(INT2SSL_BINARY) |
| 131 | + add_executable(${INT2SSL_BIN} "") |
| 132 | + target_sources(int2ssl |
| 133 | + PRIVATE |
| 134 | + XGetopt.h |
| 135 | + XGetopt.cpp |
| 136 | + |
| 137 | + main.cpp |
| 138 | + main.h |
| 139 | + ) |
| 140 | + target_link_libraries(${INT2SSL_BIN} PRIVATE ${INT2SSL_LIB}) |
| 141 | +endif() |
| 142 | + |
| 143 | +# |
| 144 | +# Compilation flags |
| 145 | +# Flags for all targets |
| 146 | +# |
| 147 | +# https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html |
| 148 | +# https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/fwkeyyhe(v=vs.100) |
| 149 | +# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically/ (latest VS) |
| 150 | +# |
| 151 | + |
| 152 | +get_property(INT2SSL_TARGETS DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" PROPERTY BUILDSYSTEM_TARGETS) |
| 153 | +foreach(target IN ITEMS ${INT2SSL_TARGETS}) |
| 154 | + int2ssl_build_option(${target} "compile" UNIX FALSE -Os INT2SSL_COMPILE_FLAG_Os) |
| 155 | +# int2ssl_build_option(${target} "compile" UNIX FALSE -s INT2SSL_COMPILE_FLAG_s) |
| 156 | + |
| 157 | + int2ssl_build_option(${target} "compile" MSVC FALSE /options:strict INT2SSL_COMPILE_FLAG_options_strict) |
| 158 | + int2ssl_build_option(${target} "compile" MSVC FALSE /Os INT2SSL_COMPILE_FLAG_Os) |
| 159 | + int2ssl_build_option(${target} "compile" MSVC FALSE /permissive- INT2SSL_COMPILE_FLAG_permissive_) |
| 160 | + |
| 161 | + int2ssl_build_option(${target} "compile" UNIX FALSE -Wall INT2SSL_COMPILE_FLAG_Wall) |
| 162 | + int2ssl_build_option(${target} "compile" UNIX FALSE -Wextra INT2SSL_COMPILE_FLAG_Wextra) |
| 163 | + int2ssl_build_option(${target} "compile" UNIX FALSE -Wpedantic INT2SSL_COMPILE_FLAG_Wpedantic) |
| 164 | +# int2ssl_build_option(${target} "compile" UNIX FALSE -Wold-style-cast INT2SSL_COMPILE_FLAG_Wold_style_cast) |
| 165 | +# int2ssl_build_option(${target} "compile" UNIX FALSE -Wuseless-cast INT2SSL_COMPILE_FLAG_Wuseless-cast) |
| 166 | + if(UNIX) |
| 167 | + int2ssl_build_option(${target} "compile" INT2SSL_STRICT TRUE -Werror INT2SSL_COMPILE_FLAG_Werror) |
| 168 | + endif() |
| 169 | + |
| 170 | +# int2ssl_build_option(${target} "compile" MSVC FALSE /W4 INT2SSL_COMPILE_FLAG_W4) |
| 171 | +endforeach() |
34 | 172 |
|
35 | | -set(CMAKE_CXX_FLAGS_RELEASE "-Os -s") |
| 173 | +# |
| 174 | +# Compilation flags |
| 175 | +# Flags for executable only |
| 176 | +# |
36 | 177 |
|
37 | | -message("CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}") |
38 | | -message("CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}") |
| 178 | +if(UNIX) |
| 179 | + # According to internet, only first flag is required to build static binary in most cases; other two mmight be needed only in edge cases |
| 180 | + int2ssl_build_option(${INT2SSL_BIN} "link" INT2SSL_BINARY_STATIC TRUE -static INT2SSL_LINK_FLAG_static) |
| 181 | + int2ssl_build_option(${INT2SSL_BIN} "link" INT2SSL_BINARY_STATIC FALSE -static-libgcc INT2SSL_LINK_FLAG_static_libgcc) |
| 182 | + int2ssl_build_option(${INT2SSL_BIN} "link" INT2SSL_BINARY_STATIC FALSE -static-libstdc++ INT2SSL_LINK_FLAG_static_libstdcxx) |
| 183 | +endif() |
39 | 184 |
|
40 | | -add_executable(int2ssl ${SOURCES}) |
| 185 | +# |
| 186 | +# Export variables |
| 187 | +# Set possibly useful variables when project i |
| 188 | +# |
| 189 | +get_directory_property(INT2SSL_HAS_PARENT PARENT_DIRECTORY) |
| 190 | +if(INT2SSL_HAS_PARENT) # if(NOT PROJECT_IS_TOP_LEVEL) -- added in CMake v3.21 |
| 191 | + set(INT2SSL_LIBRARY_TARGET ${INT2SSL_LIB} PARENT_SCOPE) |
| 192 | + set(INT2SSL_ALL_TARGETS ${INT2SSL_TARGETS} PARENT_SCOPE) |
| 193 | +endif() |
0 commit comments