Skip to content

Commit 63aeb64

Browse files
Juan Ramoscharles-lunarg
authored andcommitted
Fix CMake 3.31 builds for WIN32
A recent fix to CMake for ASM static libraries on Windows broke the existing build. Easiest solution I found is to remove the usage of ASM static libraries from the loader. This is already what the UNIX build does. This required using generator expressions to NOT pass along compiler options that aren't needed for assembly files.
1 parent 142b4ed commit 63aeb64

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

CMakeLists.txt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,35 +161,41 @@ option(BUILD_WERROR "Enable warnings as errors")
161161
# Note that clang-cl.exe should use MSVC flavor flags, not GNU
162162
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC"))
163163
if (BUILD_WERROR)
164-
target_compile_options(loader_common_options INTERFACE /WX)
164+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:/WX>)
165165
endif()
166-
target_compile_options(loader_common_options INTERFACE /W4)
166+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:/W4>)
167167
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
168168
# using GCC or Clang with the regular front end
169169
if (BUILD_WERROR)
170-
target_compile_options(loader_common_options INTERFACE -Werror)
170+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:-Werror>)
171171
endif()
172-
target_compile_options(loader_common_options INTERFACE -Wall -Wextra)
172+
target_compile_options(loader_common_options INTERFACE
173+
$<$<COMPILE_LANGUAGE::CXX,C>:-Wall>
174+
$<$<COMPILE_LANGUAGE::CXX,C>:-Wextra>
175+
)
173176
endif()
174177

175178
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
176-
target_compile_options(loader_common_options INTERFACE -Wno-missing-field-initializers)
179+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:-Wno-missing-field-initializers>)
177180

178181
# need to prepend /clang: to compiler arguments when using clang-cl
179182
if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" MATCHES "MSVC")
180-
target_compile_options(loader_common_options INTERFACE /clang:-fno-strict-aliasing)
183+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:/clang:-fno-strict-aliasing>)
181184
else()
182-
target_compile_options(loader_common_options INTERFACE -fno-strict-aliasing)
185+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:-fno-strict-aliasing>)
183186
endif()
184187

185188
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
186-
target_compile_options(loader_common_options INTERFACE -Wno-stringop-truncation -Wno-stringop-overflow)
189+
target_compile_options(loader_common_options INTERFACE
190+
$<$<COMPILE_LANGUAGE::CXX,C>:-Wno-stringop-truncation>
191+
$<$<COMPILE_LANGUAGE::CXX,C>:-Wno-stringop-overflow>
192+
)
187193
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.1)
188-
target_compile_options(loader_common_options INTERFACE -Wshadow=local) #only added in GCC 7
194+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:-Wshadow=local>) #only added in GCC 7
189195
endif()
190196
endif()
191197

192-
target_compile_options(loader_common_options INTERFACE -Wpointer-arith)
198+
target_compile_options(loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>:-Wpointer-arith>)
193199

194200
# Force GLIBC to use the 64 bit interface for file operations instead of 32 bit - More info in issue #1551
195201
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
@@ -203,7 +209,13 @@ if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" A
203209
# /guard:cf: Enable control flow guard
204210
# /wd4152: Disable warning on conversion of a function pointer to a data pointer
205211
# /wd4201: Disable warning on anonymous struct/unions
206-
target_compile_options(loader_common_options INTERFACE /sdl /GR- /guard:cf /wd4152 /wd4201)
212+
target_compile_options(loader_common_options INTERFACE
213+
$<$<COMPILE_LANGUAGE::CXX,C>:/sdl>
214+
$<$<COMPILE_LANGUAGE::CXX,C>:/GR->
215+
$<$<COMPILE_LANGUAGE::CXX,C>:/guard:cf>
216+
$<$<COMPILE_LANGUAGE::CXX,C>:/wd4152>
217+
$<$<COMPILE_LANGUAGE::CXX,C>:/wd4201>
218+
)
207219

208220
# Enable control flow guard
209221
target_link_options(loader_common_options INTERFACE "LINKER:/guard:cf")

loader/CMakeLists.txt

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,11 @@ end
236236
set_target_properties(loader_asm_gen_files PROPERTIES FOLDER ${LOADER_HELPER_FOLDER})
237237

238238
if(SYSTEM_PROCESSOR MATCHES "arm")
239-
add_library(loader-unknown-chain STATIC unknown_ext_chain_marmasm.asm)
239+
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_marmasm.asm)
240240
else()
241-
add_library(loader-unknown-chain STATIC unknown_ext_chain_masm.asm)
241+
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_masm.asm)
242242
endif()
243-
target_include_directories(loader-unknown-chain PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
244-
add_dependencies(loader-unknown-chain loader_asm_gen_files)
245243
set(UNKNOWN_FUNCTIONS_SUPPORTED ON)
246-
247-
# Work around bug in CMake Ninja + MSVC/clang-cl, see https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959
248-
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC"))
249-
if(SYSTEM_PROCESSOR MATCHES "arm")
250-
set(CMAKE_ASM_MARMASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> /OUT:<TARGET> <LINK_FLAGS> <OBJECTS>")
251-
else()
252-
set(CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> /OUT:<TARGET> <LINK_FLAGS> <OBJECTS>")
253-
endif()
254-
endif()
255244
else()
256245
message(WARNING "Could not find working ${} assembler\n${ASM_FAILURE_MSG}")
257246
endif()
@@ -279,17 +268,17 @@ elseif(UNIX OR MINGW OR (WIN32 AND USE_GAS)) # i.e.: Linux & Apple & MinGW & Win
279268
endif()
280269

281270
if(ASSEMBLER_WORKS)
282-
set(OPT_LOADER_SRCS ${OPT_LOADER_SRCS} unknown_ext_chain_gas_aarch.S)
271+
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_gas_aarch.S)
283272
endif()
284273
elseif (${SYSTEM_PROCESSOR} MATCHES "aarch64|arm64")
285274
try_compile(ASSEMBLER_WORKS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/asm_test_aarch64.S OUTPUT_VARIABLE TRY_COMPILE_OUTPUT)
286275
if(ASSEMBLER_WORKS)
287-
set(OPT_LOADER_SRCS ${OPT_LOADER_SRCS} unknown_ext_chain_gas_aarch.S)
276+
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_gas_aarch.S)
288277
endif()
289278
elseif (${SYSTEM_PROCESSOR} MATCHES "aarch32|armhf|armv7l|armv8l")
290279
try_compile(ASSEMBLER_WORKS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/asm_test_aarch32.S OUTPUT_VARIABLE TRY_COMPILE_OUTPUT)
291280
if(ASSEMBLER_WORKS)
292-
set(OPT_LOADER_SRCS ${OPT_LOADER_SRCS} unknown_ext_chain_gas_aarch.S)
281+
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_gas_aarch.S)
293282
endif()
294283
# Covers x86_64, amd64, x86, i386, i686, I386, I686
295284
elseif(${SYSTEM_PROCESSOR} MATCHES "amd64|86")
@@ -300,7 +289,7 @@ elseif(UNIX OR MINGW OR (WIN32 AND USE_GAS)) # i.e.: Linux & Apple & MinGW & Win
300289

301290
try_compile(ASSEMBLER_WORKS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/asm_test_x86.S)
302291
if(ASSEMBLER_WORKS)
303-
set(OPT_LOADER_SRCS ${OPT_LOADER_SRCS} unknown_ext_chain_gas_x86.S)
292+
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_gas_x86.S)
304293
endif()
305294
endif()
306295
endif()
@@ -391,10 +380,6 @@ if(WIN32)
391380

392381
target_link_libraries(vulkan PRIVATE loader_specific_options)
393382

394-
if(UNKNOWN_FUNCTIONS_SUPPORTED AND TARGET loader-unknown-chain)
395-
target_link_libraries(vulkan PRIVATE loader-unknown-chain)
396-
endif()
397-
398383
# when adding the suffix the import and runtime library names must be consistent
399384
# mingw: libvulkan-1.dll.a / vulkan-1.dll
400385
# msvc: vulkan-1.lib / vulkan-1.dll

0 commit comments

Comments
 (0)