From b6723b921bbd925c4c267ea46705c42281f92018 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 24 Sep 2023 12:27:19 -0400 Subject: [PATCH] refcnt: build + install fixes --- CMakeLists.txt | 40 ++++++++++++++++++++++++++++-- cmake/cxx.cmake | 18 +++++++++++--- cmake/refcntConfig.cmake.in | 4 +++ include/refcnt/Refcounted.hpp | 46 +++++++++++++++++------------------ src/Refcounted.cpp | 2 +- 5 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 cmake/refcntConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e8053f..ed3c448 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) -project(xo-refcnt VERSION 0.1) +project(refcnt VERSION 0.1) enable_language(CXX) include(cmake/cxx.cmake) @@ -13,7 +13,6 @@ include(cmake/code-coverage.cmake) enable_testing() - # activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) add_code_coverage() # 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. @@ -26,6 +25,7 @@ add_code_coverage_all_targets(EXCLUDE /nix/store/* utest/*) # ---------------------------------------------------------------- # c++ settings +set(XO_PROJECT_NAME refcnt) set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") add_definitions(${PROJECT_CXX_FLAGS}) @@ -43,6 +43,42 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") # sources add_subdirectory(src) +add_subdirectory(utest) + +# ---------------------------------------------------------------- +# cmake export + +set(XO_PROJECT_CONFIG_VERSION "${XO_PROJECT_NAME}ConfigVersion.cmake") +set(XO_PROJECT_CONFIG "${XO_PROJECT_NAME}Config.cmake") + +include(CMakePackageConfigHelpers) +write_basic_package_version_file("${PROJECT_BINARY_DIR}/${XO_PROJECT_CONFIG_VERSION}" + VERSION 0.1 + COMPATIBILITY AnyNewerVersion +) + +#install( +# TARGETS ${XO_PROJECT_NAME} +# EXPORT ${XO_PROJECT_NAME}Targets +# LIBRARY DESTINATION lib COMPONENT Runtime +# ARCHIVE DESTINATION lib COMPONENT Development +# RUNTIME DESTINATION bin COMPONENT Runtime +# PUBLIC_HEADER DESTINATION include COMPONENT Development +# BUNDLE DESTINATION bin COMPONENT Runtime +# ) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${XO_PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${XO_PROJECT_CONFIG}" + INSTALL_DESTINATION lib/cmake/${XO_PROJECT_NAME} + ) + +install(EXPORT ${XO_PROJECT_NAME}Targets DESTINATION lib/cmake/${XO_PROJECT_NAME}) +install( + FILES + "${PROJECT_BINARY_DIR}/${XO_PROJECT_CONFIG_VERSION}" + "${PROJECT_BINARY_DIR}/${XO_PROJECT_CONFIG}" + DESTINATION lib/cmake/${XO_PROJECT_NAME}) # ---------------------------------------------------------------- # install .hpp diff --git a/cmake/cxx.cmake b/cmake/cxx.cmake index 9fc84e6..4f2dd2f 100644 --- a/cmake/cxx.cmake +++ b/cmake/cxx.cmake @@ -14,9 +14,11 @@ macro(xo_include_options target) # target_include_directories( ${target} PUBLIC - ${PROJECT_SOURCE_DIR}/include # e.g. for #include "indentlog/scope.hpp" - ${PROJECT_SOURCE_DIR}/include/${target} # e.g. for #include "Refcounted.hpp" in refcnt/src - ${PROJECT_BINARY_DIR} # e.g. for generated config.hpp file + $ # e.g. for #include "indentlog/scope.hpp" + $ + $ # e.g. for #include "Refcounted.hpp" in refcnt/src + $ + $ # e.g. for generated config.hpp file ) # ---------------------------------------------------------------- @@ -72,7 +74,15 @@ endmacro() # use this for a subdir that builds a library # macro(xo_install_library target) - install(TARGETS ${target} DESTINATION lib) + install( + TARGETS ${target} + EXPORT ${target}Targets + LIBRARY DESTINATION lib COMPONENT Runtime + ARCHIVE DESTINATION lib COMPONENT Development + RUNTIME DESTINATION bin COMPONENT Runtime + PUBLIC_HEADER DESTINATION include COMPONENT Development + BUNDLE DESTINATION bin COMPONENT Runtime + ) endmacro() # ---------------------------------------------------------------- diff --git a/cmake/refcntConfig.cmake.in b/cmake/refcntConfig.cmake.in new file mode 100644 index 0000000..e13a2c5 --- /dev/null +++ b/cmake/refcntConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@XO_PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/include/refcnt/Refcounted.hpp b/include/refcnt/Refcounted.hpp index 17d778c..dc069cf 100644 --- a/include/refcnt/Refcounted.hpp +++ b/include/refcnt/Refcounted.hpp @@ -171,31 +171,31 @@ namespace xo { return 0; } /*intrusive_ptr_refcount*/ - void intrusive_ptr_set_debug(bool x); - void intrusive_ptr_log_ctor(std::string_view const & self_type, - void * this_ptr, - Refcount * x); + extern void intrusive_ptr_set_debug(bool x); + extern void intrusive_ptr_log_ctor(std::string_view const & self_type, + void * this_ptr, + Refcount * x); /* here actor short for 'aliasing ctor' */ - void intrusive_ptr_log_actor(std::string_view const & self_type, - void * this_ptr, - Refcount * x); - void intrusive_ptr_log_cctor(std::string_view const & self_type, - void * this_ptr, - Refcount * x); - void intrusive_ptr_log_mctor(std::string_view const & self_type, - void *this_ptr, - Refcount * x); - void intrusive_ptr_log_dtor(std::string_view const & self_type, - void * this_ptr, - Refcount * x); - void intrusive_ptr_log_assign(std::string_view const & self_type, - void * this_ptr, - Refcount * x); - void intrusive_ptr_log_massign(std::string_view const & self_type, - void *this_ptr, + extern void intrusive_ptr_log_actor(std::string_view const & self_type, + void * this_ptr, + Refcount * x); + extern void intrusive_ptr_log_cctor(std::string_view const & self_type, + void * this_ptr, + Refcount * x); + extern void intrusive_ptr_log_mctor(std::string_view const & self_type, + void *this_ptr, + Refcount * x); + extern void intrusive_ptr_log_dtor(std::string_view const & self_type, + void * this_ptr, + Refcount * x); + extern void intrusive_ptr_log_assign(std::string_view const & self_type, + void * this_ptr, + Refcount * x); + extern void intrusive_ptr_log_massign(std::string_view const & self_type, + void *this_ptr, Refcount * x); - void intrusive_ptr_add_ref(Refcount * x); - void intrusive_ptr_release(Refcount * x); + extern void intrusive_ptr_add_ref(Refcount * x); + extern void intrusive_ptr_release(Refcount * x); template inline std::ostream & diff --git a/src/Refcounted.cpp b/src/Refcounted.cpp index 9aeb579..11c8cb6 100644 --- a/src/Refcounted.cpp +++ b/src/Refcounted.cpp @@ -22,7 +22,7 @@ namespace xo { } /*intrusive_ptr_log_aux*/ } /*namespace*/ - bool + void intrusive_ptr_set_debug(bool debug_flag) { s_logging_enabled = debug_flag; } /*intrusive_ptr_set_debug*/