Skip to content

Commit

Permalink
Add option to download dependencies with CMake
Browse files Browse the repository at this point in the history
This is another step in reaching feature parity between CMake and meson.
When using the `fetch-deps` preset, or when setting
`CMAKE_PROJECT_TOP_LEVEL_INCLUDES` to `subprojects/provider.cmake`, the
dependencies will be downloaded and built from source.
  • Loading branch information
lunacd committed Jul 10, 2024
1 parent a2ac60e commit 6c9d02f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ insert_final_newline = true
[meson.build]
indent_size = 2

[CMakeLists.txt]
[{CMakeLists.txt,*.cmake}]
indent_size = 2

[*.{toml,yml,json}]
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ jobs:
strategy:
matrix:
cfg:
- {
id: ubuntu-gcc,
platform: ubuntu,
preset: default,
}
- { id: ubuntu-gcc, platform: ubuntu, preset: default }
- { id: ubuntu-gcc-fetch, platform: ubuntu, preset: fetch-deps }

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
subprojects/*
!subprojects/*.wrap
!subprojects/*.cmake
.pixi/
.cache/
16 changes: 15 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{
"name": "default",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"BUILD_TESTING": true
Expand All @@ -13,6 +12,21 @@
"CC": "gcc",
"CXX": "g++"
}
},
{
"name": "fetch-deps",
"inherits": "default",
"cacheVariables": {
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "subprojects/provider.cmake"
}
},
{
"name": "shared",
"inherits": "fetch-deps",
"cacheVariables": {
"BUILD_SHARED_LIBS": true,
"CMAKE_POSITION_INDEPENDENT_CODE": true
}
}
]
}
41 changes: 41 additions & 0 deletions subprojects/provider.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.24)

include(FetchContent)
FetchContent_Declare(
GTest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
URL_HASH SHA256=8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7
)
FetchContent_Declare(
tl-expected
URL https://github.com/TartanLlama/expected/archive/v1.1.0.tar.gz
URL_HASH SHA256=1db357f46dd2b24447156aaf970c4c40a793ef12a8a9c2ad9e096d9801368df6
)
FetchContent_Declare(
jsoncpp
URL https://github.com/open-source-parsers/jsoncpp/archive/1.9.5.tar.gz
URL_HASH SHA256=f409856e5920c18d0c2fb85276e24ee607d2a09b5e7d5f0a371368903c275da2
)
FetchContent_Declare(
fmt
URL https://github.com/fmtlib/fmt/archive/10.1.1.tar.gz
URL_HASH SHA256=78b8c0a72b1c35e4443a7e308df52498252d1cefc2b08c9a97bc9ee6cfe61f8b
)
FetchContent_Declare(
CLI11
URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.1.2.tar.gz
URL_HASH SHA256=26291377e892ba0e5b4972cdfd4a2ab3bf53af8dac1f4ea8fe0d1376b625c8cb
)

macro(provide_dependency method dep_name)
if ("${dep_name}" MATCHES "^(GTest|tl-expected|jsoncpp|fmt|CLI11)$")
FetchContent_MakeAvailable(${dep_name})
set(${dep_name}_FOUND TRUE)
endif()
endmacro()

cmake_language(
SET_DEPENDENCY_PROVIDER provide_dependency
SUPPORTED_METHODS
FIND_PACKAGE
)

0 comments on commit 6c9d02f

Please sign in to comment.