From dfaee89d5694a2fe15d9dd0c15b0a0ac7ed50d6b Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 21 Oct 2023 11:43:01 +0200 Subject: [PATCH] refactor: restructure project to build a library for each book chapter --- CMakeLists.txt | 16 ++++++++++------ chapters/CMakeLists.txt | 1 + chapters/chapter_02/CMakeLists.txt | 4 ++++ .../chapter_02/include}/constexp.h | 0 .../chapter_02/include}/ifswitch.h | 0 .../chapter_02/include}/initlist.h | 0 {include => chapters/chapter_02/include}/null.h | 0 {src => chapters/chapter_02/src}/constexp.cpp | 0 {src => chapters/chapter_02/src}/ifswitch.cpp | 0 {src => chapters/chapter_02/src}/initlist.cpp | 0 {src => chapters/chapter_02/src}/null.cpp | 0 11 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 chapters/CMakeLists.txt create mode 100644 chapters/chapter_02/CMakeLists.txt rename {include => chapters/chapter_02/include}/constexp.h (100%) rename {include => chapters/chapter_02/include}/ifswitch.h (100%) rename {include => chapters/chapter_02/include}/initlist.h (100%) rename {include => chapters/chapter_02/include}/null.h (100%) rename {src => chapters/chapter_02/src}/constexp.cpp (100%) rename {src => chapters/chapter_02/src}/ifswitch.cpp (100%) rename {src => chapters/chapter_02/src}/initlist.cpp (100%) rename {src => chapters/chapter_02/src}/null.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5f9770..31c0d68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project( - hello + book_exercises VERSION 0.1.0 LANGUAGES CXX) @@ -19,13 +19,17 @@ include(FetchContent) configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" "${PROJECT_BINARY_DIR}/include/version.h") -add_executable(hello src/main.cpp src/null.cpp src/constexp.cpp - src/ifswitch.cpp src/initlist.cpp) +add_subdirectory(chapters) -target_compile_features(hello PUBLIC cxx_std_20) +add_executable(book_exercises src/main.cpp) -target_include_directories(hello PRIVATE "${PROJECT_BINARY_DIR}/include" - "${PROJECT_SOURCE_DIR}/include") +target_compile_features(book_exercises PUBLIC cxx_std_20) + +target_include_directories( + book_exercises PRIVATE "${PROJECT_BINARY_DIR}/include" + "${PROJECT_SOURCE_DIR}/include") + +target_link_libraries(book_exercises PRIVATE chapter_02) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) add_subdirectory(tests) diff --git a/chapters/CMakeLists.txt b/chapters/CMakeLists.txt new file mode 100644 index 0000000..5c13caf --- /dev/null +++ b/chapters/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(chapter_02) diff --git a/chapters/chapter_02/CMakeLists.txt b/chapters/chapter_02/CMakeLists.txt new file mode 100644 index 0000000..51d62aa --- /dev/null +++ b/chapters/chapter_02/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp + src/ifswitch.cpp) + +target_include_directories(chapter_02 PUBLIC include) diff --git a/include/constexp.h b/chapters/chapter_02/include/constexp.h similarity index 100% rename from include/constexp.h rename to chapters/chapter_02/include/constexp.h diff --git a/include/ifswitch.h b/chapters/chapter_02/include/ifswitch.h similarity index 100% rename from include/ifswitch.h rename to chapters/chapter_02/include/ifswitch.h diff --git a/include/initlist.h b/chapters/chapter_02/include/initlist.h similarity index 100% rename from include/initlist.h rename to chapters/chapter_02/include/initlist.h diff --git a/include/null.h b/chapters/chapter_02/include/null.h similarity index 100% rename from include/null.h rename to chapters/chapter_02/include/null.h diff --git a/src/constexp.cpp b/chapters/chapter_02/src/constexp.cpp similarity index 100% rename from src/constexp.cpp rename to chapters/chapter_02/src/constexp.cpp diff --git a/src/ifswitch.cpp b/chapters/chapter_02/src/ifswitch.cpp similarity index 100% rename from src/ifswitch.cpp rename to chapters/chapter_02/src/ifswitch.cpp diff --git a/src/initlist.cpp b/chapters/chapter_02/src/initlist.cpp similarity index 100% rename from src/initlist.cpp rename to chapters/chapter_02/src/initlist.cpp diff --git a/src/null.cpp b/chapters/chapter_02/src/null.cpp similarity index 100% rename from src/null.cpp rename to chapters/chapter_02/src/null.cpp