Skip to content
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

CMake improvement #9

Merged
merged 1 commit into from
Oct 22, 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
41 changes: 37 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,60 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(GNUInstallDirs)
include(ThirdParties)
include(ClangTidy)
include(PedanticCompiler)

set(boxed_cpp_HEADERS
include/boxed-cpp/boxed.hpp
${PROJECT_SOURCE_DIR}/include/boxed-cpp/boxed.hpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we adapt this for our other libraries as well? Especially libunicode? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine if you want to use ${PROJECT_SOURCE_DIR} in this situation for libunicode.

)
add_library(boxed-cpp INTERFACE)
add_library(boxed-cpp::boxed-cpp ALIAS boxed-cpp)

target_compile_features(boxed-cpp INTERFACE cxx_std_20)
target_include_directories(boxed-cpp INTERFACE
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Generate the version, config and target files
include(CMakePackageConfigHelpers)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(boxed-cpp-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/boxed-cpp
)

install(FILES ${boxed_cpp_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/boxed-cpp
)
install(TARGETS boxed-cpp
EXPORT boxed-cpp-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/boxed-cpp
)
install(EXPORT boxed-cpp-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/boxed-cpp
NAMESPACE boxed-cpp::
)

# ---------------------------------------------------------------------------
# unit tests

option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: ON]" OFF)
option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: OFF]" OFF)
if(BOXED_CPP_TESTS)
ThirdPartiesAdd_Catch2()
find_package(Catch2)
if (NOT Catch2_FOUND)
ThirdPartiesAdd_Catch2()
endif()
enable_testing()
add_executable(test-boxed-cpp
test-boxed-cpp.cpp
Expand Down
8 changes: 8 additions & 0 deletions boxed-cpp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

# prevent repeatedly including the targets
if(NOT TARGET boxed-cpp::boxed-cpp)
include(${CMAKE_CURRENT_LIST_DIR}/boxed-cpp-targets.cmake)
endif()

message(STATUS "Found @PROJECT_NAME@, version: ${@PROJECT_NAME@_VERSION}")