0ad/cmake/PrecompiledHeader.cmake
Cayleb-Ordo 2d54b6cf23 Add CMake Configuration for ActorEditor
Name the project AtlasMisc as the atlas Object is shared.
Use the `target_sources` to add sources based on their targets.

Not working:
- Linking to wxWidgets find_package target
  - Terrain.obj : `error LNK2019: Verweis auf nicht aufgel├Âstes externes Symbol ""int const wxEVT_NULL" (?wxEVT_NULL@@3HB)" in Funktion ""void __cdecl dynamic initializer for 'private: static struct wxEventTableEntry const * const TerrainSidebar::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@TerrainSidebar@@0QBUwxEventTableEntry@@B@@YAXXZ)".`

Working:
- Using find_package extra variables to find most of the windows ext. libs
- excluding SDL2 and Boost, which use the custom find_prebuild_library function
2026-05-24 12:30:32 +02:00

42 lines
1.5 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}")
# 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()
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()