Skip to content
Snippets Groups Projects
Commit 26d26704 authored by Benjamin Morgan's avatar Benjamin Morgan
Browse files

Simplify build/use of builtin/system XercesC

- Make builtin "imported" target depend on XercesCBuiltIn external project.
- Subprojects only then need to link to the XercesC::XercesC target
  whether builtin/external is used
parent 3d098064
No related branches found
No related tags found
1 merge request!184Modernisation of CMake scripting to simplify build of FullSimLight
......@@ -28,9 +28,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# Set up how the project handle some of its dependenices. Either by picking them
# up from the environment, or building them itself.
include( SetupJSON )
if( NOT TARGET XercesCBuiltIn )
include( SetupXercesC )
endif()
include( SetupXercesC )
# Find the base GeoModel packages, which must be installed on the target system already
find_package( GeoModelCore REQUIRED ${GeoModel_VERSION} )
find_package( GeoModelIO REQUIRED ${GeoModel_VERSION} )
......@@ -136,15 +134,7 @@ add_executable(gm2gdml geoModel2GDML.cc ${sources} ${headers})
#----------------------------------------------------------------------------
# Add extra 'include' directories
#
# If the in-house build of the Xerces-C library is used, add explicit dependency: for Geant4
if( GEOMODEL_USE_BUILTIN_XERCESC )
add_dependencies( fullSimLight XercesCBuiltIn )
add_dependencies( gmclash XercesCBuiltIn )
add_dependencies( gmmasscalc XercesCBuiltIn )
add_dependencies( fillHistogramExample XercesCBuiltIn )
add_dependencies( gmgeantino XercesCBuiltIn )
add_dependencies( gm2gdml XercesCBuiltIn )
endif()
#----------------------------------------------------------------------------
# Link all needed libraries
#
......
......@@ -23,9 +23,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
"Framework finding behaviour on macOS" )
# Set up how the project handle some of its dependenices. Either by picking them
# up from the environment, or building them itself.
if( NOT TARGET XercesCBuiltIn )
include( SetupXercesC )
endif()
include( SetupXercesC )
# Find the base GeoModelATLAS packages, which must be installed on the target system already
find_package( GeoModelDataManagers REQUIRED ${GeoModelATLAS_VERSION} )
else()
......
......@@ -18,10 +18,7 @@ include(${Geant4_USE_FILE})
# Set target and properties
add_library( GeoMaterial2G4 SHARED ${HEADERS} ${SOURCES} )
# If the in-house build of the nlohmann_json library is used, add explicit dependency
if( GEOMODEL_USE_BUILTIN_XERCESC )
add_dependencies( GeoMaterial2G4 XercesCBuiltIn )
endif()
# Check if we are building FullSimLight individually,
# or as a part of the main GeoModel.
# In the first case, we link against the imported targets, which are taken
......
......@@ -28,9 +28,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# Set up how the project handle some of its dependenices. Either by picking them
# up from the environment, or building them itself.
include( SetupJSON )
if( NOT TARGET XercesCBuiltIn )
include( SetupXercesC )
endif()
include( SetupXercesC )
# Find the base GeoModel packages, which must be installed on the target system already
find_package( GeoModelCore REQUIRED ${GeoModel_VERSION} )
find_package( GeoModelIO REQUIRED ${GeoModel_VERSION} )
......
......@@ -6,12 +6,6 @@ file( GLOB HEADERS GDMLInterface/*.h )
# Create the library.
add_library( GDMLtoGM SHARED ${HEADERS} ${SOURCES} )
# If the in-house build of the Xerces-C library is used, add explicit dependency
if( GEOMODEL_USE_BUILTIN_XERCESC )
add_dependencies( GDMLtoGM XercesCBuiltIn )
endif()
target_link_libraries( GDMLtoGM PUBLIC XercesC::XercesC
ExpressionEvaluator GeoModelXMLParser GeoModelCore::GeoModelKernel )
target_include_directories( GDMLtoGM PUBLIC
......
......@@ -6,10 +6,6 @@ file( GLOB HEADERS GeoModelXMLParser/*.h )
# Create the library.
add_library( GeoModelXMLParser SHARED ${HEADERS} ${SOURCES} )
# If the in-house build of the Xerces-C library is used, add explicit dependency
if( GEOMODEL_USE_BUILTIN_XERCESC )
add_dependencies( GeoModelXMLParser XercesCBuiltIn )
endif()
target_link_libraries( GeoModelXMLParser PUBLIC XercesC::XercesC
ExpressionEvaluator )
target_include_directories( GeoModelXMLParser PUBLIC
......
......@@ -4,74 +4,63 @@
# it on the build machine, or by downloading it during the build itself.
#
# Make sure that this file is only included once.
get_property( _xercescSetUp GLOBAL PROPERTY GEOMODEL_XERCESC_SET_UP SET )
if( _xercescSetUp )
unset( _xercescSetUp )
return()
endif()
set_property( GLOBAL PROPERTY GEOMODEL_XERCESC_SET_UP TRUE )
# Make sure that this file is only included once.]
include_guard(GLOBAL)
# Configuration option for how XercesC should be used.
option( GEOMODEL_USE_BUILTIN_XERCESC
"Download/build a version of XercesC during the build" FALSE )
option( GEOMODEL_USE_BUILTIN_XERCESC "Download/build a version of XercesC during the build" OFF)
# Now do what was requested.
if( GEOMODEL_USE_BUILTIN_XERCESC )
if(GEOMODEL_USE_BUILTIN_XERCESC)
# Tell the user what's happening.
message( STATUS "${BoldMagenta}'GEOMODEL_USE_BUILTIN_XERCESC' was set to 'true' ==> Building XercesC as part of the project${ColourReset}" )
# Tell the user what's happening.
message( STATUS "${BoldMagenta}'GEOMODEL_USE_BUILTIN_XERCESC' was set to 'true' ==> Building XercesC as part of the project${ColourReset}" )
# The include directory and library that will be produced.
set( XercesC_INCLUDE_DIR
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Path to the Xerces-C include directory" FORCE )
set( XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}" )
set( XercesC_LIBRARY
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE PATH "Path to the Xerces-C library file" FORCE )
set( XercesC_LIBRARIES "${XercesC_LIBRARY}" )
set( XercesC_LIBRARY_RELEASE "${XercesC_LIBRARY}" CACHE PATH "Path to the Xerces-C library" FORCE )
set( XercesC_VERSION "3.2.3" )
# The include directory and library that will be produced.
set(XercesC_INCLUDE_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Path to the Xerces-C include directory" FORCE )
set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}" )
set(XercesC_LIBRARY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE PATH "Path to the Xerces-C library file" FORCE )
set(XercesC_LIBRARIES "${XercesC_LIBRARY}" )
set(XercesC_LIBRARY_RELEASE "${XercesC_LIBRARY}" CACHE PATH "Path to the Xerces-C library" FORCE )
set(XercesC_VERSION "3.2.3" )
# Create the include directory already, otherwise CMake refuses to
# create the imported target.
file( MAKE_DIRECTORY "${XercesC_INCLUDE_DIR}" )
# Create the include directory already, otherwise CMake refuses to
# create the imported target.
file( MAKE_DIRECTORY "${XercesC_INCLUDE_DIR}" )
# Build/install Eigen3 using ExternalProject_Add(...).
include( ExternalProject )
ExternalProject_Add( XercesCBuiltIn
PREFIX "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCBuild"
INSTALL_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall"
URL "https://cern.ch/lcgpackages/tarFiles/sources/xerces-c-${XercesC_VERSION}.tar.gz"
URL_MD5 "a5fa4d920fce31c9ca3bfef241644494"
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env CXXFLAGS=-std=c++${CMAKE_CXX_STANDARD}
<SOURCE_DIR>/configure --disable-static --prefix=<INSTALL_DIR>
INSTALL_COMMAND make install
COMMAND ${CMAKE_COMMAND} -E remove -f
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c.la"
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/pkgconfig"
BUILD_BYPRODUCTS "${XercesC_INCLUDE_DIR}" "${XercesC_LIBRARY}" )
install( DIRECTORY
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/bin"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib"
DESTINATION .
COMPONENT Runtime
USE_SOURCE_PERMISSIONS )
install( DIRECTORY "${XercesC_INCLUDE_DIR}"
DESTINATION .
COMPONENT Development
USE_SOURCE_PERMISSIONS )
# Build/install XercesC using ExternalProject_Add(...).
include(ExternalProject)
ExternalProject_Add( XercesCBuiltIn
PREFIX "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCBuild"
INSTALL_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall"
URL "https://cern.ch/lcgpackages/tarFiles/sources/xerces-c-${XercesC_VERSION}.tar.gz"
URL_MD5 "a5fa4d920fce31c9ca3bfef241644494"
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env CXXFLAGS=-std=c++${CMAKE_CXX_STANDARD} <SOURCE_DIR>/configure --disable-static --prefix=<INSTALL_DIR>
INSTALL_COMMAND make install
COMMAND ${CMAKE_COMMAND} -E remove -f "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c.la"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/pkgconfig"
BUILD_BYPRODUCTS "${XercesC_INCLUDE_DIR}" "${XercesC_LIBRARY}" )
install(DIRECTORY
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/bin"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib"
DESTINATION .
COMPONENT Runtime
USE_SOURCE_PERMISSIONS )
install(DIRECTORY "${XercesC_INCLUDE_DIR}"
DESTINATION .
COMPONENT Development
USE_SOURCE_PERMISSIONS )
# Set up XercesC's imported target.
add_library( XercesC::XercesC UNKNOWN IMPORTED )
set_target_properties( XercesC::XercesC PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIR}"
IMPORTED_LOCATION "${XercesC_LIBRARY}" )
# Set up local XercesC "imported" target.
add_library(XercesC::XercesC UNKNOWN IMPORTED)
set_target_properties( XercesC::XercesC PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIR}"
IMPORTED_LOCATION "${XercesC_LIBRARY}")
# Handle dependency to underlying external project
add_dependencies(XercesC::XercesC XercesCBuiltIn)
else()
# Just find an existing installation of XercesC.
find_package( XercesC REQUIRED )
# Just find an existing installation of XercesC.
find_package(XercesC REQUIRED)
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment