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 1
0011 lib_args
0012 "${options}"
0013 "${oneValueArgs}"
0014 "${multiValueArgs}"
0015 )
0016
0017 set(full_target_name "Acts${library_name}")
0018
0019 # Forward all arguments except the first (library_name) to add_library
0020 add_library(${full_target_name} ${lib_args_UNPARSED_ARGUMENTS})
0021
0022 # Create alias target with Acts:: namespace
0023 add_library(Acts::${library_name} ALIAS ${full_target_name})
0024
0025 set_target_properties(
0026 ${full_target_name}
0027 PROPERTIES EXPORT_NAME Acts::${library_name}
0028 )
0029
0030 install(
0031 TARGETS ${full_target_name}
0032 EXPORT ${full_target_name}Targets
0033 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
0034 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
0035 )
0036
0037 if(lib_args_ACTS_INCLUDE_FOLDER)
0038 install(
0039 DIRECTORY ${lib_args_ACTS_INCLUDE_FOLDER}
0040 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
0041 )
0042 endif()
0043 endfunction()
0044
0045 # This function adds a helper target called Acts${target}_HEADERS which has
0046 # generated source files that include each hedaer that was given one-by-one.
0047 # The generated target links against the one given in `target` and therefore
0048 # has access to all includes.
0049 # The generated target is not included in the default build, and is only meant
0050 # to help tools like clangd discover compiler flags.
0051 #
0052 # By default the helper target is named `Acts${target}_HEADERS` and links
0053 # against `Acts::${target}`. Projects that do not follow the Acts naming
0054 # convention (e.g. the in-tree detray) can override both with `NAME` and
0055 # `LINK`:
0056 #
0057 # acts_compile_headers(
0058 # core
0059 # NAME detray_core_HEADERS
0060 # LINK detray::core_array
0061 # GLOB include/detray/**/*.hpp
0062 # )
0063 function(acts_compile_headers target)
0064 set(options "")
0065 set(oneValueArgs NAME LINK)
0066 set(multiValueArgs GLOB)
0067 cmake_parse_arguments(
0068 PARSE_ARGV 0
0069 ARGS
0070 "${options}"
0071 "${oneValueArgs}"
0072 "${multiValueArgs}"
0073 )
0074
0075 if(NOT ACTS_COMPILE_HEADERS)
0076 return()
0077 endif()
0078
0079 if(NOT ARGS_NAME)
0080 set(ARGS_NAME "Acts${target}_HEADERS")
0081 endif()
0082 if(NOT ARGS_LINK)
0083 set(ARGS_LINK "Acts::${target}")
0084 endif()
0085
0086 if(NOT "${ARGS_GLOB}" STREQUAL "")
0087 if(NOT "${_headers}" STREQUAL "")
0088 message(SEND_ERROR "Cannot use HEADERS and GLOB at the same time")
0089 return()
0090 endif()
0091
0092 file(
0093 GLOB_RECURSE _headers
0094 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
0095 ${ARGS_GLOB}
0096 )
0097 endif()
0098
0099 if("${_headers}" STREQUAL "")
0100 message(SEND_ERROR "No headers specified")
0101 return()
0102 endif()
0103
0104 set(_sources "")
0105
0106 foreach(_file ${_headers})
0107 if(IS_ABSOLUTE "${_file}")
0108 message(SEND_ERROR "Absolute paths are not allowed: ${_file}")
0109 continue()
0110 endif()
0111
0112 set(_header_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
0113
0114 if(NOT EXISTS "${_header_file}")
0115 message(SEND_ERROR "File not found: ${_header_file}")
0116 endif()
0117 if(IS_DIRECTORY "${_header_file}")
0118 message(SEND_ERROR "Path is a directory: ${_header_file}")
0119 endif()
0120
0121 get_filename_component(_header_file_name "${_file}" NAME)
0122 get_filename_component(_header_directory "${_file}" DIRECTORY)
0123
0124 set(_temporary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_header_directory}")
0125
0126 file(MAKE_DIRECTORY "${_temporary_dir}")
0127
0128 set(_temporary_path "${_temporary_dir}/${_header_file_name}.cpp")
0129
0130 file(WRITE "${_temporary_path}" "#include \"${_header_file}\"")
0131
0132 list(APPEND _sources "${_temporary_path}")
0133 endforeach()
0134
0135 if(NOT TARGET ${ARGS_NAME})
0136 add_library(${ARGS_NAME} SHARED EXCLUDE_FROM_ALL ${_sources})
0137 target_link_libraries(${ARGS_NAME} PRIVATE ${ARGS_LINK})
0138 else()
0139 target_sources(${ARGS_NAME} PRIVATE ${_sources})
0140 endif()
0141 endfunction()