Skip to content

[CMake] Move towards target-based CMake and partly fix picking up headers from an installed ROOT #8709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions builtins/nlohmann/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Install nlohmann/json.hpp include to have it
# Install nlohmann/json.hpp and json_fwd.hpp
# This file will define the target
# nlohmann_json
# and the alias
# nlohmann_json::nlohmann_json
# with proper #defines and includes. Use the alias target with the full prefix for access to JSON.

# file only used when ACLiC or ROOT macros will include REve headers,
# it is not used for ROOT compilation
# The installed files are only used when ACLiC or ROOT macros will include REve headers,
# they are not used for ROOT compilation, as this happens directly from the source directory.

# extract version from existing header file
file(STRINGS "json.hpp" JSON_H REGEX "^#define NLOHMANN_JSON_VERSION_[A-Z]+[ ]+[0-9]+.*$")
Expand All @@ -20,4 +25,15 @@ set_property(GLOBAL APPEND PROPERTY ROOT_BUILTIN_TARGETS builtin_nlohmann_json_i

install(FILES ${CMAKE_SOURCE_DIR}/builtins/nlohmann/json.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nlohmann/)

# Create a target and all its configs:
add_library(nlohmann_json INTERFACE)

target_include_directories(nlohmann_json INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/builtins> $<INSTALL_INTERFACE:include>)
target_compile_definitions(nlohmann_json INTERFACE NLOHMANN_JSON_PROVIDES_FWD_HPP)

install(TARGETS nlohmann_json
EXPORT ROOTExports)
set_property(GLOBAL APPEND PROPERTY ROOT_EXPORTED_TARGETS nlohmann_json)

# Alias, so can use it as drop-in replacement for system nlohmann_json.
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
1 change: 1 addition & 0 deletions builtins/openssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ set(OPENSSL_INCLUDE_DIRS ${OPENSSL_PREFIX}/include CACHE INTERNAL "" FORCE)
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY} CACHE INTERNAL "" FORCE)
set(OPENSSL_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY} CACHE INTERNAL "" FORCE)
set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${CMAKE_DL_LIBS} CACHE INTERNAL "" FORCE)
set(OPENSSL_ROOT ${OPENSSL_PREFIX} CACHE INTERNAL "Location of the builtin OpenSSL installation" FORCE)

# Dependent libraries might check for the existence of the include directories
file(MAKE_DIRECTORY ${OPENSSL_INCLUDE_DIR})
Expand Down
38 changes: 13 additions & 25 deletions builtins/xrootd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@
include(ExternalProject)

set(XROOTD_VERSION "5.8.0")
set(XROOTD_PREFIX ${CMAKE_BINARY_DIR}/XROOTD-prefix)

set(XROOTD_PREFIX ${CMAKE_BINARY_DIR})
message(STATUS "Downloading and building XROOTD version ${XROOTD_VERSION}")

list(REMOVE_ITEM XROOTD_CLIENT_LIBRARIES OpenSSL::SSL)
list(REMOVE_ITEM XROOTD_UTILS_LIBRARIES OpenSSL::SSL)

set(libname ${CMAKE_SHARED_LIBRARY_PREFIX}XrdCl${CMAKE_SHARED_LIBRARY_SUFFIX})
list(APPEND XROOTD_CLIENT_LIBRARIES ${XROOTD_PREFIX}/lib/${libname})
list(REMOVE_DUPLICATES XROOTD_CLIENT_LIBRARIES)

set(libname ${CMAKE_SHARED_LIBRARY_PREFIX}XrdUtils${CMAKE_SHARED_LIBRARY_SUFFIX})
list(APPEND XROOTD_UTILS_LIBRARIES ${XROOTD_PREFIX}/lib/${libname})
list(REMOVE_DUPLICATES XROOTD_UTILS_LIBRARIES)

ExternalProject_Add(
BUILTIN_XROOTD
URL http://lcgpackages.web.cern.ch/lcgpackages/tarFiles/sources/xrootd-${XROOTD_VERSION}.tar.gz
Expand All @@ -41,10 +30,11 @@ ExternalProject_Add(
-DENABLE_CEPH=OFF
-DXRDCL_LIB_ONLY=ON
-DCMAKE_INSTALL_RPATH:STRING=${XROOTD_PREFIX}/lib
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
-DOpenSSL_ROOT=${OPENSSL_ROOT} #For CMake <3.27
-DOPENSSL_ROOT=${OPENSSL_ROOT}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install
LOG_DOWNLOAD 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 LOG_OUTPUT_ON_FAILURE 1
BUILD_BYPRODUCTS ${XROOTD_CLIENT_LIBRARIES} ${XROOTD_UTILS_LIBRARIES}
BUILD_BYPRODUCTS XrdUtils XrdCl
TIMEOUT 600
)

Expand All @@ -55,22 +45,19 @@ if(builtin_openssl)
add_dependencies(BUILTIN_XROOTD OPENSSL)
endif()

list(APPEND XROOTD_CLIENT_LIBRARIES OpenSSL::SSL)
list(REMOVE_DUPLICATES XROOTD_CLIENT_LIBRARIES)
list(APPEND XROOTD_UTILS_LIBRARIES OpenSSL::SSL)
list(REMOVE_DUPLICATES XROOTD_UTILS_LIBRARIES)

set(XROOTD_INCLUDE_DIRS ${XROOTD_PREFIX}/include/xrootd CACHE INTERNAL "" FORCE)
set(XROOTD_CLIENT_LIBRARIES ${XROOTD_CLIENT_LIBRARIES} CACHE INTERNAL "" FORCE)
set(XROOTD_UTILS_LIBRARIES ${XROOTD_UTILS_LIBRARIES} CACHE INTERNAL "" FORCE)
set(XRDCL_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}XrdCl${CMAKE_SHARED_LIBRARY_SUFFIX})
set(XRDUTILS_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}XrdUtils${CMAKE_SHARED_LIBRARY_SUFFIX})
set(XROOTD_CLIENT_LIBRARIES ${XROOTD_PREFIX}/lib/${XRDCL_NAME} CACHE INTERNAL "" FORCE)
set(XROOTD_UTILS_LIBRARIES ${XROOTD_PREFIX}/lib/${XRDUTILS_NAME} CACHE INTERNAL "" FORCE)
set(XROOTD_LIBRARIES ${XROOTD_PREFIX}/lib/${XRDCL_NAME} CACHE INTERNAL "" FORCE)

list(APPEND CMAKE_BUILD_RPATH ${XROOTD_PREFIX}/lib)
add_dependencies(XRootD BUILTIN_XROOTD)
install(DIRECTORY ${XROOTD_PREFIX}/lib/ DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries FILES_MATCHING PATTERN "libXrd*")
install(DIRECTORY ${XROOTD_PREFIX}/include/xrootd/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xrootd COMPONENT headers)
set(CMAKE_BUILD_RPATH ${CMAKE_BUILD_RPATH} ${XROOTD_PREFIX}/lib PARENT_SCOPE)

set_property(GLOBAL APPEND PROPERTY ROOT_BUILTIN_TARGETS BUILTIN_XROOTD)

install(DIRECTORY ${XROOTD_PREFIX}/lib/ DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries FILES_MATCHING PATTERN "libXrd*")
install(DIRECTORY ${XROOTD_PREFIX}/include/xrootd/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xrootd COMPONENT headers)
if(APPLE)
# XRootD libraries on mac need the LC_RPATH variable set. The build process already takes care of setting
# * BUILD_RPATH = build/XROOTD-prefix/../src
Expand All @@ -81,3 +68,4 @@ if(APPLE)
CODE "xrootd_libs_change_rpath(${XROOTD_PREFIX}/lib ${CMAKE_INSTALL_FULL_LIBDIR})"
)
endif()

81 changes: 0 additions & 81 deletions cmake/modules/FindGTest.cmake

This file was deleted.

18 changes: 10 additions & 8 deletions cmake/modules/FindVdt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``VDT::VDT``,
# if Vdt has been found.
# VDT::VDT if Vdt has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -42,8 +41,6 @@ if(NOT VDT_LIBRARY)
find_library(VDT_LIBRARY NAMES vdt)
endif()

mark_as_advanced(VDT_INCLUDE_DIR VDT_LIBRARY)

if(VDT_INCLUDE_DIR)
file(STRINGS "${VDT_INCLUDE_DIR}/vdt/vdtMath.h" VDT_H REGEX "^#define VDT_VERSION_[A-Z]+[ ]+[0-9]+.*$")
string(REGEX REPLACE ".+VDT_VERSION_MAJOR[ ]+([0-9]+).*$" "\\1" VDT_VERSION_MAJOR "${VDT_H}")
Expand All @@ -59,9 +56,14 @@ if(VDT_INCLUDE_DIR)
endif()
endif()

# Don't show in GUI
mark_as_advanced(VDT_FOUND VDT_VERSION VDT_INCLUDE_DIR VDT_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Vdt FOUND_VAR VDT_FOUND
REQUIRED_VARS VDT_INCLUDE_DIR VDT_LIBRARY VERSION_VAR VDT_VERSION)
find_package_handle_standard_args(Vdt
REQUIRED_VARS VDT_INCLUDE_DIR VDT_LIBRARY
VERSION_VAR VDT_VERSION)


if(VDT_FOUND)
set(VDT_INCLUDE_DIRS ${VDT_INCLUDE_DIR})
Expand All @@ -71,12 +73,12 @@ if(VDT_FOUND)
endif()

if(NOT TARGET VDT::VDT)
add_library(VDT::VDT UNKNOWN IMPORTED)
add_library(VDT::VDT SHARED IMPORTED)
target_include_directories(VDT::VDT SYSTEM INTERFACE ${VDT_INCLUDE_DIRS})

set_target_properties(VDT::VDT
PROPERTIES
IMPORTED_LOCATION "${VDT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${VDT_INCLUDE_DIRS}"
)
endif()
endif()
Loading
Loading