Warning, /acts/cmake/ActsFunctions.cmake is written in an unsupported language. File is not indexed.
0001 # This function adds a helper target called ${target}_HEADERS which has
0002 # generated source files that include each hedaer that was given one-by-one.
0003 # The generated target links against the one given in `target` and therefore
0004 # has access to all includes.
0005 # The generated target is not included in the default build, and is only meant
0006 # to help tools like clangd discover compiler flags.
0007 function(acts_compile_headers target)
0008 set(options "")
0009 set(oneValueArgs GLOB)
0010 set(multiValueArgs "")
0011 cmake_parse_arguments(
0012 PARSE_ARGV
0013 0
0014 ARGS
0015 "${options}"
0016 "${oneValueArgs}"
0017 "${multiValueArgs}"
0018 )
0019
0020 if(NOT ACTS_COMPILE_HEADERS)
0021 return()
0022 endif()
0023
0024 if(NOT "${ARGS_GLOB}" STREQUAL "")
0025 if(NOT "${_headers}" STREQUAL "")
0026 message(SEND_ERROR "Cannot use HEADERS and GLOB at the same time")
0027 return()
0028 endif()
0029
0030 file(
0031 GLOB_RECURSE _headers
0032 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
0033 ${ARGS_GLOB}
0034 )
0035 endif()
0036
0037 if("${_headers}" STREQUAL "")
0038 message(SEND_ERROR "No headers specified")
0039 return()
0040 endif()
0041
0042 set(_sources "")
0043
0044 foreach(_file ${_headers})
0045 if(IS_ABSOLUTE "${_file}")
0046 message(SEND_ERROR "Absolute paths are not allowed: ${_file}")
0047 continue()
0048 endif()
0049
0050 set(_header_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
0051
0052 if(NOT EXISTS "${_header_file}")
0053 message(SEND_ERROR "File not found: ${_header_file}")
0054 endif()
0055 if(IS_DIRECTORY "${_header_file}")
0056 message(SEND_ERROR "Path is a directory: ${_header_file}")
0057 endif()
0058
0059 get_filename_component(_header_file_name "${_file}" NAME_WLE)
0060 get_filename_component(_header_directory "${_file}" DIRECTORY)
0061
0062 set(_temporary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_header_directory}")
0063
0064 file(MAKE_DIRECTORY "${_temporary_dir}")
0065
0066 set(_temporary_path "${_temporary_dir}/${_header_file_name}.cpp")
0067
0068 file(WRITE "${_temporary_path}" "#include \"${_header_file}\"")
0069
0070 list(APPEND _sources "${_temporary_path}")
0071 endforeach()
0072
0073 add_library(${target}_HEADERS SHARED EXCLUDE_FROM_ALL ${_sources})
0074 target_link_libraries(${target}_HEADERS PRIVATE ${target})
0075 endfunction()