Skip to content

Commit

Permalink
🔧 Copy deps to ./include/ to support add_subdirectory() usage
Browse files Browse the repository at this point in the history
Reverts regression by 8550275
  • Loading branch information
heavywatal committed Oct 28, 2024
1 parent aad636c commit d4490bd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/include/clippson/*.h
/include/clippson/json*
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(clippson
VERSION 0.8.8
LANGUAGES CXX)

cmake_policy(SET CMP0169 OLD) # 3.28
set(CMAKE_VERBOSE_MAKEFILE ON)
include(CMakePrintHelpers)
include(FetchContent)
Expand Down Expand Up @@ -31,6 +32,7 @@ function(git_fetch package version repo)
GIT_TAG ${tag}
GIT_SHALLOW ON
)
FetchContent_GetProperties(${package})
if(NOT ${package}_POPULATED)
FetchContent_Populate(${package})
endif()
Expand All @@ -41,25 +43,23 @@ endfunction()
git_fetch(clipp v1.2.3.1 heavywatal/clipp)
git_fetch(json v3.11.3 heavywatal/json)

set(clipp_srcs ${clipp_SOURCE_DIR}/include/clipp.h)
set(json_srcs ${json_SOURCE_DIR}/src/json.hpp ${json_SOURCE_DIR}/src/json_fwd.hpp)
foreach(src IN LISTS ${clipp_srcs} ${json_srcs})
configure_file(${src} ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME} COPYONLY)
endforeach()

add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${clipp_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${json_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES
${clipp_SOURCE_DIR}/include/clipp.h
${json_SOURCE_DIR}/src/json.hpp
${json_SOURCE_DIR}/src/json_fwd.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-config
)
Expand Down
5 changes: 2 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(source_files
example.cpp
include_deps.cpp
types_target.cpp
types_json.cpp
types_both.cpp
Expand All @@ -8,9 +9,7 @@ set(source_files
foreach(src IN LISTS source_files)
get_filename_component(name_we ${src} NAME_WE)
add_executable(test-${name_we} ${src})
set_target_properties(test-${name_we} PROPERTIES
CXX_EXTENSIONS OFF
)
set_target_properties(test-${name_we} PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(test-${name_we} PRIVATE ${PROJECT_NAME}::${PROJECT_NAME})
target_compile_options(test-${name_we} PRIVATE -Wall -Wextra -pedantic)
add_test(NAME ${name_we} COMMAND $<TARGET_FILE:test-${name_we}> -h)
Expand Down
19 changes: 19 additions & 0 deletions test/include_deps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <clippson/clipp.h>
#include <clippson/json.hpp>

#include <iostream>

int main(int argc, char* argv[]) {
bool help;
bool verbose;
auto cli = (
clipp::option("-h", "--help").set(help).doc("print help"),
clipp::option("-v", "--verbose").set(verbose)
);
clipp::parse(argc, argv, cli);
nlohmann::json vm;
vm["help"] = help;
vm["verbose"] = verbose;
std::cout << vm << std::endl;
return 0;
}

0 comments on commit d4490bd

Please sign in to comment.