-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CMake and MSVS2022 support (#3590)
- Loading branch information
Showing
41 changed files
with
694 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
/config/fxdata/*.fon | ||
.vs/ | ||
build*/ | ||
/out/* | ||
*.cache | ||
.vscode | ||
/libexterns | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
# Do not allow building in root | ||
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR) | ||
message(FATAL_ERROR "Do not build in the root. Create a bin directory and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt") | ||
endif () | ||
|
||
project(keeperfx C CXX) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
# Get the abbreviated commit Id of the head. | ||
find_package(Git REQUIRED) | ||
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --always OUTPUT_VARIABLE COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
set(VER_MAJOR 1) | ||
set(VER_MINOR 2) | ||
set(VER_RELEASE 0) | ||
set(VER_BUILD 0) | ||
set(VER_STRING "${VER_MAJOR}.${VER_MINOR}.${VER_RELEASE}.${VER_BUILD} ${PACKAGE_SUFFIX}") | ||
set(PACKAGE_SUFFIX "") | ||
set(GIT_REVISION "${COMMIT_ID}") | ||
|
||
# CMAKE_BINARY_DIR is defined in CMakePresets.json. | ||
set(KEEPERFX_VER_DEFS_H_IN ${CMAKE_SOURCE_DIR}/ver_defs.h.in) | ||
set(KEEPERFX_VER_DEFS_H_OUT ${CMAKE_BINARY_DIR}/ver_defs.h) | ||
configure_file(${KEEPERFX_VER_DEFS_H_IN} ${KEEPERFX_VER_DEFS_H_OUT}) | ||
|
||
# Add binary dir to the include paths, so ver_defs.h can be found. | ||
include_directories($(${CMAKE_BINARY_DIR})) | ||
|
||
find_package(SDL2 CONFIG REQUIRED) | ||
find_package(SDL2_image CONFIG REQUIRED) | ||
find_package(SDL2_mixer CONFIG REQUIRED) | ||
find_package(SDL2_net CONFIG REQUIRED) | ||
|
||
# Global definitions. | ||
add_compile_definitions(_CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS) | ||
|
||
file(GLOB_RECURSE KEEPERFX_SOURCES_C "src/*.c") | ||
file(GLOB_RECURSE KEEPERFX_SOURCES_CXX "src/*.cpp") | ||
|
||
# Global definitions for all targets. | ||
add_compile_definitions("DEBUG=$<IF:$<CONFIG:Debug>,1,0>") | ||
add_compile_definitions("SPNG_STATIC=1") | ||
|
||
# Add two executable targets: keeperfx and keeperfx_hvlog. | ||
add_executable(keeperfx ${KEEPERFX_SOURCES_C} ${KEEPERFX_SOURCES_CXX}) | ||
|
||
target_compile_definitions(keeperfx PUBLIC BFDEBUG_LEVEL=0) | ||
target_sources(keeperfx PRIVATE "res/keeperfx_stdres.rc") | ||
|
||
add_executable(keeperfx_hvlog ${KEEPERFX_SOURCES_C} ${KEEPERFX_SOURCES_CXX}) | ||
|
||
target_compile_definitions(keeperfx_hvlog PUBLIC BFDEBUG_LEVEL=10) | ||
target_sources(keeperfx_hvlog PRIVATE "res/keeperfx_stdres.rc") | ||
|
||
message(STATUS "We are using ${CMAKE_CXX_COMPILER_ID}") | ||
set(WARNFLAGS -Wall -W -Wshadow -Wno-sign-compare -Wno-unused-parameter -Wno-strict-aliasing -Wno-unknown-pragmas) | ||
set(GNU_COMPILER_FLAG -march=x86-64 -fno-omit-frame-pointer -fmessage-length=0) | ||
set(GNU_LINK_FLAG -mwindows -Wl,--enable-auto-import) | ||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit") | ||
target_compile_options(keeperfx PRIVATE ${WARNFLAGS} ${GNU_COMPILER_FLAG}) | ||
target_compile_options(keeperfx_hvlog PRIVATE ${WARNFLAGS} ${GNU_COMPILER_FLAG}) | ||
target_link_options(keeperfx PRIVATE ${GNU_LINK_FLAG} -Wl,-Map,keeperfx.map) | ||
target_link_options(keeperfx_hvlog PRIVATE ${GNU_LINK_FLAG} -Wl,-Map,keeperfx_hvlog.map) | ||
target_link_libraries (keeperfx PUBLIC -static gcc stdc++ winpthread -dynamic) | ||
target_link_libraries (keeperfx_hvlog PUBLIC -static gcc stdc++ winpthread -dynamic) | ||
|
||
# Go into submodules. | ||
add_subdirectory(deps) | ||
add_subdirectory(tools) | ||
|
||
# System libraries. | ||
target_link_libraries(keeperfx PRIVATE imagehlp dbghelp) | ||
target_link_libraries(keeperfx_hvlog PRIVATE imagehlp dbghelp) | ||
|
||
# External libraries. | ||
target_link_libraries(keeperfx | ||
PRIVATE | ||
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main> | ||
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>) | ||
target_link_libraries(keeperfx | ||
PRIVATE $<IF:$<TARGET_EXISTS:SDL2_mixer::SDL2_mixer>,SDL2_mixer::SDL2_mixer,SDL2_mixer::SDL2_mixer-static>) | ||
target_link_libraries(keeperfx | ||
PRIVATE $<IF:$<TARGET_EXISTS:SDL2_net::SDL2_net>,SDL2_net::SDL2_net,SDL2_net::SDL2_net-static>) | ||
target_link_libraries(keeperfx | ||
PRIVATE $<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>) | ||
|
||
target_link_libraries(keeperfx_hvlog | ||
PRIVATE | ||
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main> | ||
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>) | ||
target_link_libraries(keeperfx_hvlog | ||
PRIVATE $<IF:$<TARGET_EXISTS:SDL2_mixer::SDL2_mixer>,SDL2_mixer::SDL2_mixer,SDL2_mixer::SDL2_mixer-static>) | ||
target_link_libraries(keeperfx_hvlog | ||
PRIVATE $<IF:$<TARGET_EXISTS:SDL2_net::SDL2_net>,SDL2_net::SDL2_net,SDL2_net::SDL2_net-static>) | ||
target_link_libraries(keeperfx_hvlog | ||
PRIVATE $<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
{ | ||
"version": 3, | ||
"configurePresets": [ | ||
{ | ||
"name": "base", | ||
"displayName": "Basic Config", | ||
"description": "Basic build using Ninja generator", | ||
"generator": "Ninja", | ||
"hidden": true, | ||
"binaryDir": "${sourceDir}/out/build/${presetName}", | ||
"installDir": "${sourceDir}/out/install/${presetName}", | ||
"cacheVariables": { | ||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", | ||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" | ||
} | ||
}, | ||
|
||
{ | ||
"name": "x86", | ||
"hidden": true, | ||
"architecture": { | ||
"value": "x86", | ||
"strategy": "external" | ||
} | ||
}, | ||
|
||
{ | ||
"name": "Debug", | ||
"displayName": "Config Debug", | ||
"hidden": true, | ||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } | ||
}, | ||
{ | ||
"name": "Release", | ||
"displayName": "Config Release", | ||
"hidden": true, | ||
"cacheVariables": { | ||
"CMAKE_BUILD_TYPE": "RelWithDebInfo", | ||
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": true | ||
} | ||
}, | ||
|
||
{ | ||
"name": "MSVC", | ||
"hidden": true, | ||
"cacheVariables": { | ||
"CMAKE_C_COMPILER": "cl.exe", | ||
"CMAKE_CXX_COMPILER": "cl.exe" | ||
} | ||
}, | ||
{ | ||
"name": "Clang", | ||
"hidden": true, | ||
"cacheVariables": { | ||
"CMAKE_C_COMPILER": "clang-cl.exe", | ||
"CMAKE_CXX_COMPILER": "clang-cl.exe" | ||
}, | ||
"vendor": { | ||
"microsoft.com/VisualStudioSettings/CMake/1.0": { | ||
"intelliSenseMode": "windows-clang-x86" | ||
} | ||
} | ||
}, | ||
|
||
{ | ||
"name": "Debug-Clang", | ||
"displayName": "Debug Clang", | ||
"inherits": [ "base", "x86", "Debug", "Clang" ], | ||
"hidden": true | ||
}, | ||
{ | ||
"name": "Release-Clang", | ||
"displayName": "Release Clang", | ||
"inherits": [ "base", "x86", "Release", "Clang" ], | ||
"hidden": true | ||
}, | ||
{ | ||
"name": "Debug-MSVC", | ||
"displayName": "Debug MSVC", | ||
"inherits": [ "base", "x86", "Debug", "MSVC" ], | ||
"hidden": true | ||
}, | ||
{ | ||
"name": "Release-MSVC", | ||
"displayName": "Release MSVC", | ||
"inherits": [ "base", "x86", "Release", "MSVC" ], | ||
"hidden": true | ||
}, | ||
|
||
{ | ||
"name": "MingGW32-Base", | ||
"hidden": true, | ||
"inherits": "base", | ||
"environment": { | ||
"PATH": "C:/msys64/mingw32/bin;$penv{PATH}" | ||
}, | ||
"cacheVariables": { | ||
"CMAKE_C_COMPILER": "gcc.exe", | ||
"CMAKE_CXX_COMPILER": "g++.exe", | ||
"VCPKG_TARGET_TRIPLET": "x86-mingw-dynamic" | ||
}, | ||
"vendor": { | ||
"microsoft.com/VisualStudioSettings/CMake/1.0": { | ||
"intelliSenseMode": "windows-gcc-x86" | ||
} | ||
} | ||
}, | ||
|
||
{ | ||
"name": "x86-MinGW32-Debug", | ||
"displayName": "x86-MinGW32-Debug", | ||
"inherits": [ "MingGW32-Base", "x86", "Debug" ], | ||
"cacheVariables": { | ||
"CMAKE_EXPORT_COMPILE_COMMANDS": "on" | ||
} | ||
}, | ||
{ | ||
"name": "x86-MinGW32-Release", | ||
"displayName": "x86-MinGW32-Release", | ||
"inherits": [ "MingGW32-Base", "x86", "Release" ], | ||
"cacheVariables": { | ||
"CMAKE_EXPORT_COMPILE_COMMANDS": "on" | ||
} | ||
} | ||
], | ||
"buildPresets": [ | ||
{ | ||
"name": "Base", | ||
"hidden": true, | ||
"jobs": 8, | ||
"configurePreset": "Debug" | ||
}, | ||
|
||
{ | ||
"name": "StandardLog", | ||
"hidden": true, | ||
"inherits": "Base", | ||
"targets": "keeperfx" | ||
}, | ||
{ | ||
"name": "HeavyLog", | ||
"hidden": true, | ||
"inherits": "Base", | ||
"targets": "keeperfx_hvlog", | ||
"verbose": true | ||
}, | ||
|
||
{ | ||
"name": "Debug-Clang-Standard", | ||
"displayName": "Debug Clang Standard", | ||
"inherits": "StandardLog", | ||
"configurePreset": "Debug-Clang" | ||
}, | ||
{ | ||
"name": "Release-Clang-Standard", | ||
"displayName": "Release Clang Standard", | ||
"inherits": "StandardLog", | ||
"configurePreset": "Release-Clang" | ||
}, | ||
{ | ||
"name": "Debug-MSVC-Standard", | ||
"displayName": "Debug MSVC Standard", | ||
"inherits": "StandardLog", | ||
"configurePreset": "Debug-MSVC" | ||
}, | ||
{ | ||
"name": "Release-MSVC-Standard", | ||
"displayName": "Release MSVC Standard", | ||
"inherits": "StandardLog", | ||
"configurePreset": "Release-MSVC" | ||
}, | ||
{ | ||
"name": "Debug-Clang-HeavyLog", | ||
"displayName": "Debug Clang HeavyLog", | ||
"inherits": "HeavyLog", | ||
"configurePreset": "Debug-Clang" | ||
}, | ||
{ | ||
"name": "Release-Clang-HeavyLog", | ||
"displayName": "Release Clang HeavyLog", | ||
"inherits": "HeavyLog", | ||
"configurePreset": "Release-Clang" | ||
}, | ||
{ | ||
"name": "Debug-MSVC-HeavyLog", | ||
"displayName": "Debug MSVC HeavyLog", | ||
"inherits": "HeavyLog", | ||
"configurePreset": "Debug-MSVC" | ||
}, | ||
{ | ||
"name": "Release-MSVC-HeavyLog", | ||
"displayName": "Release MSVC HeavyLog", | ||
"inherits": "HeavyLog", | ||
"configurePreset": "Release-MSVC" | ||
}, | ||
|
||
{ | ||
"name": "Debug-MinGW32-Standard", | ||
"displayName": "Debug MinGW32 Standard", | ||
"inherits": "StandardLog", | ||
"configurePreset": "x86-MinGW32-Debug" | ||
}, | ||
{ | ||
"name": "Release-MinGW32-Standard", | ||
"displayName": "Debug MinGW32 Standard", | ||
"inherits": "StandardLog", | ||
"configurePreset": "x86-MinGW32-Release" | ||
}, | ||
{ | ||
"name": "Debug-MinGW32-HeavyLog", | ||
"displayName": "Debug MinGW32 HeavyLog", | ||
"inherits": "HeavyLog", | ||
"configurePreset": "x86-MinGW32-Debug" | ||
}, | ||
{ | ||
"name": "Release-MinGW32-HeavyLog", | ||
"displayName": "Release MinGW32 HeavyLog", | ||
"inherits": "HeavyLog", | ||
"configurePreset": "x86-MinGW32-Release" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.