Skip to content

Commit c93a53d

Browse files
build: Generate CMake settings file containing dependency installation directories to replace specification through CLI options. (#31)
Co-authored-by: davidlion <[email protected]>
1 parent 2ed729f commit c93a53d

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ option(BUILD_TESTING "If ON, unit tests will be built." ON)
1616
# Import CMake helper functions
1717
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
1818

19+
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
20+
# Include dependency settings if the project isn't being included as a subproject.
21+
# NOTE: We mark the file optional because if the user happens to have the dependencies
22+
# installed, this file is not necessary.
23+
include(build/deps/settings.cmake OPTIONAL)
24+
endif()
25+
1926
if(BUILD_TESTING)
2027
find_package(Catch2 3.8.0 REQUIRED)
2128
if(Catch2_FOUND)

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Initialize and update submodules:
2727
git submodule update --init --recursive
2828
```
2929

30+
If you want to open the project in an IDE, run the following command to install any necessary
31+
dependencies from source:
32+
```shell
33+
task deps:install-all
34+
```
35+
3036
## Building
3137
To build all targets:
3238
```shell

taskfile.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ vars:
1010
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
1111
G_CPP_SRC_DIR: "{{.ROOT_DIR}}/src"
1212
G_DEPS_DIR: "{{.G_BUILD_DIR}}/deps"
13+
14+
# This should be kept in-sync with its usage in CMakeLists.txt
15+
G_DEPS_CMAKE_SETTINGS_FILE: "{{.G_DEPS_DIR}}/settings.cmake"
16+
1317
G_TEST_BIN_DIR: "{{.G_BUILD_DIR}}/testbin"
1418
G_TEST_TARGET_SUFFIXES:
1519
- "all"

taskfiles/build.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ version: "3"
22

33
vars:
44
G_CMAKE_CACHE: "{{.G_BUILD_DIR}}/CMakeCache.txt"
5-
G_CMAKE_CONF_ARGS:
6-
- "-DCatch2_ROOT={{.G_DEPS_DIR}}/Catch2/Catch2-install"
75
G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json"
86

97
tasks:
@@ -64,6 +62,4 @@ tasks:
6462
- task: ":utils:cmake-generate"
6563
vars:
6664
BUILD_DIR: "{{.G_BUILD_DIR}}"
67-
EXTRA_ARGS:
68-
ref: ".G_CMAKE_CONF_ARGS"
6965
SOURCE_DIR: "{{.ROOT_DIR}}"

taskfiles/deps.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
version: "3"
22

3+
vars:
4+
G_CATCH2_LIB_NAME: "Catch2"
5+
G_CATCH2_WORK_DIR: "{{.G_DEPS_DIR}}/{{.G_CATCH2_LIB_NAME}}"
6+
37
tasks:
48
install-all:
59
desc: "Install all dependencies required by ystdlib-cpp."
610
deps:
711
- "install-Catch2"
12+
cmds:
13+
- "rm -f '{{.G_DEPS_CMAKE_SETTINGS_FILE}}'"
14+
- >-
15+
echo "set(
16+
{{.G_CATCH2_LIB_NAME}}_ROOT \"{{.G_CATCH2_WORK_DIR}}/{{.G_CATCH2_LIB_NAME}}-install\"
17+
)" >> "{{.G_DEPS_CMAKE_SETTINGS_FILE}}"
818
919
install-Catch2:
1020
internal: true
11-
vars:
12-
NAME: "Catch2"
13-
WORK_DIR: "{{.G_DEPS_DIR}}/{{.NAME}}"
1421
run: "once"
1522
cmds:
1623
- task: ":utils:cmake-install-remote-tar"
1724
vars:
18-
NAME: "{{.NAME}}"
19-
WORK_DIR: "{{.WORK_DIR}}"
25+
NAME: "{{.G_CATCH2_LIB_NAME}}"
26+
WORK_DIR: "{{.G_CATCH2_WORK_DIR}}"
2027
FILE_SHA256: "1ab2de20460d4641553addfdfe6acd4109d871d5531f8f519a52ea4926303087"
2128
URL: "https://github.com/catchorg/Catch2/archive/refs/tags/v3.8.0.tar.gz"

0 commit comments

Comments
 (0)