From b4052c647fc8d28f2c8b7daeb6faeb9a320efea6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 30 Apr 2024 10:16:51 -0500 Subject: [PATCH] xo-refcnt: build: streamline using recent xo-camke macros --- CMakeLists.txt | 33 +++++++--------------- cmake/xo-bootstrap-macros.cmake | 35 +++++++++++++++++++++++ src/CMakeLists.txt | 2 +- utest/CMakeLists.txt | 50 ++------------------------------- utest/intrusive_ptr.test.cpp | 2 +- 5 files changed, 49 insertions(+), 73 deletions(-) create mode 100644 cmake/xo-bootstrap-macros.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 655a14a4..336947d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,38 +3,30 @@ cmake_minimum_required(VERSION 3.10) project(refcnt VERSION 0.1) -enable_language(CXX) -# common XO cmake macros (see proj/xo-cmake) -include(xo_macros/xo_cxx) -include(xo_macros/code-coverage) +include(GNUInstallDirs) +include(cmake/xo-bootstrap-macros.cmake) + +xo_cxx_toplevel_options2() # ---------------------------------------------------------------- -# unit test setup +# cmake -DCMAKE_BUILD_TYPE=debug +xo_toplevel_debug_config2() -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. -# we're not interested in code coverage for these sources. -# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; -# rather, want coverage on the code that the unit tests exercise. -# -add_code_coverage_all_targets(EXCLUDE /nix/store/* utest/*) +# ---------------------------------------------------------------- +# cmake -DCMAKE_BUILD_TYPE=coverage +xo_toplevel_coverage_config2() # ---------------------------------------------------------------- # c++ settings -set(XO_PROJECT_NAME refcnt) +set(XO_PROJECT_NAME refcnt) # is this used? set(PROJECT_CXX_FLAGS "") #set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") # gcc-only! add_definitions(${PROJECT_CXX_FLAGS}) -xo_toplevel_compile_options() - # ---------------------------------------------------------------- -# sources add_subdirectory(src) add_subdirectory(utest) @@ -44,9 +36,4 @@ add_subdirectory(utest) xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) -# ---------------------------------------------------------------- -# install .hpp - -xo_install_include_tree() - # end CMakeLists.txt diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake new file mode 100644 index 00000000..aba31169 --- /dev/null +++ b/cmake/xo-bootstrap-macros.cmake @@ -0,0 +1,35 @@ +# ---------------------------------------------------------------- +# for example: +# $ PREFIX=/usr/local # for example +# $ cmake -DCMAKE_MODULE_PATH=prefix -DCMAKE_INSTALL_PREFIX=$PREFIX -B .build +# +# will get +# CMAKE_MODULE_PATH +# from xo-cmake-config --cmake-module-path +# +# and expect .cmake macros in +# CMAKE_MODULE_PATH/xo_macros/xo_cxx.cmake +# ---------------------------------------------------------------- + +find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED) + +if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND") + message(FATAL "could not find xo-cmake-config executable") +endif() + +message(STATUS "XO_CMAKE_CONFIG_EXECUTABLE=${XO_CMAKE_CONFIG_EXECUTABLE}") + +if (NOT XO_SUBMODULE_BUILD) + if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix)) + # default to typical install location for xo-project-macros + execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH) + message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + endif() +endif() + +# needs to have been installed somewhere on CMAKE_MODULE_PATH, +# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) +# +include(xo_macros/xo_cxx) + +xo_cxx_bootstrap_message() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d35b21d..4622ad44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ set(SELF_LIB refcnt) set(SELF_SRCS Refcounted.cpp Displayable.cpp) -xo_add_shared_library(${SELF_LIB} ${PROJECT_VERSION} 1 ${SELF_SRCS}) +xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) xo_dependency(${SELF_LIB} indentlog) diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index c19d0070..2e65b14b 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -4,58 +4,12 @@ set(SELF_EXECUTABLE_NAME utest.refcnt) # These tests can use the Catch2-provided main set(SELF_SOURCE_FILES intrusive_ptr.test.cpp refcnt_utest_main.cpp) -add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) -xo_include_options2(${SELF_EXECUTABLE_NAME}) - -add_test(NAME ${SELF_EXECUTABLE_NAME} COMMAND ${SELF_EXECUTABLE_NAME}) -target_code_coverage(${SELF_EXECUTABLE_NAME} AUTO ALL) - -#target_link_libraries(${SELF_EXECUTABLE_NAME} PRIVATE Catch2::Catch2WithMain) - -# ---------------------------------------------------------------- -# generic project dependency - -## PROJECT_SOURCE_DIR: -## so we can for example write -## #include "indentlog/scope.hpp" -## from anywhere in the project -## PROJECT_BINARY_DIR: -## since version file will be in build directory, need that directory -## to also be included in compiler's include path -## -#target_include_directories(${SELF_EXECUTABLE_NAME} PUBLIC -# ${PROJECT_SOURCE_DIR} -# ${PROJECT_BINARY_DIR}) - -# ---------------------------------------------------------------- -# internal dependencies: refcnt, ... - -xo_self_dependency(${SELF_EXECUTABLE_NAME} refcnt) -#target_link_libraries(${SELF_EXECUTABLE_NAME} PUBLIC refcnt) +xo_add_utest_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) # ---------------------------------------------------------------- # 3rd party dependency: catch2: +xo_self_dependency(${SELF_EXECUTABLE_NAME} refcnt) xo_external_target_dependency(${SELF_EXECUTABLE_NAME} Catch2 Catch2::Catch2) -# need this so that catch2/include appears in compile_commands.json, -# on which lsp integration relies. -# -# See also /nix/store/*-catch2-*/lib/cmake/Catch2/ParseAndAddCatchTests.cmake; -# commands here derived from ^ .cmake file -# -#find_path(CATCH_INCLUDE_DIR "catch2/catch.hpp") -#target_include_directories(${SELF_EXECUTABLE_NAME} PUBLIC ${CATCH_INCLUDE_DIR}) - -# ---------------------------------------------------------------- -# make standard directories for std:: includes explicit -# so that -# (1) they appear in compile_commands.json. -# (2) clangd (run from emacs lsp-mode) can find them -# -if(CMAKE_EXPORT_COMPILE_COMMANDS) - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) -endif() - # end CMakeLists.txt diff --git a/utest/intrusive_ptr.test.cpp b/utest/intrusive_ptr.test.cpp index bc45d38c..2b87f1d2 100644 --- a/utest/intrusive_ptr.test.cpp +++ b/utest/intrusive_ptr.test.cpp @@ -2,7 +2,7 @@ #include "Refcounted.hpp" #include "xo/indentlog/scope.hpp" -#include "catch2/catch.hpp" +#include #include #include