mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
59 lines
2 KiB
CMake
59 lines
2 KiB
CMake
function(precompile_header _target _header _source)
|
|
set(single_args FORCE_INCLUDE)
|
|
cmake_parse_arguments(args "" "${single_args}" "" ${ARGN})
|
|
|
|
get_target_property(target_compiler_FLAGS ${_target} COMPILE_OPTIONS)
|
|
get_target_property(target_bindir ${_target} BINARY_DIR)
|
|
set(gcc_out ${target_bindir}/${_header}.gch)
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
|
message(STATUS "Precompiled: ${_target} ${_header} ${_source}")
|
|
# message(STATUS "Precompiled: ${_target} ${_header} ${_source}")
|
|
# target_compile_options(${_target}
|
|
# PRIVATE
|
|
# /Yu${_header}
|
|
# )
|
|
# set_source_files_properties(${_source}/precompiled.cpp PROPERTIES
|
|
# COMPILE_FLAGS
|
|
# /Yc${_header}
|
|
# )
|
|
# if(${args_FORCE_INCLUDE})
|
|
# set_source_files_properties(${_source}/precompiled.cpp
|
|
# PROPERTIES
|
|
# COMPILE_FLAGS
|
|
# /FI${_header}
|
|
# )
|
|
# endif()
|
|
# get_source_file_property(tmp ${_source}/precompiled.cpp COMPILE_FLAGS)
|
|
# message(STATUS "Property: ${tmp}")
|
|
# include(CMakePrintHelpers)
|
|
# cmake_print_properties(TARGETS ${_target}
|
|
# PROPERTIES
|
|
# # INCLUDE_DIRECTORIES
|
|
# # LINK_LIBRARIES
|
|
# COMPILE_OPTIONS
|
|
# # COMPILE_DEFINITIONS
|
|
# # WIN32_EXECUTABLE
|
|
# # MACOSX_BUNDLE
|
|
# # IMPORTED_LOCATION
|
|
# # INTERFACE_INCLUDE_DIRECTORIES
|
|
# # CXX_EXTENSIONS
|
|
# # CXX_STANDARD_REQUIRED
|
|
# )
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|AppleClang")
|
|
message(STATUS "C++")
|
|
add_custom_command(
|
|
OUTPUT "${gcc_out}"
|
|
COMMAND ${CMAKE_CXX_COMPILER} "${target_compiler_FLAGS}" -x c++-header -o "${gcc_out}" -c "${_header}"
|
|
DEPENDS "${_header}"
|
|
COMMENT "Precompiling ${_header} for ${_target} (C++)"
|
|
)
|
|
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU|AppleClang")
|
|
message(STATUS "C")
|
|
add_custom_command(
|
|
OUTPUT "${gcc_out}"
|
|
COMMAND ${CMAKE_C_COMPILER} "${target_compiler_FLAGS}" -x c-header -o "${gcc_out}" -c "${_header}"
|
|
DEPENDS "${_header}"
|
|
COMMENT "Precompiling ${_header} for ${_target} (C)"
|
|
)
|
|
endif()
|
|
endfunction()
|