Skip to content

Commit a0fe920

Browse files
authored
Minor CMake code review (#635)
1 parent 9efce61 commit a0fe920

3 files changed

Lines changed: 39 additions & 58 deletions

File tree

CMakeLists.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,16 @@ set(SHADER_SOURCES
164164
Src/Shaders/ToneMap.fx)
165165

166166
# These source files are identical in both DX11 and DX12 version.
167-
set(LIBRARY_HEADERS ${LIBRARY_HEADERS}
167+
list(APPEND LIBRARY_HEADERS
168168
Inc/SimpleMath.h
169169
Inc/SimpleMath.inl)
170170

171-
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
171+
list(APPEND LIBRARY_SOURCES
172172
Src/BinaryReader.cpp
173173
Src/Geometry.cpp
174174
Src/SimpleMath.cpp)
175175

176-
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
176+
list(APPEND LIBRARY_SOURCES
177177
Src/AlignedNew.h
178178
Src/Bezier.h
179179
Src/BinaryReader.h
@@ -187,7 +187,7 @@ set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
187187
Src/vbo.h
188188
Src/TeapotData.inc)
189189

190-
set(SHADER_SOURCES ${SHADER_SOURCES}
190+
list(APPEND SHADER_SOURCES
191191
Src/Shaders/Common.fxh
192192
Src/Shaders/Lighting.fxh
193193
Src/Shaders/PBRCommon.fxh
@@ -198,30 +198,30 @@ set(SHADER_SOURCES ${SHADER_SOURCES}
198198

199199
# Xbox-specific extensions
200200
if(DEFINED XBOX_CONSOLE_TARGET)
201-
set(LIBRARY_HEADERS ${LIBRARY_HEADERS}
201+
list(APPEND LIBRARY_HEADERS
202202
Inc/XboxDDSTextureLoader.h)
203203

204-
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
204+
list(APPEND LIBRARY_SOURCES
205205
Src/XboxDDSTextureLoader.cpp)
206206
endif()
207207

208208
if(BUILD_XINPUT OR BUILD_WGI OR BUILD_GAMEINPUT)
209-
set(LIBRARY_HEADERS ${LIBRARY_HEADERS}
209+
list(APPEND LIBRARY_HEADERS
210210
Inc/GamePad.h
211211
Inc/Keyboard.h
212212
Inc/Mouse.h)
213213

214-
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
214+
list(APPEND LIBRARY_SOURCES
215215
Src/GamePad.cpp
216216
Src/Keyboard.cpp
217217
Src/Mouse.cpp)
218218
endif()
219219

220220
if(BUILD_XAUDIO_WIN10 OR BUILD_XAUDIO_WIN8 OR BUILD_XAUDIO_REDIST)
221-
set(LIBRARY_HEADERS ${LIBRARY_HEADERS}
221+
list(APPEND LIBRARY_HEADERS
222222
Inc/Audio.h)
223223

224-
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
224+
list(APPEND LIBRARY_SOURCES
225225
Audio/AudioEngine.cpp
226226
Audio/DynamicSoundEffectInstance.cpp
227227
Audio/SoundCommon.cpp
@@ -246,8 +246,7 @@ else()
246246
file(TO_CMAKE_PATH ${COMPILED_SHADERS} COMPILED_SHADERS)
247247
endif()
248248

249-
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
250-
${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc)
249+
list(APPEND LIBRARY_SOURCES ${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc)
251250

252251
if(BUILD_XBOXONE_SHADERS)
253252
message(STATUS "Using Shader Model 5.0 for Xbox One for shaders")
@@ -264,7 +263,9 @@ if(NOT USE_PREBUILT_SHADERS)
264263
HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}"
265264
"C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}.0/${DIRECTX_HOST_ARCH}"
266265
"C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}")
267-
message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}")
266+
if(DIRECTX_FXC_TOOL)
267+
message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}")
268+
endif()
268269
endif()
269270
add_custom_command(
270271
OUTPUT "${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc"
@@ -312,8 +313,9 @@ source_group(Inc REGULAR_EXPRESSION Inc/*.*)
312313
source_group(Src REGULAR_EXPRESSION Src/*.*)
313314

314315
target_include_directories(${PROJECT_NAME} PUBLIC
315-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Inc>
316-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/directxtk>)
316+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Inc>)
317+
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE
318+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/directxtk>)
317319

318320
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
319321

@@ -330,7 +332,9 @@ endif()
330332

331333
if(directxmath_FOUND)
332334
message(STATUS "Using DirectXMath package")
333-
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXMath)
335+
if(NOT MINGW)
336+
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXMath)
337+
endif()
334338
endif()
335339

336340
if(BUILD_XAUDIO_REDIST AND (NOT BUILD_XAUDIO_WIN10) AND (NOT BUILD_XAUDIO_WIN8))
@@ -397,10 +401,9 @@ install(FILES
397401
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
398402

399403
# Create pkg-config file
400-
include(build/JoinPaths.cmake)
401404
# from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files
402-
join_paths(DIRECTXTK_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
403-
join_paths(DIRECTXTK_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
405+
cmake_path(APPEND DIRECTXTK_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
406+
cmake_path(APPEND DIRECTXTK_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
404407

405408
set(DIRECTXTK_DEP_L "")
406409
if(directxmath_FOUND)
@@ -420,6 +423,8 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectXTK.pc"
420423
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
421424

422425
#--- Command-line tools
426+
set(TOOL_EXES "")
427+
423428
if(BUILD_TOOLS AND WIN32)
424429
set(TOOL_EXES xwbtool)
425430

@@ -490,8 +495,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
490495
target_compile_options(${t} PRIVATE "-Wno-attributes")
491496
endif()
492497
endforeach()
493-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
494-
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
495498
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
496499
if(BUILD_SHARED_LIBS)
497500
target_compile_options(${PROJECT_NAME} PRIVATE /wd4251 /wd4275)
@@ -533,6 +536,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
533536
endforeach()
534537

535538
if(BUILD_FUZZING AND (NOT WINDOWS_STORE))
539+
# Prevent fuzzing builds (which is otherwise configured as a Release mode) from disabling assertions
536540
string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
537541
string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
538542

@@ -573,7 +577,7 @@ if(WIN32)
573577
endif()
574578
endif()
575579

576-
if(BUILD_TOOLS AND WIN32)
580+
if(BUILD_TOOLS AND WIN32 AND (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR))
577581
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT xwbtool)
578582
endif()
579583

CMakePresets.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@
253253
"hidden": true
254254
},
255255

256-
{ "name": "x64-Debug" , "description": "MSVC for x64 (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "MSVC" ] },
257-
{ "name": "x64-Release" , "description": "MSVC for x64 (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "MSVC" ] },
258-
{ "name": "x86-Debug" , "description": "MSVC for x86 (Debug) for Windows 8", "inherits": [ "base", "x86", "Debug", "MSVC" ] },
259-
{ "name": "x86-Release" , "description": "MSVC for x86 (Release) for Windows 8", "inherits": [ "base", "x86", "Release", "MSVC" ] },
256+
{ "name": "x64-Debug" , "description": "MSVC for x64 (Debug) for Windows 8.1", "inherits": [ "base", "x64", "Debug", "MSVC" ] },
257+
{ "name": "x64-Release" , "description": "MSVC for x64 (Release) for Windows 8.1", "inherits": [ "base", "x64", "Release", "MSVC" ] },
258+
{ "name": "x86-Debug" , "description": "MSVC for x86 (Debug) for Windows 8.1", "inherits": [ "base", "x86", "Debug", "MSVC" ] },
259+
{ "name": "x86-Release" , "description": "MSVC for x86 (Release) for Windows 8.1", "inherits": [ "base", "x86", "Release", "MSVC" ] },
260260

261261
{ "name": "x64-Debug-Win10" , "description": "MSVC for x64 (Debug) for Windows 10", "inherits": [ "base", "x64", "Debug", "MSVC", "Win10" ] },
262262
{ "name": "x64-Release-Win10" , "description": "MSVC for x64 (Release) for Windows 10", "inherits": [ "base", "x64", "Release", "MSVC", "Win10" ] },
@@ -303,10 +303,10 @@
303303
{ "name": "arm64ec-Debug-VCPKG" , "description": "MSVC for ARM64EC (Debug) using VCPKG", "inherits": [ "base", "ARM64EC", "Debug", "MSVC", "VCPKG", "Win10" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } },
304304
{ "name": "arm64ec-Release-VCPKG", "description": "MSVC for ARM64EC (Release) using VCPKG", "inherits": [ "base", "ARM64EC", "Release", "MSVC", "VCPKG", "Win10" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } },
305305

306-
{ "name": "x64-Debug-Clang" , "description": "Clang/LLVM for x64 (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "Clang" ] },
307-
{ "name": "x64-Release-Clang" , "description": "Clang/LLVM for x64 (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "Clang" ] },
308-
{ "name": "x86-Debug-Clang" , "description": "Clang/LLVM for x86 (Debug) for Windows 8", "inherits": [ "base", "x86", "Debug", "Clang", "Clang-X86" ] },
309-
{ "name": "x86-Release-Clang" , "description": "Clang/LLVM for x86 (Release) for Windows 8", "inherits": [ "base", "x86", "Release", "Clang", "Clang-X86" ] },
306+
{ "name": "x64-Debug-Clang" , "description": "Clang/LLVM for x64 (Debug) for Windows 8.1", "inherits": [ "base", "x64", "Debug", "Clang" ] },
307+
{ "name": "x64-Release-Clang" , "description": "Clang/LLVM for x64 (Release) for Windows 8.1", "inherits": [ "base", "x64", "Release", "Clang" ] },
308+
{ "name": "x86-Debug-Clang" , "description": "Clang/LLVM for x86 (Debug) for Windows 8.1", "inherits": [ "base", "x86", "Debug", "Clang", "Clang-X86" ] },
309+
{ "name": "x86-Release-Clang" , "description": "Clang/LLVM for x86 (Release) for Windows 8.1", "inherits": [ "base", "x86", "Release", "Clang", "Clang-X86" ] },
310310

311311
{ "name": "x64-Debug-Win10-Clang" , "description": "Clang/LLVM for x64 (Debug) for Windows 10", "inherits": [ "base", "x64", "Debug", "Clang", "Win10" ] },
312312
{ "name": "x64-Release-Win10-Clang" , "description": "Clang/LLVM for x64 (Release) for Windows 10", "inherits": [ "base", "x64", "Release", "Clang", "Win10" ] },
@@ -344,13 +344,13 @@
344344
{ "name": "x64-Debug-MinGW-GI" , "description": "MinG-W64 (Debug) using GameInput", "inherits": [ "base", "x64", "Debug", "GNUC", "VCPKG", "XAudio2Redist", "MinGW64" ], "cacheVariables": { "BUILD_GAMEINPUT": "true" } },
345345
{ "name": "x64-Release-MinGW-GI", "description": "MinG-W64 (Release) using GameInput", "inherits": [ "base", "x64", "Release", "GNUC", "VCPKG", "XAudio2Redist", "MinGW64" ], "cacheVariables": { "BUILD_GAMEINPUT": "true" } },
346346

347-
{ "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "Intel" ] },
348-
{ "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "Intel" ] },
347+
{ "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) for Windows 8.1", "inherits": [ "base", "x64", "Debug", "Intel" ] },
348+
{ "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) for Windows 8.1", "inherits": [ "base", "x64", "Release", "Intel" ] },
349349

350-
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
351-
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },
350+
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) for Windows 8.1", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
351+
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) for Windows 8.1", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },
352352

353-
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) for Windows 8 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC", "Analyze" ] },
353+
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) for Windows 8.1 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC", "Analyze" ] },
354354
{ "name": "x64-Analyze-Win10" , "description": "MSVC for x64 (Debug) for Windows 10 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC", "Win10", "Analyze" ] },
355355
{ "name": "x64-Coverage" , "description": "MSVC for x64 (Debug) w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "MSVC", "Coverage" ] },
356356
{ "name": "x64-Coverage-Clang", "description": "Clang/LLVM for x64 (Debug) w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "Clang", "Coverage" ] },

build/JoinPaths.cmake

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)