From eecb1bc1b19a36b76b5206d794db6730d9279afb Mon Sep 17 00:00:00 2001 From: Ben Morgan Date: Wed, 23 Nov 2022 14:33:27 +0000 Subject: [PATCH 1/2] Do not include ROOT's use file ROOT's "use" file executes CMake {include,link}_directories as well as appending to CMAKE_CXX_FLAGS and executing add_definitions. The primary issue here is the use of include_directories, which - adds "-I" rather than "-isystem" paths to compile commands - mixes these with project-local setttings - flags appear in all subsequent compilations at the same directory scope any further subdirectories This was observed to cause an issue at link time for Celeritas programs using nlohmann_json, where the found ROOT had been installed with a builtin nlohmann_json of different version to that found by CMake. The above scoped injection of the ROOT include path meant that different nlohmann_json headers were used at library, application compile time resulting in undefined symbol errors. Remove inclusion of ROOT's use file from Celeritas build scripts. ROOTConfig.cmake, and hence find_package(ROOT) now set up the needed CMAKE_MODULE_PATH and other ROOT-related variables with relevant compile options propagated through target usage requirements. --- src/celeritas/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/celeritas/CMakeLists.txt b/src/celeritas/CMakeLists.txt index 2b75af6771..348375bcd4 100644 --- a/src/celeritas/CMakeLists.txt +++ b/src/celeritas/CMakeLists.txt @@ -140,7 +140,6 @@ if(CELERITAS_USE_ROOT) # Call the ROOT library generation inside a function to prevent ROOT-defined # directory properties from escaping function(celeritas_root_library objlib root_tgt) - include(${ROOT_USE_FILE}) # Use directory includes because ROOT has trouble with build/install # interface dependencies propagated through corecel include_directories( From dc8476c99cb2fa29f72fefa1ae9b2eb95bef6534 Mon Sep 17 00:00:00 2001 From: Ben Morgan Date: Wed, 23 Nov 2022 16:58:14 +0000 Subject: [PATCH 2/2] Inline ROOT dictionary generation Use of a function to hide ROOT setting directory properties is now redundant as ROOT "use" file no longer included. Inline function code in script, removing/updating function variables as needed. --- src/celeritas/CMakeLists.txt | 104 +++++++++++++++++------------------ 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/src/celeritas/CMakeLists.txt b/src/celeritas/CMakeLists.txt index 348375bcd4..d087bcddb2 100644 --- a/src/celeritas/CMakeLists.txt +++ b/src/celeritas/CMakeLists.txt @@ -137,59 +137,57 @@ if(CELERITAS_USE_OpenMP) endif() if(CELERITAS_USE_ROOT) - # Call the ROOT library generation inside a function to prevent ROOT-defined - # directory properties from escaping - function(celeritas_root_library objlib root_tgt) - # Use directory includes because ROOT has trouble with build/install - # interface dependencies propagated through corecel - include_directories( - "${PROJECT_SOURCE_DIR}/src" - "${CELERITAS_HEADER_CONFIG_DIRECTORY}" - ) - - # Set the CMAKE output directory locally to inform ROOT where we put our - # libs - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CELERITAS_LIBRARY_OUTPUT_DIRECTORY}) - - # Generate the - root_generate_dictionary(${root_tgt} - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportData.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportElement.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportMaterial.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportParticle.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportPhysicsTable.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportPhysicsVector.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportProcess.hh" - "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportVolume.hh" - NOINSTALL - MODULE celeritas - LINKDEF "${CMAKE_CURRENT_SOURCE_DIR}/ext/RootInterfaceLinkDef.h" - ) - celeritas_add_object_library(${objlib} - ext/RootExporter.cc - ext/RootImporter.cc - ext/ScopedRootErrorHandler.cc - ext/detail/TFileUniquePtr.root.cc - "${CMAKE_CURRENT_BINARY_DIR}/${root_tgt}.cxx" - ) - target_link_libraries(${objlib} - PRIVATE Celeritas::corecel ROOT::Core ROOT::Tree - ) - - # Install the rootmap/pcm files needed for users or downstream apps to use - # Celeritas ROOT interfaces - set(_lib_prefix - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_LIBRARY_PREFIX}celeritas" - ) - install(FILES - "${_lib_prefix}.rootmap" - "${_lib_prefix}_rdict.pcm" - COMPONENT runtime - DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) - endfunction() - - celeritas_root_library(celeritas_root CeleritasRootInterface) + # Use directory includes because ROOT has trouble with build/install + # interface dependencies propagated through corecel. + # This is safe here as it is only adding project-local paths that are + # identical to those set in corecel's usage requirments. + include_directories( + "${PROJECT_SOURCE_DIR}/src" + "${CELERITAS_HEADER_CONFIG_DIRECTORY}" + ) + + # Set the CMAKE output directory locally to inform ROOT where we put our + # libs. Safe against overriding project settings as the celeritas_add_... + # functions set this to the same value for our targets. + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CELERITAS_LIBRARY_OUTPUT_DIRECTORY}) + + # Generate the dictionary source file + root_generate_dictionary(CeleritasRootInterface + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportData.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportElement.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportMaterial.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportParticle.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportPhysicsTable.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportPhysicsVector.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportProcess.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/io/ImportVolume.hh" + NOINSTALL + MODULE celeritas + LINKDEF "${CMAKE_CURRENT_SOURCE_DIR}/ext/RootInterfaceLinkDef.h" + ) + celeritas_add_object_library(celeritas_root + ext/RootExporter.cc + ext/RootImporter.cc + ext/ScopedRootErrorHandler.cc + ext/detail/TFileUniquePtr.root.cc + "${CMAKE_CURRENT_BINARY_DIR}/CeleritasRootInterface.cxx" + ) + target_link_libraries(celeritas_root + PRIVATE Celeritas::corecel ROOT::Core ROOT::Tree + ) + + # Install the rootmap/pcm files needed for users or downstream apps to use + # Celeritas ROOT interfaces + set(_lib_prefix + "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_LIBRARY_PREFIX}celeritas" + ) + install(FILES + "${_lib_prefix}.rootmap" + "${_lib_prefix}_rdict.pcm" + COMPONENT runtime + DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ) + list(APPEND SOURCES $) list(APPEND PRIVATE_DEPS celeritas_root) endif()