Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/Traccc/cmake/traccc-functions.cmake is written in an unsupported language. File is not indexed.

0001 # TRACCC library, part of the ACTS project (R&D line)
0002 #
0003 # (c) 2021-2023 CERN for the benefit of the ACTS project
0004 #
0005 # Mozilla Public License Version 2.0
0006 
0007 # DISCOVERY_TIMEOUT in gtest_discover_tests(...) requires at least CMake 3.10.
0008 cmake_minimum_required(VERSION 3.10)
0009 
0010 # Guard against multiple includes.
0011 include_guard(GLOBAL)
0012 
0013 # CMake include(s).
0014 include(CMakeParseArguments)
0015 include(GoogleTest)
0016 
0017 # Function for declaring the libraries of the project
0018 #
0019 # Usage: traccc_add_library( traccc_core core
0020 #                            [TYPE SHARED/INTERFACE/STATIC]
0021 #                            include/source1.hpp source2.cpp )
0022 #
0023 function(traccc_add_library fullname basename)
0024     # Parse the function's options.
0025     cmake_parse_arguments(ARG "" "TYPE" "" ${ARGN})
0026 
0027     # Decide what sources to give to the library.
0028     set(_sources ${ARG_UNPARSED_ARGUMENTS})
0029     if("${ARG_TYPE}" STREQUAL "INTERFACE")
0030         set(_sources)
0031     endif()
0032 
0033     # Create the library.
0034     add_library(${fullname} ${ARG_TYPE} ${_sources})
0035 
0036     # Set up how clients should find its headers.
0037     if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/")
0038         set(_depType PUBLIC)
0039         if("${ARG_TYPE}" STREQUAL "INTERFACE")
0040             set(_depType INTERFACE)
0041         endif()
0042         target_include_directories(
0043             ${fullname}
0044             ${_depType}
0045             $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
0046             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
0047         )
0048         unset(_depType)
0049     endif()
0050 
0051     # Make sure that the library is available as "traccc::${basename}" in every
0052     # situation.
0053     set_target_properties(${fullname} PROPERTIES EXPORT_NAME ${basename})
0054     add_library(traccc::${basename} ALIAS ${fullname})
0055 
0056     # Specify the (SO)VERSION of the library.
0057     if(NOT "${ARG_TYPE}" STREQUAL "INTERFACE")
0058         set_target_properties(
0059             ${fullname}
0060             PROPERTIES
0061                 VERSION ${PROJECT_VERSION}
0062                 SOVERSION ${PROJECT_VERSION_MAJOR}
0063         )
0064     endif()
0065 
0066     # Set up the installation of the library and its headers.
0067     install(
0068         TARGETS ${fullname}
0069         EXPORT traccc-exports
0070         LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
0071         ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
0072         RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
0073     )
0074     if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/")
0075         install(
0076             DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
0077             DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
0078         )
0079     endif()
0080 endfunction(traccc_add_library)
0081 
0082 # Function for declaring the (installable) executables of the project
0083 #
0084 # Usage: traccc_add_executable( super_exe super_source.cpp )
0085 #
0086 function(traccc_add_executable name)
0087     # Parse the function's options.
0088     cmake_parse_arguments(ARG "" "" "LINK_LIBRARIES" ${ARGN})
0089 
0090     # Set up the executable.
0091     set(exe_name "traccc_${name}")
0092     add_executable(${exe_name} ${ARG_UNPARSED_ARGUMENTS})
0093     if(ARG_LINK_LIBRARIES)
0094         target_link_libraries(${exe_name} PRIVATE ${ARG_LINK_LIBRARIES})
0095     endif()
0096 
0097     # Make sure that the executable is available as "traccc::${name}" in every
0098     # situation.
0099     set_target_properties(${exe_name} PROPERTIES EXPORT_NAME ${name})
0100     add_executable(traccc::${name} ALIAS ${exe_name})
0101 
0102     # Set up the installation of the executable.
0103     install(
0104         TARGETS ${exe_name}
0105         EXPORT traccc-exports
0106         RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
0107     )
0108 endfunction(traccc_add_executable)
0109 
0110 # Helper function for setting up the traccc tests.
0111 #
0112 # Usage: traccc_add_test( core_containers source1.cpp source2.cpp
0113 #                         LINK_LIBRARIES traccc::core )
0114 #
0115 function(traccc_add_test name)
0116     # Parse the function's options.
0117     cmake_parse_arguments(ARG "" "" "LINK_LIBRARIES" ${ARGN})
0118 
0119     # Create the test executable.
0120     set(test_exe_name "traccc_test_${name}")
0121     add_executable(${test_exe_name} ${ARG_UNPARSED_ARGUMENTS})
0122     if(ARG_LINK_LIBRARIES)
0123         target_link_libraries(${test_exe_name} PRIVATE ${ARG_LINK_LIBRARIES})
0124     endif()
0125 
0126     # Discover all of the tests from the execuable, and set them up as individual
0127     # CTest tests. All the while ensuring that they would find their data files.
0128     gtest_discover_tests(
0129         ${test_exe_name}
0130         PROPERTIES ENVIRONMENT TRACCC_TEST_DATA_DIR=${PROJECT_SOURCE_DIR}/data
0131         DISCOVERY_TIMEOUT 20
0132     )
0133 endfunction(traccc_add_test)
0134 
0135 # Helper function for adding individual flags to "flag variables".
0136 #
0137 # Usage: traccc_add_flag( CMAKE_CXX_FLAGS "-Wall" )
0138 #
0139 function(traccc_add_flag name value)
0140     # Escape special characters in the value:
0141     set(matchedValue "${value}")
0142     foreach(
0143         c
0144         "*"
0145         "."
0146         "^"
0147         "$"
0148         "+"
0149         "?"
0150     )
0151         string(REPLACE "${c}" "\\${c}" matchedValue "${matchedValue}")
0152     endforeach()
0153 
0154     # Check if the variable already has this value in it:
0155     if("${${name}}" MATCHES "${matchedValue}")
0156         return()
0157     endif()
0158 
0159     # If not, then let's add it now:
0160     set(${name} "${${name}} ${value}" PARENT_SCOPE)
0161 endfunction(traccc_add_flag)