Skip to content

Commit 3ad0889

Browse files
committed
Add GYB support for Windows
1 parent 6805ecc commit 3ad0889

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ CMakeFiles
4545
# Ignore compile database
4646
#==============================================================================#
4747
compile_commands.json
48+
49+
# Ignore generated GYB files until we fix the workaround on Windows
50+
#==============================================================================#
51+
8
52+
4
53+
SortedCFDatabase.def

cmake/modules/SwiftAddCustomCommandTarget.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ function(add_custom_command_target dependency_out_var_name)
123123
# CMake doesn't allow '/' characters in filenames, so replace them with '-'
124124
list(GET ACCT_OUTPUT 0 output_filename)
125125
string(REPLACE "${CMAKE_BINARY_DIR}/" "" target_name "${output_filename}")
126+
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" target_name "${target_name}")
126127
string(REPLACE "${CMAKE_CFG_INTDIR}/" "" target_name "${target_name}")
127128
string(REPLACE "/" "-" target_name "${target_name}")
128129
else()

cmake/modules/SwiftHandleGybSources.cmake

+13-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function(handle_gyb_source_single dependency_out_var_name)
5151
COMMAND
5252
"${CMAKE_COMMAND}" -E make_directory "${dir}"
5353
COMMAND
54-
"${gyb_tool}" "${gyb_flags}"
54+
"${PYTHON_EXECUTABLE}" "${gyb_tool}" "${gyb_flags}"
5555
-o "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_SOURCE}"
5656
COMMAND
5757
"${CMAKE_COMMAND}" -E copy_if_different
@@ -113,10 +113,20 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
113113
if(src STREQUAL src_sans_gyb)
114114
list(APPEND de_gybbed_sources "${src}")
115115
else()
116+
117+
# On Windows (using Visual Studio), the generated project files assume that the
118+
# generated GYB files will be in the source, not binary directory.
119+
# We can work around this by modifying the root directory when generating VS projects.
120+
if ("${CMAKE_GENERATOR_PLATFORM}" MATCHES "Visual Studio")
121+
set(dir_root ${CMAKE_CURRENT_SOURCE_DIR})
122+
else()
123+
set(dir_root ${CMAKE_CURRENT_BINARY_DIR})
124+
endif()
125+
116126
if (arch)
117-
set(dir "${CMAKE_CURRENT_BINARY_DIR}/${ptr_size}")
127+
set(dir "${dir_root}/${ptr_size}")
118128
else()
119-
set(dir "${CMAKE_CURRENT_BINARY_DIR}")
129+
set(dir "${dir_root}")
120130
endif()
121131
set(output_file_name "${dir}/${src_sans_gyb}")
122132
list(APPEND de_gybbed_sources "${output_file_name}")

0 commit comments

Comments
 (0)