Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/cmake/ActsFunctions.cmake is written in an unsupported language. File is not indexed.

0001 # This function creates a library with Acts namespace support
0002 # It takes the library name without the "Acts" prefix and creates:
0003 # 1. A direct CMake target named "Acts${library_name}"
0004 # 2. An ALIAS target named "Acts::${library_name}"
0005 function(acts_add_library library_name)
0006     set(options "")
0007     set(oneValueArgs ACTS_INCLUDE_FOLDER)
0008     set(multiValueArgs "")
0009     cmake_parse_arguments(
0010         PARSE_ARGV
0011         1
0012         lib_args
0013         "${options}"
0014         "${oneValueArgs}"
0015         "${multiValueArgs}"
0016     )
0017 
0018     set(full_target_name "Acts${library_name}")
0019 
0020     # Forward all arguments except the first (library_name) to add_library
0021     add_library(${full_target_name} ${lib_args_UNPARSED_ARGUMENTS})
0022 
0023     # Create alias target with Acts:: namespace
0024     add_library(Acts::${library_name} ALIAS ${full_target_name})
0025 
0026     set_target_properties(
0027         ${full_target_name}
0028         PROPERTIES EXPORT_NAME Acts::${library_name}
0029     )
0030 
0031     install(
0032         TARGETS ${full_target_name}
0033         EXPORT ${full_target_name}Targets
0034         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
0035         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
0036     )
0037 
0038     if(lib_args_ACTS_INCLUDE_FOLDER)
0039         install(
0040             DIRECTORY ${lib_args_ACTS_INCLUDE_FOLDER}
0041             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
0042         )
0043     endif()
0044 endfunction()
0045 
0046 # This function adds a helper target called ${target}_HEADERS which has
0047 # generated source files that include each hedaer that was given one-by-one.
0048 # The generated target links against the one given in `target` and therefore
0049 # has access to all includes.
0050 # The generated target is not included in the default build, and is only meant
0051 # to help tools like clangd discover compiler flags.
0052 function(acts_compile_headers target)
0053     set(options "")
0054     set(oneValueArgs GLOB)
0055     set(multiValueArgs "")
0056     cmake_parse_arguments(
0057         PARSE_ARGV
0058         0
0059         ARGS
0060         "${options}"
0061         "${oneValueArgs}"
0062         "${multiValueArgs}"
0063     )
0064 
0065     if(NOT ACTS_COMPILE_HEADERS)
0066         return()
0067     endif()
0068 
0069     if(NOT "${ARGS_GLOB}" STREQUAL "")
0070         if(NOT "${_headers}" STREQUAL "")
0071             message(SEND_ERROR "Cannot use HEADERS and GLOB at the same time")
0072             return()
0073         endif()
0074 
0075         file(
0076             GLOB_RECURSE _headers
0077             RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
0078             ${ARGS_GLOB}
0079         )
0080     endif()
0081 
0082     if("${_headers}" STREQUAL "")
0083         message(SEND_ERROR "No headers specified")
0084         return()
0085     endif()
0086 
0087     set(_sources "")
0088 
0089     foreach(_file ${_headers})
0090         if(IS_ABSOLUTE "${_file}")
0091             message(SEND_ERROR "Absolute paths are not allowed: ${_file}")
0092             continue()
0093         endif()
0094 
0095         set(_header_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
0096 
0097         if(NOT EXISTS "${_header_file}")
0098             message(SEND_ERROR "File not found: ${_header_file}")
0099         endif()
0100         if(IS_DIRECTORY "${_header_file}")
0101             message(SEND_ERROR "Path is a directory: ${_header_file}")
0102         endif()
0103 
0104         get_filename_component(_header_file_name "${_file}" NAME_WLE)
0105         get_filename_component(_header_directory "${_file}" DIRECTORY)
0106 
0107         set(_temporary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_header_directory}")
0108 
0109         file(MAKE_DIRECTORY "${_temporary_dir}")
0110 
0111         set(_temporary_path "${_temporary_dir}/${_header_file_name}.cpp")
0112 
0113         file(WRITE "${_temporary_path}" "#include \"${_header_file}\"")
0114 
0115         list(APPEND _sources "${_temporary_path}")
0116     endforeach()
0117 
0118     add_library(Acts${target}_HEADERS SHARED EXCLUDE_FROM_ALL ${_sources})
0119     target_link_libraries(Acts${target}_HEADERS PRIVATE Acts::${target})
0120 endfunction()