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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9c6485a
Make CppInterOp work with new gtest target names.
hageboeck Jun 24, 2025
1e8e6ba
[sofie] Add missing link to Core.
hageboeck Jun 18, 2025
1156518
[imt] Fix missing include directories for TBB
hageboeck Dec 13, 2022
938f13f
[Tree] Remove res/ header from tests.
hageboeck Dec 26, 2023
02dc777
[RDF] Remove an unused include from the datasetspec test.
hageboeck Jun 20, 2025
dd0f33b
Add missing includes of gtest.h
hageboeck Jan 14, 2025
92095ef
Remove gtest include from TestSupport.hxx.
hageboeck Jan 14, 2025
c628b2f
[cling] Add parsing of -isystem arguments to rootcling.
hageboeck Feb 10, 2023
377987d
[CMake] Make VDT an IMPORTED target; convert to target-based cmake.
hageboeck Jul 12, 2021
3158318
[CMake] Make XRootD config target-based.
hageboeck Jul 12, 2021
9641c3f
[CMake] Require OpenSSL when XRootD is a builtin.
hageboeck Feb 3, 2025
8ebed97
[CMake] Save location of the builtin openssl.
hageboeck Feb 3, 2025
4ae0deb
[CMake] Make nlohmann_json config target-based.
hageboeck Jul 13, 2021
1422dac
[CMake] Make lzma config target-based.
hageboeck Feb 27, 2024
e36077c
[CMake] Remove manual lists of include directories.
hageboeck Jul 13, 2021
0c17e88
[CMake] Consolidate dependency management for ROOT_LINKER_LIBRARY.
hageboeck Jul 21, 2021
b3aed70
[CMake] Use modern target_link_library syntax for exectuables.
hageboeck Jul 21, 2021
dce6f64
[CMake] Improve ROOT_GENERATE_DICTIONARY
hageboeck Jul 21, 2021
fb0097f
[CMake] Fix unit test config for core/thread.
hageboeck Mar 23, 2023
b674226
[CMake][NFC] Clarify arguments of ROOT_STANDARD_LIBRARY_PACKAGE.
hageboeck Oct 26, 2023
556b623
[CMake][NFC] Remove an unused argument for ROOT_ADD_TEST.
hageboeck Dec 27, 2022
bd78653
[CMake] Move to CMake's native FindGTest
hageboeck Mar 14, 2024
054aff5
[core] Add missing gmock dependencies.
hageboeck Jan 13, 2025
3583493
[CMake] Use CMAKE_CXX_COMPILER_LAUNCHER for ccache.
hageboeck Jun 17, 2025
e9ae5bb
[CMake] Move setting of OSX_SYSROOT before project().
hageboeck Jun 17, 2025
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
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ if(WIN32)
cmake_policy(SET CMP0091 OLD)
set(CMAKE_SKIP_TEST_ALL_DEPENDENCY TRUE)
endif()
if(APPLE AND (NOT CMAKE_OSX_SYSROOT OR CMAKE_OSX_SYSROOT STREQUAL ""))
# The SYSROOT *must* be set before the project() call
execute_process(COMMAND xcrun --sdk macosx --show-sdk-path
OUTPUT_VARIABLE SDK_PATH
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(NOT EXISTS "${SDK_PATH}")
message(FATAL_ERROR "Could not detect macOS SDK path")
endif()

set(CMAKE_OSX_SYSROOT "${SDK_PATH}" CACHE PATH "SDK path" FORCE)
endif()

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE)
message(FATAL_ERROR
Expand Down Expand Up @@ -217,7 +230,7 @@ if(ccache)

if(EXISTS ${CCACHE_COMMAND})
message(STATUS "Found ccache: ${CCACHE_COMMAND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_COMMAND})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_COMMAND} CACHE STRING "Path to ccache" FORCE)
execute_process(COMMAND ${CCACHE_COMMAND} "-V" OUTPUT_VARIABLE CCACHE_VERSION)
string(REGEX REPLACE "ccache version ([0-9\\.]+).*" "\\1" CCACHE_VERSION ${CCACHE_VERSION})
else()
Expand Down
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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably keep only -DOpenSSL_ROOT here, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try

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