From 4c64d7daef8819d644ab78a911067b16943f023d Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 2 Feb 2026 22:50:17 +0100 Subject: build: Refactor CMake back to in-tree CMakeLists This moves the build definitions back to src/ subdirectories (CMakeLists.txt per component). Configuration and dependencies are kept out of tree. Configuration options are bundled into cmake/config/ modules. Dependencies are grouped by component (system/, crypt/, eth/, coverage/, etc.). It now consistently uses target-based commands (target_include_directories, target_link_libraries) instead of global include_directories(). Proper PRIVATE/PUBLIC visibility for executable link libraries. CONFIG_OUROBOROS_DEBUG now properly set based on being a valid debug config (not just checking the string name). It also adds OuroborosTargets export for find_package() support and CMake package config files (OuroborosConfig.cmake) for easier integration with CMake projects. The build logic now follows more idiomatic CMake practices with configuration separated from target definitions. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- cmake/install.cmake | 87 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 25 deletions(-) (limited to 'cmake/install.cmake') diff --git a/cmake/install.cmake b/cmake/install.cmake index 21a8cd52..79714df2 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -1,12 +1,48 @@ # Installation configuration -# Install pkg-config files +include(CMakePackageConfigHelpers) + +# Public headers +install(FILES ${PUBLIC_HEADER_FILES} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ouroboros) + +# Man pages +if(GZIP_EXECUTABLE) + foreach(_man ${MAN_FILES}) + string(REGEX REPLACE "^.+[.]([1-9]).gz" "\\1" _mansect ${_man}) + install(FILES ${_man} DESTINATION "${CMAKE_INSTALL_MANDIR}/man${_mansect}") + endforeach() +endif() + +# pkg-config files install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros-dev.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros-irm.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +set(OUROBOROS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Ouroboros") + +install(EXPORT OuroborosTargets + FILE OuroborosTargets.cmake + NAMESPACE Ouroboros:: + DESTINATION ${OUROBOROS_CMAKE_DIR}) + +configure_package_config_file( + "${CMAKE_SOURCE_DIR}/cmake/OuroborosConfig.cmake.in" + "${CMAKE_BINARY_DIR}/OuroborosConfig.cmake" + INSTALL_DESTINATION ${OUROBOROS_CMAKE_DIR}) + +write_basic_package_version_file( + "${CMAKE_BINARY_DIR}/OuroborosConfigVersion.cmake" + VERSION ${PACKAGE_VERSION} + COMPATIBILITY SameMajorVersion) + +install(FILES + "${CMAKE_BINARY_DIR}/OuroborosConfig.cmake" + "${CMAKE_BINARY_DIR}/OuroborosConfigVersion.cmake" + DESTINATION ${OUROBOROS_CMAKE_DIR}) + # Systemd service file installation set(SYSTEMD_INSTALL_FILES "DETECT" CACHE STRING "Install systemd .service files (NO (never), DETECT (use pkg-config - default),\ @@ -15,50 +51,51 @@ set(SYSTEMD_UNITDIR_OVERRIDE "" CACHE PATH "Path to install systemd files. When SYSTEMD_INSTALL_FILES == DETECT, this\ can be empty to automatically determine the path. Cannot be empty when FORCE.") -if (SYSTEMD_INSTALL_FILES STREQUAL "DETECT" OR SYSTEMD_INSTALL_FILES STREQUAL "FORCE") - if (SYSTEMD_INSTALL_FILES STREQUAL "DETECT") - pkg_check_modules(SYSTEMD "systemd") - if (SYSTEMD_FOUND) - if ("${SYSTEMD_UNITDIR_OVERRIDE}" STREQUAL "") +if(SYSTEMD_INSTALL_FILES STREQUAL "DETECT" OR SYSTEMD_INSTALL_FILES STREQUAL "FORCE") + if(SYSTEMD_INSTALL_FILES STREQUAL "DETECT") + if(PkgConfig_FOUND) + pkg_check_modules(SYSTEMD "systemd") + endif() + if(SYSTEMD_FOUND) + if(SYSTEMD_UNITDIR_OVERRIDE STREQUAL "") execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=systemdsystemunitdir systemd OUTPUT_VARIABLE SYSTEMD_UNITDIR_INTERNAL) string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNITDIR_INTERNAL "${SYSTEMD_UNITDIR_INTERNAL}" ) - else () + else() set(SYSTEMD_UNITDIR_INTERNAL "${SYSTEMD_UNITDIR_OVERRIDE}") - endif () - else () + endif() + else() set(SYSTEMD_UNITDIR_INTERNAL "") - endif () - elseif (SYSTEMD_INSTALL_FILES STREQUAL "FORCE") - if ("${SYSTEMD_UNITDIR_OVERRIDE}" STREQUAL "") + endif() + elseif(SYSTEMD_INSTALL_FILES STREQUAL "FORCE") + if(SYSTEMD_UNITDIR_OVERRIDE STREQUAL "") message(FATAL_ERROR "Systemd installation required by user, but no path\ provided with SYSTEMD_UNITDIR_OVERRIDE.") - else () + else() set(SYSTEMD_UNITDIR_INTERNAL "${SYSTEMD_UNITDIR_OVERRIDE}") - endif () + endif() endif() - if (NOT ${SYSTEMD_UNITDIR_INTERNAL} STREQUAL "") + if(NOT SYSTEMD_UNITDIR_INTERNAL STREQUAL "") message(STATUS "Systemd service installation enabled to: ${SYSTEMD_UNITDIR_INTERNAL}") - if (LIBTOML_LIBRARIES AND NOT DISABLE_CONFIGFILE) + if(LIBTOML_LIBRARIES AND NOT DISABLE_CONFIGFILE) set (CONFIGURE_STRING "--config ${OUROBOROS_CONFIG_DIR}/${OUROBOROS_CONFIG_FILE}") - else () + else() set (CONFIGURE_STRING "") - endif () - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ouroboros.service.in" - "${CMAKE_CURRENT_BINARY_DIR}/ouroboros.service" @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros.service" + endif() + configure_file("${CMAKE_SOURCE_DIR}/ouroboros.service.in" + "${CMAKE_BINARY_DIR}/ouroboros.service" @ONLY) + install(FILES "${CMAKE_BINARY_DIR}/ouroboros.service" DESTINATION "${SYSTEMD_UNITDIR_INTERNAL}") - endif () -else () + endif() +else() message(STATUS "Systemd service installation disabled by user") endif() -# Uninstall target configure_file("${CMAKE_SOURCE_DIR}/cmake/utils/CMakeUninstall.cmake.in" - "${CMAKE_BINARY_DIR}/cmake/cmakeuninstall.cmake" IMMEDIATE @ONLY) + "${CMAKE_BINARY_DIR}/cmake/cmakeuninstall.cmake" @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake/cmakeuninstall.cmake) -- cgit v1.2.3