diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f88bca..c1a36b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,73 +1,93 @@ # Top level CMakeLists.txt for EvtGen # Enforce an out-of-source build. # Should be the first action in the top level CMakeLists.txt if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(STATUS "EvtGen requires an out-of-source build.") message(STATUS "Please remove the following files from ${CMAKE_BINARY_DIR}:") message(STATUS " CMakeCache.txt") message(STATUS " CMakeFiles") message(STATUS "Once these files are removed, create a separate directory") message(STATUS "and run CMake from there, pointing it to:") message(STATUS " ${CMAKE_SOURCE_DIR}") message(FATAL_ERROR "in-source build detected") endif() # Also require a minimum version of CMake cmake_minimum_required(VERSION 3.8.0) # Project setup if(${CMAKE_VERSION} VERSION_LESS 3.9.0) project(EvtGen VERSION 2.0.0 ) elseif(${CMAKE_VERSION} VERSION_LESS 3.12.0) project(EvtGen VERSION 2.0.0 DESCRIPTION "Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons." ) else() project(EvtGen VERSION 2.0.0 DESCRIPTION "Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons." HOMEPAGE_URL "https://evtgen.hepforge.org" ) endif() # Prepend this project's custom module path(s) to CMAKE_MODULE_PATH set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH}) # Include needed modules to perform any custom setup # Install paths include(InstallPaths) # Compilation/linking flags and related settings include(CompilerFlags) # EvtGen external dependencies option(EVTGEN_PYTHIA "Enable/disable linking with Pythia8" OFF) option(EVTGEN_PHOTOS "Enable/disable linking with Photos++" OFF) option(EVTGEN_TAUOLA "Enable/disable linking with Tauola++" OFF) message(STATUS "EvtGen: Linking with Pythia8 ${EVTGEN_PYTHIA}") message(STATUS "EvtGen: Linking with Photos++ ${EVTGEN_PHOTOS}") message(STATUS "EvtGen: Linking with Tauola++ ${EVTGEN_TAUOLA}") include(ExternalDependencies) # Now build the library add_subdirectory(src) # Copy the particle property and decay tables configure_file(DECAY.DEC ${CMAKE_CURRENT_BINARY_DIR}/DECAY.DEC COPYONLY) configure_file(DECAY.XML ${CMAKE_CURRENT_BINARY_DIR}/DECAY.XML COPYONLY) configure_file(evt.pdl ${CMAKE_CURRENT_BINARY_DIR}/evt.pdl COPYONLY) # Build the executables in the test and validation directories add_subdirectory(test) add_subdirectory(validation) # Install the include directories install(DIRECTORY EvtGen DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY EvtGenBase DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY EvtGenExternal DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY EvtGenModels DESTINATION ${CMAKE_INSTALL_PREFIX}) # Install the particle properties and decay tables install(FILES DECAY.DEC DECAY.XML evt.pdl DESTINATION ${CMAKE_INSTALL_PREFIX}) +# Generate CMake config files, which can be used by other projects +include(CMakePackageConfigHelpers) + +set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) +set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) + +configure_package_config_file(cmake/Templates/EvtGenConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/EvtGenConfig.cmake + INSTALL_DESTINATION cmake + PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR + ) + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/EvtGenConfigVersion.cmake + COMPATIBILITY AnyNewerVersion + ) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/EvtGenConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/EvtGenConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake + ) diff --git a/cmake/Templates/EvtGenConfig.cmake.in b/cmake/Templates/EvtGenConfig.cmake.in new file mode 100644 index 0000000..ac7875b --- /dev/null +++ b/cmake/Templates/EvtGenConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +set_and_check(EVTGEN_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(EVTGEN_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") + +check_required_components(EvtGen)