Commit d4cf35e9 authored by Lynn Garren's avatar Lynn Garren
Browse files

improve component options per Ben Morgan

parent 03d3efc9
......@@ -20,10 +20,12 @@ macro(clhep_build_library package)
# check for dependencies
set( package_library_list )
set(package_library_list_static)
if( ${PACKAGE}_DEPS )
foreach ( dep ${${PACKAGE}_DEPS} )
##message( STATUS "clhep_build_library ${package} will use ${dep}")
list(APPEND package_library_list ${dep})
list(APPEND package_library_list_static ${dep}S)
endforeach()
endif()
......@@ -42,10 +44,11 @@ macro(clhep_build_library package)
)
target_link_libraries(${package} ${package_library_list} )
target_link_libraries(${package}S ${package_library_list} )
target_link_libraries(${package}S ${package_library_list_static} )
# Install the libraries
INSTALL (TARGETS ${package} ${package}S
EXPORT CLHEPLibraryDepends
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
......
......@@ -52,12 +52,22 @@ configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/CLHEPConfig.cmake.in
# We 'export' the main CLHEP library targets from the build tree.
# This file is include()d by CLHEPConfig.cmake
export(TARGETS CLHEP CLHEPS
# First build up list of all modular targets, static and shared
set(CLHEP_libraries_all ${CLHEP_libraries})
foreach(_lib ${CLHEP_libraries})
list(APPEND CLHEP_libraries_all "${_lib}S")
endforeach()
export(TARGETS CLHEP CLHEPS ${CLHEP_libraries_all}
NAMESPACE "CLHEP::"
FILE ${PROJECT_BINARY_DIR}/CLHEPLibraryDepends.cmake
)
# Now we configure clhep.pc.
#-----------------------------------------------------------------------
# Pkg-config setup
# Full clhep.pc.
# In the build tree we hardcode all paths, as we never need to relocate
# a build tree
#
......@@ -70,6 +80,23 @@ configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep.pc.in
@ONLY
)
# Messy deps for now (can't extract them from lower down the build tree)]
set(CLHEP_PC_Exceptions_REQUIRES "clhep-cast = ${CLHEP_VERSION}, clhep-refcount = ${CLHEP_VERSION}")
set(CLHEP_PC_Geometry_REQUIRES "clhep-vector = ${CLHEP_VERSION}")
set(CLHEP_PC_Matrix_REQUIRES "clhep-random = ${CLHEP_VERSION}, clhep-vector = ${CLHEP_VERSION}")
set(CLHEP_PC_RandomObjects_REQUIRES = "clhep-random = ${CLHEP_VERSION}, clhep-matrix = ${CLHEP_VERSION}, clhep-vector = ${CLHEP_VERSION}")
# Now the components
foreach(_lib ${CLHEP_libraries})
set(CLHEP_PC_COMPONENT ${_lib})
string(TOLOWER ${CLHEP_PC_COMPONENT} _pcfilename)
set(CLHEP_PC_COMPONENT_REQUIRES "${CLHEP_PC_${_lib}_REQUIRES}")
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep-component.pc.in
${PROJECT_BINARY_DIR}/clhep-${_pcfilename}.pc
@ONLY
)
endforeach()
#----------------------------------------------------------------------------
# - Now we handle the installation tree
......@@ -102,7 +129,7 @@ configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/CLHEPConfig.cmake.in
@ONLY
)
# Also configure the pkgconfig file, again outputting to a directory under
# Also configure the pkgconfig files, again outputting to a directory under
# the build directory ready for installation
# Now we use the 'pcfiledir' variable of pkg-config - this tells us the
# directory where clhep.pc is located. Since we know we'll install clhep.pc
......@@ -119,6 +146,18 @@ configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep.pc.in
@ONLY
)
# Now the components
foreach(_lib ${CLHEP_libraries})
set(CLHEP_PC_COMPONENT ${_lib})
string(TOLOWER ${CLHEP_PC_COMPONENT} _pcfilename)
set(CLHEP_PC_COMPONENT_REQUIRES "${CLHEP_PC_${_lib}_REQUIRES}")
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep-component.pc.in
${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep-${_pcfilename}.pc
@ONLY
)
endforeach()
# - Install the config files, and 'install export' the library depends file
# The choice of 'lib/CLHEP-<VERSION>' is based on the recommendations
# in the CMake documentation for find_package on UNIX so that
......@@ -132,7 +171,9 @@ install(FILES
DESTINATION lib${LIB_SUFFIX}/CLHEP-${VERSION}
)
install(EXPORT CLHEPLibraryDepends DESTINATION lib${LIB_SUFFIX}/CLHEP-${VERSION})
install(EXPORT CLHEPLibraryDepends
NAMESPACE "CLHEP::"
DESTINATION lib${LIB_SUFFIX}/CLHEP-${VERSION})
# Install the pkg-config file. The choice of 'lib${LIB_SUFFIX}/pkgconfig' for the
# installation seems fairly standard.
......@@ -140,6 +181,14 @@ install(FILES
${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep.pc
DESTINATION lib${LIB_SUFFIX}/pkgconfig
)
foreach(_lib ${CLHEP_libraries})
string(TOLOWER ${_lib} _pcfilename)
install(FILES
${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep-${_pcfilename}.pc
DESTINATION lib${LIB_SUFFIX}/pkgconfig
)
endforeach()
# - And we should be done...
......
......@@ -4,38 +4,74 @@
# CLHEP_DEFINITIONS - compile definitions needed to use CLHEP
# CLHEP_LIBRARIES - libraries to link against
#
# CLHEP is built concurrently as a single library and as a set of component
# libraries. At present, this config file is only designed to configure
# the single main library in static or shared mode.
# You may supply a version number through find_package which will be checked
# against the version of this build. Standard CMake logic is used so that
# the EXACT flag may be passed, and otherwise this build will report itself
# as compatible with the requested version if:
#
# The following per-component variables are set:
# VERSION_OF_THIS_BUILD >= VERSION_REQUESTED
#
# CLHEP_${COMPONENT}_FOUND True if CLHEP library mode "component"
# was found
# CLHEP is built concurrently as a complete library and as a set of
# component libraries. In each case, shared and static variants are
# always built. By default, this module populates CLHEP_LIBRARIES with
# the single,shared library. Thus
#
# CLHEP_${COMPONENT}_LIBRARY Contains the library for specified mode
# "component"
# find_package(CLHEP)
#
# CLHEP current only supports two components: static and shared, which
# represent the two possible library modes that the main CLHEP library
# is built in.
# include_directories(${CLHEP_INCLUDE_DIRS})
# add_executable(MyProgram ...sources...)
# target_link_libraries(MyProgram ${CLHEP_LIBRARIES})
#
# You can call find_package with 'static' or 'shared' as component arguments
# to pick a particular library mode of CLHEP. For example
# would link 'MyProgram' with the complete, shared CLHEP library
#
# By passing 'COMPONENT' arguments to find_package, you may select between
# static, shared and component libraries. For example, to select linking
# with the complete, static CLHEP library:
#
# find_package(CLHEP REQUIRED static)
#
# will set CLHEP_LIBRARIES to the CLHEP static library.
# This will populate CLHEP_LIBRARIES with the requested static variant.
# To select CLHEP component libraries, pass their names as COMPONENT
# arguments. For example:
#
# find_package(CLHEP REQUIRED Vector Matrix)
#
# would populate CLHEP_LIBRARIES with the shared variants of the Vector
# and Matrix component libraries. Note that CMake will take care of
# any dependencies between components at the linking stage, so you only
# need to list those you wish to use directly. Static component libraries
# may also be selected by using the same `static` component name, so that
#
# find_package(CLHEP REQUIRED static Vector Matrix)
#
# If you do not specify a shared or static component argument, shared
# libraries will be selected by default.
# would populate CLHEP_LIBRARIES with the shared variants of the Vector
# and Matrix component libraries. Note that the order of component
# arguments does not matter, so
#
# find_package(CLHEP REQUIRED Vector static Matrix)
#
# would work just as well. Mixtures of static and shared components are
# not allowed. The complete list of CLHEP component names which may be
# passed is:
#
# Vector CLHEP Vector component library (SHARED)
# Evaluator CLHEP Evaluator component library (SHARED)
# GenericFunctions CLHEP GenericFunctions component library (SHARED)
# Geometry CLHEP Geometry component library (SHARED)
# Random CLHEP Random component library (SHARED)
# Matrix CLHEP Matrix component library (SHARED)
# RandomObjects CLHEP RandomObjects component library (SHARED)
# Cast CLHEP Cast component library (SHARED)
# RefCount CLHEP RefCount component library (SHARED)
# Exceptions CLHEP Exceptions component library (SHARED)
#
# ===========================================================================
# Variables used by this module which can change the default behaviour of
# this module. They need to be set prior to the call to find_package
#
# CLHEP_CONFIG_DEBUG - If set, this will enable some output from this module
# to help in debugging it behaviour
# to help in debugging its behaviour
#
#----------------------------------------------------------------------------
......@@ -86,28 +122,46 @@ set(CLHEP_DEFINITIONS @CLHEP_DEFINITIONS@)
#
include("${_thisdir}/CLHEPLibraryDepends.cmake")
#----------------------------------------------------------------------------
# Whilst the export file lists usable CMake targets, we also create
# standard style _LIBRAR{Y|IES} so usage is transparent. This is also
# useful later if we want to introduce component libraries.
#
set(CLHEP_shared_LIBRARY CLHEP)
set(CLHEP_shared_FOUND 1)
set(CLHEP_static_LIBRARY CLHEPS)
set(CLHEP_static_FOUND 1)
#----------------------------------------------------------------------
# - Handle shared vs static - default to shared if user didn't specify
# This is actually very simple because we always build both!
if(CLHEP_FIND_REQUIRED_shared)
set(CLHEP_LIBRARIES CLHEP)
elseif(CLHEP_FIND_REQUIRED_static)
set(CLHEP_LIBRARIES CLHEPS)
else()
set(CLHEP_LIBRARIES CLHEP)
endif()
set(CLHEP_KNOWN_COMPONENTS "@CLHEP_libraries@")
# Only allow single library variant to be used to populate CLHEP_LIBRARIES
if(DEFINED CLHEP_FIND_REQUIRED_static AND NOT CLHEP_LIBRARIES)
list(REMOVE_ITEM CLHEP_FIND_COMPONENTS static)
set(__clhep_lib_suffix "S")
endif()
foreach(__clhep_component_lib ${CLHEP_KNOWN_COMPONENTS})
if(DEFINED CLHEP_FIND_REQUIRED_${__clhep_component_lib})
list(REMOVE_ITEM CLHEP_FIND_COMPONENTS ${__clhep_component_lib})
list(APPEND CLHEP_LIBRARIES CLHEP::${__clhep_component_lib}${__clhep_lib_suffix})
endif()
endforeach()
# If CLHEP_LIBRARIES is empty at this point, then the complete lib is
# needed
if(NOT CLHEP_LIBRARIES)
set(CLHEP_LIBRARIES CLHEP::CLHEP${__clhep_lib_suffix})
endif()
#-----------------------------------------------------------------------
# Finally, handle any remaining components.
# We should have dealt with all available components above, except for
# ui_all and vis_all, and removed them from the list of FIND_COMPONENTS
# so any left we either didn't find or don't know about. Emit a warning
# if REQUIRED isn't set, or FATAL_ERROR otherwise
#
list(REMOVE_DUPLICATES CLHEP_FIND_COMPONENTS)
foreach(_remaining ${CLHEP_FIND_COMPONENTS})
if(CLHEP_FIND_REQUIRED)
message(FATAL_ERROR "CLHEP component ${_remaining} not found")
elseif(NOT CLHEP_FIND_QUIETLY)
message(WARNING "CLHEP component ${_remaining} not found")
endif()
unset(CLHEP_FIND_REQUIRED_${_remaining})
endforeach()
# And we should be good to go...
# - Relocatable pkgconfig file for CLHEP Component @CLHEP_PC_COMPONENT@
# Generated by CMake : DO NOT EDIT!
#
prefix=@CLHEP_PKGCONFIG_PREFIX@
libdir=@CLHEP_PKGCONFIG_LIBDIR@
includedir=@CLHEP_PKGCONFIG_INCLUDEDIR@
Name: CLHEP-@CLHEP_PC_COMPONENT@
Description: Class Library for High Energy Physics, @CLHEP_PC_COMPONENT@ Component
Version: @CLHEP_VERSION@
Requires: @CLHEP_PC_COMPONENT_REQUIRES@
Libs: -L${libdir} -lCLHEP-@CLHEP_PC_COMPONENT@-@CLHEP_VERSION@
Cflags: -I${includedir}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment