From 85293ef4f727820f3f3547d36a63e4f1a7a4bdaf Mon Sep 17 00:00:00 2001 From: Christian Lang Date: Wed, 7 Feb 2024 11:23:05 +0100 Subject: [PATCH] WIP --- .../cmake-exercise/devcontainer.json | 17 +++++++++++ .github/workflows/cmake-exercise.yml | 2 ++ topics/build_systems/CMakeLists.txt | 2 +- .../build_systems/build_systems_exercise.md | 6 ++-- topics/build_systems/code/CMakeLists.txt | 21 -------------- .../code/CMakeLists_exercise.txt | 7 ----- .../code/CMakeLists_solution.txt | 28 +++++++++++++++++++ 7 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 .devcontainer/cmake-exercise/devcontainer.json delete mode 100644 topics/build_systems/code/CMakeLists_exercise.txt create mode 100644 topics/build_systems/code/CMakeLists_solution.txt diff --git a/.devcontainer/cmake-exercise/devcontainer.json b/.devcontainer/cmake-exercise/devcontainer.json new file mode 100644 index 0000000..d1fdfc4 --- /dev/null +++ b/.devcontainer/cmake-exercise/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "CMake exercise", + "image": "danger89/cmake:5.0", + "customizations": { + "vscode": { + "extensions": [ + "llvm-vs-code-extensions.vscode-clangd", + "matepek.vscode-catch2-test-adapter", + "ms-vscode.cmake-tools", + "twxs.cmake" + ], + "settings": { + "cmake.sourceDirectory": "${workspaceFolder}/topics/build_systems/code" + } + } + } +} diff --git a/.github/workflows/cmake-exercise.yml b/.github/workflows/cmake-exercise.yml index 5928331..b41f877 100644 --- a/.github/workflows/cmake-exercise.yml +++ b/.github/workflows/cmake-exercise.yml @@ -13,6 +13,8 @@ jobs: - name: configure and build working-directory: topics/build_systems/code run: | + rm CMakeLists.txt + mv CMakeLists_solution.txt CMakeLists.txt mkdir build cmake -S . -B build cmake --build build diff --git a/topics/build_systems/CMakeLists.txt b/topics/build_systems/CMakeLists.txt index 47d42c9..48df7ee 100644 --- a/topics/build_systems/CMakeLists.txt +++ b/topics/build_systems/CMakeLists.txt @@ -7,7 +7,7 @@ js_exercise(build_systems_exercise build_systems_exercise.md) js_script(bitbucket_pipelines_exercise bitbucket_pipelines_exercise.md) file(GLOB_RECURSE code RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "code/*") -list(FILTER code EXCLUDE REGEX "code/CMakeLists.txt") +list(FILTER code EXCLUDE REGEX "code/CMakeLists_solution.txt") js_add_to_global_archive_file_list(${code}) if (JS_WITH_CODE) diff --git a/topics/build_systems/build_systems_exercise.md b/topics/build_systems/build_systems_exercise.md index 17e7d53..48570d5 100644 --- a/topics/build_systems/build_systems_exercise.md +++ b/topics/build_systems/build_systems_exercise.md @@ -85,10 +85,8 @@ Der typische Workflow, um ein CMake-basiertes Projekt zu kompilieren, sieht folg Aufgabe ------- -* Die Vorlage für die CMake-Konfiguration: `CMakeLists_exercise.txt` im entpackten `code`-Ordner - zu `CMakeLists.txt` umbenennen - und mit CLion dieses CMake-Projekt (`code`-Ordner) öffnen. - Dies sollte automatisch den CMake-Cache erzeugen. +* Mit CLion das vorbereitete CMake-Projekt (`code`-Ordner) öffnen. + Dadurch sollte das `CMakeLists.txt` im entpackten `code`-Ordner automatisch geladen und der CMake-Cache erzeugt werden. * Das `CMakeLists.txt` so vervollständigen, dass die Hauptapplikation gebaut werden kann. Die Dokumentation zu folgenden Befehlen könnte helfen: `set`, `target_include_directories`, `add_executable` diff --git a/topics/build_systems/code/CMakeLists.txt b/topics/build_systems/code/CMakeLists.txt index 9800655..b9b9648 100644 --- a/topics/build_systems/code/CMakeLists.txt +++ b/topics/build_systems/code/CMakeLists.txt @@ -4,25 +4,4 @@ cmake_minimum_required(VERSION 3.5) project(bit_fields) set(BF_TARGET bit-fields) -# search all relevant files -file(GLOB_RECURSE BF_SRC_MAIN "src/main.c*") -file(GLOB_RECURSE BF_SRC_ALL "src/*.c*") -file(GLOB_RECURSE BF_TEST_ALL "test/*.c*") -list(REMOVE_ITEM BF_SRC_ALL ${BF_SRC_MAIN}) - -# internal library target -set(BF_TARGET_LIB ${BF_TARGET}-lib) -add_library(${BF_TARGET_LIB} STATIC ${BF_SRC_ALL}) -target_include_directories(${BF_TARGET_LIB} PUBLIC "libs" "src") - # main app target -set(BF_TARGET_APP ${BF_TARGET}-app) -add_executable(${BF_TARGET_APP} ${BF_SRC_MAIN}) -target_link_libraries(${BF_TARGET_APP} PRIVATE ${BF_TARGET_LIB}) - -# unit test target -set(BF_TARGET_TEST ${BF_TARGET}-test) -enable_testing() -add_executable(${BF_TARGET_TEST} ${BF_TEST_ALL}) -add_test(unittest ${BF_TARGET_TEST}) -target_link_libraries(${BF_TARGET_TEST} PRIVATE ${BF_TARGET_LIB}) diff --git a/topics/build_systems/code/CMakeLists_exercise.txt b/topics/build_systems/code/CMakeLists_exercise.txt deleted file mode 100644 index b9b9648..0000000 --- a/topics/build_systems/code/CMakeLists_exercise.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -# project settings -project(bit_fields) -set(BF_TARGET bit-fields) - -# main app target diff --git a/topics/build_systems/code/CMakeLists_solution.txt b/topics/build_systems/code/CMakeLists_solution.txt new file mode 100644 index 0000000..9800655 --- /dev/null +++ b/topics/build_systems/code/CMakeLists_solution.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.5) + +# project settings +project(bit_fields) +set(BF_TARGET bit-fields) + +# search all relevant files +file(GLOB_RECURSE BF_SRC_MAIN "src/main.c*") +file(GLOB_RECURSE BF_SRC_ALL "src/*.c*") +file(GLOB_RECURSE BF_TEST_ALL "test/*.c*") +list(REMOVE_ITEM BF_SRC_ALL ${BF_SRC_MAIN}) + +# internal library target +set(BF_TARGET_LIB ${BF_TARGET}-lib) +add_library(${BF_TARGET_LIB} STATIC ${BF_SRC_ALL}) +target_include_directories(${BF_TARGET_LIB} PUBLIC "libs" "src") + +# main app target +set(BF_TARGET_APP ${BF_TARGET}-app) +add_executable(${BF_TARGET_APP} ${BF_SRC_MAIN}) +target_link_libraries(${BF_TARGET_APP} PRIVATE ${BF_TARGET_LIB}) + +# unit test target +set(BF_TARGET_TEST ${BF_TARGET}-test) +enable_testing() +add_executable(${BF_TARGET_TEST} ${BF_TEST_ALL}) +add_test(unittest ${BF_TARGET_TEST}) +target_link_libraries(${BF_TARGET_TEST} PRIVATE ${BF_TARGET_LIB})