Skip to content

Commit a56078a

Browse files
author
Greg Roth
authored
Make hctbuild cmake gen consistent with asserts (microsoft#5881)
A slightly complex series of events causes invocations of hctbuild after the first to enable asserts in release builds. This sets the build type even when it isn't needed to avoid it. Because the build type was not being set when generating for visual studio in hctbuild, when generating the cmake files using CMakeLists, it would produce an alarming message saying it was defaulting to debug, but, in fact, since it didn't care for the purposes of sln file generation, that wasn't actually a problem, just confusing. It did set a variable to enable asserts, but didn't do this for release variant builds The real problem occurs if hctbuild is invoked again, at that point, instead of defaulting to Debug, it leaves the build type empty because of another variable set in the cache. Additionally, since the first invocation enabled asserts, that also comes from the cache and so code that strips NDEBUG from all build variants is invoked because the build type is, in fact, not debug, it's an empty string.
1 parent 568ad77 commit a56078a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
# See docs/CMake.html for instructions about how to build LLVM with CMake.
22
cmake_minimum_required(VERSION 3.17.2) # HLSL Change - Require CMake 3.17.2.
33

4+
message(CMAKE_BUILD_TYPE0!!!!!="${CMAKE_BUILD_TYPE}")
5+
message(CMAKE_CONFIGURATION_TYPES!!!!!="${CMAKE_CONFIGURATION_TYPES}")
6+
message(CMAKE_CXX_FLAGS_RELEASE!!!!!="${CMAKE_CXX_FLAGS_RELEASE}")
47
set(CMAKE_CXX_STANDARD 17)
58
set(CMAKE_CXX_STANDARD_REQUIRED ON)
69

710
if (NOT "${DXC_CMAKE_BEGINS_INCLUDE}" STREQUAL "")
811
include(${DXC_CMAKE_BEGINS_INCLUDE})
912
endif()
1013

14+
1115
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1216
message(STATUS "No build type selected, default to Debug")
1317
set(CMAKE_BUILD_TYPE "Debug")
1418
endif()
19+
message(CMAKE_BUILD_TYPE1!!!!!="${CMAKE_BUILD_TYPE}")
1520

1621
if(POLICY CMP0022)
1722
cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
@@ -315,11 +320,15 @@ option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
315320
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
316321
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
317322

323+
message(uppercase_CMAKE_BUILD_TYPE!!!!!="${CMAKE_BUILD_TYPE}")
318324
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
325+
message(assertions OFF)
319326
option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
320327
else()
328+
message(assertions ON)
321329
option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
322330
endif()
331+
message(LLVM_ENABLE_ASSERTIONS!!!!!="${LLVM_ENABLE_ASSERTIONS}")
323332

324333
set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
325334
"Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ int main() { return (float)x; }"
5656
endif()
5757

5858
if( LLVM_ENABLE_ASSERTIONS )
59+
message(how did I get here?)
5960
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
6061
# HLSL Note: the above comment referrs to llvm.org problem, not pull request:
6162
# https://bugs.llvm.org/show_bug.cgi?id=4379

utils/hct/hctbuild.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ if "%DO_SETUP%"=="1" (
471471
echo Running "%CMAKE_PATH%" -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% > %3\cmake-log.txt
472472
"%CMAKE_PATH%" -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
473473
) else (
474-
rem -DCMAKE_BUILD_TYPE:STRING=%1 is not necessary for multi-config generators like VS
475-
rem but need CMAKE_BUILD_TYPE to generate lit cfg.
474+
rem BUILD_TYPE is mostly ignored in this path as VS generates multiple targets
475+
rem it is still needed to satisfy cmake file expectations
476476
echo Running "%CMAKE_PATH%" -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% > %3\cmake-log.txt
477477
"%CMAKE_PATH%" %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
478478
)

0 commit comments

Comments
 (0)