From 825f38f5b5a7ec83e96906f12bc31f8b9b14ea47 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 4 Oct 2024 20:07:11 +0200 Subject: [PATCH] CML: Create header-only target in IDEs Since CMake 3.19 it is possible to specify private sources for `INTERFACE` targets. This makes the library turn up like compiled libraries in IDEs such as Visual Studio. It can also be specified in the `add_library` call but using `target_sources` is more isolated to the CMake version check --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 976738b..79540d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,10 @@ add_library(boost_optional INTERFACE) add_library(Boost::optional ALIAS boost_optional) target_include_directories(boost_optional INTERFACE include) +if(NOT CMAKE_VERSION VERSION_LESS "3.19") + file(GLOB_RECURSE headers include/*.hpp) + target_sources(boost_optional PRIVATE ${headers}) +endif() target_link_libraries(boost_optional INTERFACE