CMake: Organize files

1. Platform and toolchain files are now all under `platforms/`, with a
   single `CMake/platforms/${platform}.cmake` per platform.

2. Custom functions/macros are under `functions/`.

3. Finder modules are in `/finders`.
This commit is contained in:
Gleb Mazovetskiy 2021-12-07 10:58:53 +00:00 committed by Anders Jenbo
commit 4848632db2
68 changed files with 82 additions and 85 deletions

View file

@ -26,13 +26,13 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: linux-x86-cmake-${{ github.sha }}
restore-keys: linux-x86-cmake-
key: linux-x86-cmake-v2-${{ github.sha }}
restore-keys: linux-x86-cmake-v2-
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}
run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_TOOLCHAIN_FILE=../CMake/32bit.cmake
run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/linux_i386.toolchain.cmake
- name: Build
working-directory: ${{github.workspace}}

View file

@ -26,13 +26,13 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: windows-x86_64-cmake-${{ github.sha }}
restore-keys: windows-x86_64-cmake-
key: windows-x86_64-cmake-v2-${{ github.sha }}
restore-keys: windows-x86_64-cmake-v2-
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}
run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/mingwcc64.cmake -DDEVILUTIONX_SYSTEM_BZIP2=OFF
run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/mingwcc64.toolchain.cmake -DDEVILUTIONX_SYSTEM_BZIP2=OFF
- name: Build
working-directory: ${{github.workspace}}

View file

@ -26,13 +26,13 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: windows-x86-cmake-${{ github.sha }}
restore-keys: windows-x86-cmake-
key: windows-x86-cmake-v2-${{ github.sha }}
restore-keys: windows-x86-cmake-v2-
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}
run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/mingwcc.cmake -DDEVILUTIONX_SYSTEM_BZIP2=OFF
run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/mingwcc.toolchain.cmake -DDEVILUTIONX_SYSTEM_BZIP2=OFF
- name: Build
working-directory: ${{github.workspace}}

View file

@ -24,15 +24,15 @@ jobs:
uses: actions/cache@v2
with:
path: build
key: ios-cmake-${{ github.sha }}
restore-keys: ios-cmake-
key: ios-cmake-v2-${{ github.sha }}
restore-keys: ios-cmake-v2-
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}
run: cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/ios.toolchain.cmake -DENABLE_BITCODE=0 -DPLATFORM=OS64
run: cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/ios.toolchain.cmake -DENABLE_BITCODE=0 -DPLATFORM=OS64
- name: Build
working-directory: ${{github.workspace}}

View file

@ -11,7 +11,7 @@ else()
set(SDL_STATIC OFF)
endif()
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(SDL2
URL https://github.com/libsdl-org/SDL/archive/5056b29b0f8611b470d8b8bdb313eab628f8bd6e.tar.gz

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
if(DEVILUTIONX_STATIC_SDL_AUDIOLIB)
set(BUILD_SHARED_LIBS OFF)

View file

@ -1,4 +1,4 @@
include(dependency_options)
include(functions/dependency_options)
if(NOT DEFINED DEVILUTIONX_SYSTEM_LIBPNG)
find_package(PNG QUIET)
@ -26,7 +26,7 @@ else()
add_subdirectory(../libpng libpng)
endif()
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
if(USE_SDL1)
FetchContent_Declare(SDL_image

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(asio

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(bzip2

View file

@ -1,11 +1,11 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(find_steam_game
URL https://github.com/cxong/find_steam_game/archive/94e9046bcf94a655bdc051b6e6662fabd18e3f30.zip
URL_HASH MD5=c2742aff3d2a2dd162200fdab1b2b4a4
)
FetchContent_MakeAvailableExcludeFromAll(find_steam_game)
add_library(find_steam_game INTERFACE)
target_include_directories(find_steam_game INTERFACE ${find_steam_game_SOURCE_DIR})
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(find_steam_game
URL https://github.com/cxong/find_steam_game/archive/94e9046bcf94a655bdc051b6e6662fabd18e3f30.zip
URL_HASH MD5=c2742aff3d2a2dd162200fdab1b2b4a4
)
FetchContent_MakeAvailableExcludeFromAll(find_steam_game)
add_library(find_steam_game INTERFACE)
target_include_directories(find_steam_game INTERFACE ${find_steam_game_SOURCE_DIR})

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
if(NOT WIN32 AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
# Enable POSIX extensions such as `readlink` and `ftruncate`.

View file

@ -4,7 +4,7 @@ if(NOT TARGET BZip2::BZip2)
find_package(BZip2 REQUIRED)
endif()
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(libmpq

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
if(NOT DISABLE_LTO)
# Force CMake to raise an error if INTERPROCEDURAL_OPTIMIZATION

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(libsmackerdec

View file

@ -1,5 +1,5 @@
if(NOT DEVILUTIONX_SYSTEM_LIBSODIUM)
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
set(SODIUM_MINIMAL ON)
set(SODIUM_ENABLE_BLOCKING_RANDOM OFF)

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(libzt

View file

@ -1,4 +1,4 @@
include(FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(simpleini

View file

@ -1,6 +1,6 @@
# Options that control whether to use system dependencies or build them from source,
# and whether to link them statically.
include(dependency_options)
include(functions/dependency_options)
if(USE_SDL1)
find_package(SDL REQUIRED)

View file

@ -1,38 +1,3 @@
if(NINTENDO_SWITCH)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/switch")
include(switch_defs)
endif()
if(VITA)
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
include(vita_defs)
endif()
set(TARGET_PLATFORM host CACHE STRING "Target platform")
set_property(CACHE TARGET_PLATFORM PROPERTY STRINGS host retrofw rg350 gkd350h cpigamesh)
if(TARGET_PLATFORM STREQUAL "lepus")
include(lepus_defs)
elseif(TARGET_PLATFORM STREQUAL "retrofw")
include(retrofw_defs)
elseif(TARGET_PLATFORM STREQUAL "rg350")
include(rg350_defs)
elseif(TARGET_PLATFORM STREQUAL "gkd350h")
include(gkd350h_defs)
elseif(TARGET_PLATFORM STREQUAL "cpigamesh")
include(cpigamesh_defs)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|OpenBSD|DragonFly")
if(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
add_definitions(-D_NETBSD_SOURCE)
else()
add_definitions(-D_BSD_SOURCE)
set(UBSAN OFF)
endif()
set(ASAN OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate")
endif()
if(WIN32)
set(ASAN OFF)
set(UBSAN OFF)
@ -44,19 +9,52 @@ if(HAIKU)
set(UBSAN OFF)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|OpenBSD|DragonFly|NetBSD")
if(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
add_definitions(-D_NETBSD_SOURCE)
else()
add_definitions(-D_BSD_SOURCE)
set(UBSAN OFF)
endif()
set(ASAN OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate")
endif()
set(TARGET_PLATFORM host CACHE STRING "Target platform")
set_property(CACHE TARGET_PLATFORM PROPERTY STRINGS host retrofw rg350 gkd350h cpigamesh)
if(TARGET_PLATFORM STREQUAL "retrofw")
include(platforms/retrofw)
elseif(TARGET_PLATFORM STREQUAL "rg350")
include(platforms/rg350)
elseif(TARGET_PLATFORM STREQUAL "gkd350h")
include(platforms/gkd350h)
elseif(TARGET_PLATFORM STREQUAL "cpigamesh")
include(platforms/cpigamesh)
elseif(TARGET_PLATFORM STREQUAL "lepus")
include(platforms/lepus)
endif()
if(NINTENDO_SWITCH)
include(platforms/switch)
endif()
if(AMIGA)
include(amiga_defs)
include(platforms/amiga)
endif()
if(NINTENDO_3DS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/ctr")
include(n3ds_defs)
include(platforms/n3ds)
endif()
if(VITA)
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
include(platforms/vita)
endif()
if(ANDROID)
include(android_defs)
include(platforms/android)
endif()
if(IOS)
include(ios_defs)
include(platforms/ios)
endif()

View file

@ -1,3 +0,0 @@
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(WARNING [[In-source build detected, please eg. create a new directory and use `cmake ..`]])
endif()

View file

@ -11,7 +11,8 @@ set(USE_SDL1 ON)
set(PREFILL_PLAYER_NAME ON)
#3DS libraries
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/ctr/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/ctr")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/ctr/modules")
find_package(CITRO3D REQUIRED)
#additional compilation definitions

View file

@ -1,3 +1,5 @@
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/switch")
set(ASAN OFF)
set(UBSAN OFF)

View file

@ -1,5 +0,0 @@
# Enables a number of header file definitions required by ASIO
target_compile_definitions(asio INTERFACE _DEFAULT_SOURCE=ON)
# Missing headers and declarations provided by DevilutionX
target_include_directories(asio BEFORE INTERFACE ${CMAKE_CURRENT_LIST_DIR}/asio/include)

View file

@ -22,11 +22,15 @@ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
add_subdirectory(dist)
endif()
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(WARNING [[In-source build detected, please eg. create a new directory and use `cmake ..`]])
endif()
include(CMakeDependentOption)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
include(out_of_tree)
include(genex)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/finders")
include(functions/genex)
DEBUG_OPTION(ASAN "Enable address sanitizer")
DEBUG_OPTION(UBSAN "Enable undefined behaviour sanitizer")
@ -92,7 +96,7 @@ include(VcPkgManifestFeatures)
# Set up the `project` early so that properties such as `TARGET_SUPPORTS_SHARED_LIBS` are defined.
if(NOT VERSION_NUM)
include(CMake/git.cmake)
include(functions/git)
get_git_tag(VERSION_NUM)
if (NOT "${VERSION_NUM}" STREQUAL "")
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_NUM ${VERSION_NUM} )

View file

@ -132,14 +132,14 @@ sudo apt-get install cmake gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 pkg-config-
### 32-bit
```bash
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/mingwcc.cmake -DCMAKE_BUILD_TYPE=Release
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/mingwcc.toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build build -j $(getconf _NPROCESSORS_ONLN)
```
### 64-bit
```bash
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/mingwcc64.cmake -DCMAKE_BUILD_TYPE=Release
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/mingwcc64.toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build build -j $(getconf _NPROCESSORS_ONLN)
```
@ -369,7 +369,7 @@ select Icons -> Information in the top menu.
- `-DCMAKE_BUILD_TYPE=Release` changed build type to release and optimize for distribution.
- `-DNONET=ON` disable network support, this also removes the need for the ASIO and Sodium.
- `-DUSE_SDL1=ON` build for SDL v1 instead of v2, not all features are supported under SDL v1, notably upscaling.
- `-DCMAKE_TOOLCHAIN_FILE=../CMake/32bit.cmake` generate 32bit builds on 64bit platforms (remember to use the `linux32` command if on Linux).
- `-DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/linux_i386.toolchain..cmake` generate 32bit builds on 64bit platforms (remember to use the `linux32` command if on Linux).
### Debug builds
- `-DDEBUG=OFF` disable debug mode of the Diablo engine.