Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: fix pre-compiled header files for MSVC/Ninja #3204

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmake/defaults/msvcdefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ set(_PXR_CXX_FLAGS "${_PXR_CXX_FLAGS} /Gm-")
# with no symbols in it. We do this a lot because of a pattern of having
# a C++ source file for many header-only facilities, e.g. tf/bitUtils.cpp.
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")

# Enforce synchronous PDB writes when using Ninja
# (this prevents "permission denied" compile errors on program databases)
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set(_PXR_CXX_FLAGS "${_PXR_CXX_FLAGS} /FS")
endif()
18 changes: 10 additions & 8 deletions cmake/macros/Private.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ function(_pxr_enable_precompiled_header TARGET_NAME)
# Headers live in subdirectories.
set(rel_output_header_path "${PXR_PREFIX}/${TARGET_NAME}/${output_header_name}")
set(abs_output_header_path "${PROJECT_BINARY_DIR}/include/${rel_output_header_path}")
set(abs_precompiled_path ${PROJECT_BINARY_DIR}/include/${PXR_PREFIX}/${TARGET_NAME}/${CMAKE_BUILD_TYPE}/${precompiled_name})
set(abs_precompiled_container_path "${PROJECT_BINARY_DIR}/include/${PXR_PREFIX}/${TARGET_NAME}/${CMAKE_BUILD_TYPE}")
set(abs_precompiled_path "${abs_precompiled_container_path}/${precompiled_name}")

# Additional compile flags to use precompiled header. This will be
set(compile_flags "")
Expand Down Expand Up @@ -555,22 +556,23 @@ function(_pxr_enable_precompiled_header TARGET_NAME)
set(abs_output_source_path ${CMAKE_CURRENT_BINARY_DIR}/${output_header_name_we}.cpp)
add_custom_command(
OUTPUT "${abs_output_source_path}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_precompiled_container_path}"
COMMAND ${CMAKE_COMMAND} -E touch ${abs_output_source_path}
)

# The trigger file gets a special compile flag (/Yc).
set_source_files_properties(${abs_output_source_path} PROPERTIES
COMPILE_FLAGS "/Yc\"${rel_output_header_path}\" /FI\"${rel_output_header_path}\" /Fp\"${abs_precompiled_path}\""
OBJECT_OUTPUTS "${abs_precompiled_path}"
OBJECT_DEPENDS "${abs_output_header_path}"
)

# Add the header file to the target.
target_sources(${TARGET_NAME} PRIVATE "${abs_output_header_path}")

# Add the trigger file to the target.
target_sources(${TARGET_NAME} PRIVATE "${abs_output_source_path}")

# The trigger file gets a special compile flag (/Yc).
set_source_files_properties(${abs_output_source_path} PROPERTIES
COMPILE_FLAGS "/Yc\"${rel_output_header_path}\" /FI\"${rel_output_header_path}\" /Fp\"${abs_precompiled_path}\""
OBJECT_OUTPUTS "${abs_precompiled_path}"
OBJECT_DEPENDS "${abs_output_header_path}"
)

# Exclude the trigger.
list(APPEND pch_EXCLUDE ${abs_output_source_path})
else()
Expand Down