Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
langchr86 committed Feb 7, 2024
1 parent 1942250 commit 85293ef
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 33 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/cmake-exercise/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
2 changes: 2 additions & 0 deletions .github/workflows/cmake-exercise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion topics/build_systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions topics/build_systems/build_systems_exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
21 changes: 0 additions & 21 deletions topics/build_systems/code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
7 changes: 0 additions & 7 deletions topics/build_systems/code/CMakeLists_exercise.txt

This file was deleted.

28 changes: 28 additions & 0 deletions topics/build_systems/code/CMakeLists_solution.txt
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 85293ef

Please sign in to comment.