Skip to content

Commit 8fc1436

Browse files
authored
CMake presets. (vcmi#744)
* CI: use single build action * CMake: use imported targets * CI: do not build boost for linux * CMake: add FORCE_BUNDLED_MINIZIP option * linux: use external minizip and fuzzylite * CMake: add presets * .gitignore: ignore cmake build dirs * github: use cmake presets
1 parent a8265c7 commit 8fc1436

27 files changed

+1424
-699
lines changed

.github/workflows/github.yml

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
pull_request:
99
env:
1010
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11-
BUILD_TYPE: Release
11+
BUILD_TYPE: RelWithDebInfo
1212

1313
jobs:
1414
build:
@@ -17,22 +17,18 @@ jobs:
1717
include:
1818
- platform: linux
1919
os: ubuntu-20.04
20-
cc: clang-10
21-
cxx: clang++-10
2220
test: 0
23-
cmake_args: -G Ninja
21+
preset: linux-clang-release
2422
- platform: linux
2523
os: ubuntu-20.04
26-
cc: gcc-9
27-
cxx: g++-9
2824
test: 0
29-
cmake_args: -G Ninja
25+
preset: linux-gcc-release
3026
- platform: mac
3127
os: macos-latest
3228
test: 0
3329
pack: 1
3430
extension: dmg
35-
cmake_args: -G Ninja
31+
preset: macos-ninja-release
3632
- platform: mxe
3733
os: ubuntu-20.04
3834
mxe: i686-w64-mingw32.shared
@@ -46,15 +42,14 @@ jobs:
4642
test: 0
4743
pack: 1
4844
extension: exe
49-
cmake_args: -G "Visual Studio 17 2022" -A x64 '-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake'
50-
45+
preset: windows-msvc-release
5146
runs-on: ${{ matrix.os }}
5247
defaults:
5348
run:
5449
shell: bash
5550

5651
steps:
57-
- uses: actions/checkout@v2
52+
- uses: actions/checkout@v3
5853
with:
5954
submodules: recursive
6055

@@ -63,7 +58,7 @@ jobs:
6358
env:
6459
MXE_TARGET: ${{ matrix.mxe }}
6560
VCMI_BUILD_PLATFORM: x64
66-
61+
6762
- name: Git branch name
6863
id: git-branch-name
6964
uses: EthanSK/git-branch-name-action@v1
@@ -77,73 +72,80 @@ jobs:
7772
PULL_REQUEST: ${{ github.event.pull_request.number }}
7873

7974
- name: Configure CMake
75+
if: "${{ matrix.preset == '' }}"
8076
run: |
81-
mkdir '${{github.workspace}}/build'
82-
cd '${{github.workspace}}/build'
83-
cmake ${{matrix.cmake_args}} .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
77+
mkdir -p '${{github.workspace}}/out/build/${{matrix.preset}}'
78+
cd '${{github.workspace}}/out/build/${{matrix.preset}}'
79+
cmake \
80+
../.. -GNinja \
81+
${{matrix.cmake_args}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
8482
-DENABLE_TEST=${{matrix.test}} \
8583
-DPACKAGE_NAME_SUFFIX:STRING="$VCMI_PACKAGE_NAME_SUFFIX" \
8684
-DPACKAGE_FILE_NAME:STRING="$VCMI_PACKAGE_FILE_NAME"
8785
env:
8886
CC: ${{ matrix.cc }}
8987
CXX: ${{ matrix.cxx }}
9088

89+
- name: CMake Preset
90+
if: "${{ matrix.preset != '' }}"
91+
run: |
92+
cmake --preset ${{ matrix.preset }}
93+
9194
- name: Build
92-
if: ${{ matrix.platform != 'msvc' }}
95+
if: "${{ matrix.preset == '' }}"
9396
run: |
94-
cd '${{github.workspace}}/build'
95-
ninja
96-
97-
- name: Build MSVC
98-
if: ${{ matrix.platform == 'msvc' }}
97+
cmake --build '${{github.workspace}}/out/build/${{matrix.preset}}'
98+
99+
- name: Build Preset
100+
if: "${{ matrix.preset != '' }}"
99101
run: |
100-
cd '${{github.workspace}}/build'
101-
cmake --build . --config ${{env.BUILD_TYPE}}
102+
cmake --build --preset ${{matrix.preset}}
102103
103104
- name: Test
104-
if: ${{ matrix.test == 1 }}
105+
if: ${{ matrix.test == 1 && matrix.preset != ''}}
105106
run: |
106-
cd '${{github.workspace}}/build'
107-
ctest -C Release -V
108-
107+
ctest --preset ${{matrix.preset}}
108+
109109
- name: Pack
110110
id: cpack
111111
if: ${{ matrix.pack == 1 }}
112112
run: |
113-
cd '${{github.workspace}}/build'
113+
cd '${{github.workspace}}/out/build/${{matrix.preset}}'
114114
CPACK_PATH=`which -a cpack | grep -m1 -v -i chocolatey`
115-
"$CPACK_PATH" -C Release ${{ matrix.cpack_args }}
116-
115+
"$CPACK_PATH" -C ${{env.BUILD_TYPE}} ${{ matrix.cpack_args }}
116+
rm -rf _CPack_Packages
117+
117118
- name: Additional logs
118119
if: ${{ failure() && steps.cpack.outcome == 'failure' && matrix.platform == 'mxe' }}
119120
run: |
120-
cat '${{github.workspace}}/build/_CPack_Packages/win32/NSIS/project.nsi'
121-
cat '${{github.workspace}}/build/_CPack_Packages/win32/NSIS/NSISOutput.log'
122-
121+
cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/project.nsi'
122+
cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/NSISOutput.log'
123+
123124
- name: Artifacts
124125
if: ${{ matrix.pack == 1 }}
125-
uses: actions/upload-artifact@v2
126+
uses: actions/upload-artifact@v3
126127
with:
127128
name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
128-
path: ${{github.workspace}}/build/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
129-
129+
path: |
130+
${{github.workspace}}/**/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
131+
130132
- name: Upload build
131133
if: ${{ matrix.pack == 1 && github.ref == 'refs/heads/develop' && matrix.platform != 'msvc' }}
132134
run: |
133-
cd '${{github.workspace}}/build'
135+
cd '${{github.workspace}}/out/build/${{matrix.preset}}'
134136
source '${{github.workspace}}/CI/upload_package.sh'
135137
env:
136138
DEPLOY_RSA: ${{ secrets.DEPLOY_RSA }}
137139
PACKAGE_EXTENSION: ${{ matrix.extension }}
138-
140+
139141
- uses: act10ns/slack@v1
140142
with:
141143
status: ${{ job.status }}
142144
channel: '#notifications'
143145
env:
144146
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
145147
if: always()
146-
148+
147149
- name: Trigger Android
148150
uses: peter-evans/repository-dispatch@v1
149151
if: ${{ github.ref == 'refs/heads/develop' && matrix.platform == 'mxe' }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
/launcher/vcmilauncher
44
/launcher/vcmilauncher_automoc.cpp
55

6+
build/
7+
.cache/*
8+
out/
69
*.dll
710
*.exe
811
*.depend

AI/CMakeLists.txt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,28 @@ else()
88
option(FORCE_BUNDLED_FL "Force to use FuzzyLite included into VCMI's source tree" OFF)
99
endif()
1010

11+
if(TBB_FOUND AND MSVC)
12+
install_vcpkg_imported_tgt(TBB::tbb)
13+
endif()
14+
15+
1116
if(NOT FORCE_BUNDLED_FL)
12-
find_package(FuzzyLite)
17+
find_package(fuzzylite)
1318
else()
14-
set(FL_FOUND FALSE)
19+
set(fuzzylite_FOUND FALSE)
1520
endif()
1621

17-
if(TBB_FOUND AND MSVC)
18-
get_target_property(TBB_LIB_LOCATION TBB::tbb LOCATION)
19-
get_filename_component(TBB_LIB_FOLDER ${TBB_LIB_LOCATION} PATH)
20-
get_filename_component(TBB_DLL ${TBB_LIB_FOLDER}/../bin/tbb.dll ABSOLUTE)
21-
message("${TBB_DLL}")
22-
install(FILES ${TBB_DLL} DESTINATION ${BIN_DIR})
22+
if(TARGET fuzzylite::fuzzylite AND MSVC)
23+
install_vcpkg_imported_tgt(fuzzylite::fuzzylite)
2324
endif()
2425

25-
if(FL_FOUND)
26-
if(MSVC)
27-
get_filename_component(FL_LIB_FOLDER ${FL_LIBRARIES} PATH)
28-
get_filename_component(FL_DLL ${FL_LIB_FOLDER}/../bin/fuzzylite.dll ABSOLUTE)
29-
message("${FL_DLL}")
30-
install(FILES ${FL_DLL} DESTINATION ${BIN_DIR})
31-
endif()
32-
else()
26+
if(NOT fuzzylite_FOUND)
3327
set(FL_BUILD_BINARY OFF CACHE BOOL "")
3428
set(FL_BUILD_SHARED OFF CACHE BOOL "")
3529
set(FL_BUILD_TESTS OFF CACHE BOOL "")
3630
add_subdirectory(FuzzyLite/fuzzylite EXCLUDE_FROM_ALL)
31+
add_library(fuzzylite::fuzzylite ALIAS fl-static)
32+
target_include_directories(fl-static PUBLIC ${CMAKE_HOME_DIRECTORY}/AI/FuzzyLite/fuzzylite)
3733
endif()
3834

3935
#######################################

AI/Nullkiller/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,9 @@ endif()
128128

129129
add_library(Nullkiller SHARED ${Nullkiller_SRCS} ${Nullkiller_HEADERS})
130130

131-
if(FL_FOUND)
132-
target_include_directories(Nullkiller PUBLIC ${FL_INCLUDE_DIRS})
133-
else()
134-
target_include_directories(Nullkiller PUBLIC ${CMAKE_HOME_DIRECTORY}/AI/FuzzyLite/fuzzylite)
135-
endif()
136131
target_include_directories(Nullkiller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
137132

138-
if(FL_FOUND)
139-
target_link_libraries(Nullkiller PRIVATE ${FL_LIBRARIES} vcmi)
140-
else()
141-
target_link_libraries(Nullkiller PRIVATE fl-static vcmi)
142-
endif()
133+
target_link_libraries(Nullkiller PRIVATE vcmi fuzzylite::fuzzylite)
143134

144135
target_link_libraries(Nullkiller PRIVATE TBB::tbb)
145136

AI/VCAI/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,9 @@ endif()
109109

110110
add_library(VCAI SHARED ${VCAI_SRCS} ${VCAI_HEADERS})
111111

112-
if(FL_FOUND)
113-
target_include_directories(VCAI PUBLIC ${FL_INCLUDE_DIRS})
114-
else()
115-
target_include_directories(VCAI PUBLIC ${CMAKE_HOME_DIRECTORY}/AI/FuzzyLite/fuzzylite)
116-
endif()
117112
target_include_directories(VCAI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
118113

119-
if(FL_FOUND)
120-
target_link_libraries(VCAI PRIVATE ${FL_LIBRARIES} vcmi)
121-
else()
122-
target_link_libraries(VCAI PRIVATE fl-static vcmi)
123-
endif()
114+
target_link_libraries(VCAI PRIVATE vcmi fuzzylite::fuzzylite)
124115

125116
vcmi_set_output_dir(VCAI "AI")
126117

CI/linux/before_install.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22

33
sudo apt-get update
44

5-
# Boost
6-
wget -nv https://boostorg.jfrog.io/artifactory/main/release/1.66.0/source/boost_1_66_0.tar.gz
7-
tar xfz boost_1_66_0.tar.gz
8-
cd boost_1_66_0
9-
./bootstrap.sh --with-libraries=program_options,filesystem,system,thread,locale,date_time
10-
./b2
11-
sudo ./b2 install
12-
135
# Dependencies
6+
sudo apt-get install libboost-all-dev
147
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
158
sudo apt-get install qtbase5-dev
16-
sudo apt-get install ninja-build zlib1g-dev libavformat-dev libswscale-dev libtbb-dev libluajit-5.1-dev
9+
sudo apt-get install ninja-build zlib1g-dev libavformat-dev libswscale-dev libtbb-dev libluajit-5.1-dev
10+
# Optional dependencies
11+
sudo apt-get install libminizip-dev libfuzzylite-dev

0 commit comments

Comments
 (0)