Skip to content

Improve Header File Specification Using File Sets #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ include(cmake/CPM.cmake)

# Build the main library
add_library(errors src/error.cpp)
target_include_directories(errors PUBLIC include)
target_sources(
errors PUBLIC
FILE_SET HEADERS
BASE_DIRS include
FILES include/errors/error.hpp
)

# Check if this project is the main project
if(NOT_SUBPROJECT)
Expand All @@ -41,11 +46,11 @@ if(NOT_SUBPROJECT)

# Append the main library properties instead of linking the library.
get_target_property(errors_SOURCES errors SOURCES)
get_target_property(errors_INCLUDES errors INCLUDE_DIRECTORIES)
get_target_property(errors_HEADER_DIRS errors HEADER_DIRS)

# Build tests for the main library
add_executable(errors_test test/error_test.cpp ${errors_SOURCES})
target_include_directories(errors_test PRIVATE ${errors_INCLUDES})
target_include_directories(errors_test PRIVATE ${errors_HEADER_DIRS})
target_link_libraries(errors_test PRIVATE Catch2::Catch2WithMain)

# Enable support to check for test coverage
Expand Down
11 changes: 8 additions & 3 deletions components/format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
cpmaddpackage("gh:fmtlib/fmt#10.0.0")

add_library(errors_format src/format.cpp)
target_include_directories(errors_format PUBLIC include)
target_sources(
errors_format PUBLIC
FILE_SET HEADERS
BASE_DIRS include
FILES include/errors/format.hpp
)
target_link_libraries(errors_format PUBLIC errors fmt)

if(NOT_SUBPROJECT)
if (BUILD_TESTING)
# Append the main library properties instead of linking the library.
get_target_property(errors_format_SOURCES errors_format SOURCES)
get_target_property(errors_format_INCLUDES errors_format INCLUDE_DIRECTORIES)
get_target_property(errors_format_HEADER_DIRS errors_format HEADER_DIRS)
get_target_property(errors_format_LIBRARIES errors_format LINK_LIBRARIES)

# Build tests for the main library
add_executable(errors_format_test test/format_test.cpp ${errors_format_SOURCES})
target_include_directories(errors_format_test PRIVATE ${errors_format_INCLUDES})
target_include_directories(errors_format_test PRIVATE ${errors_format_HEADER_DIRS})
target_link_libraries(errors_format_test PRIVATE Catch2::Catch2WithMain ${errors_format_LIBRARIES})

# Enable support to check for test coverage
Expand Down