Files
swift-mirror/lib/Basic/CMakeLists.txt
Tim Kientzle 5b49a04ddc New assertions support
This adds three new assertion macros:
* `ASSERT` - always compiled in, always checked
* `CONDITIONAL_ASSERT` - always compiled in, checked whenever the `-compiler-assertions` flag is provided
* `DEBUG_ASSERT` - only compiled into debug builds, always checked when compiled in  (functionally the same as Standard C `assert`)

The new `-compiler-assertions` flag is recognized by both `swift-frontend` and
`swiftc`.

The goal is to eventually replace every use of `assert` in the compiler with one of the above:
* Most assertions will use `ASSERT` (most assertions should always be present and checked, even in release builds)
* Expensive assertions can use `CONDITIONAL_ASSERT` to be suppressed by default
* A few very expensive and/or brittle assertions can use `DEBUG_ASSERT` to be compiled out of release builds

This should:
* Improve quality by catching errors earlier,
* Accelerate compiler triage and debugging by providing more accurate crash dumps by default, and
* Allow compiler engineers and end users alike to add `-compiler-assertions` to get more accurate failure diagnostics with any compiler
2024-05-16 11:38:00 -07:00

149 lines
4.6 KiB
CMake

# On non-Darwin require UUID.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(UUID_INCLUDE "")
set(UUID_LIBRARIES "")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(UUID_INCLUDE "")
set(UUID_LIBRARIES "rpcrt4.lib")
else()
find_package(UUID REQUIRED)
set(UUID_INCLUDE "${UUID_INCLUDE_DIRS}")
endif()
function(generate_revision_inc revision_inc_var name dir)
if(SWIFT_APPEND_VC_REV)
# generate_vcs_version_script generates header with only `undef`s
# inside when source directory doesn't exist.
find_first_existing_vc_file("${dir}" ${name}_vc)
set(dir_when_append_enabled ${dir})
endif()
# Create custom target to generate the VC revision include.
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/${name}Revision.inc")
set(generate_vcs_version_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/GenerateVersionFromVCS.cmake")
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${${name}_vc}" "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=$<UPPER_CASE:${name}>"
"-D$<UPPER_CASE:${name}>_SOURCE_DIR=${dir_when_append_enabled}"
"-DHEADER_FILE=${version_inc}"
-P "${generate_vcs_version_script}")
# Mark the generated header as being generated.
set_source_files_properties("${version_inc}"
PROPERTIES GENERATED TRUE
HEADER_FILE_ONLY TRUE)
set(${revision_inc_var} ${version_inc} PARENT_SCOPE)
endfunction()
generate_revision_inc(llvm_revision_inc LLVM "${LLVM_MAIN_SRC_DIR}")
generate_revision_inc(swift_revision_inc Swift "${SWIFT_SOURCE_DIR}")
add_swift_host_library(swiftBasic STATIC
Assertions.cpp
BasicBridging.cpp
BasicSourceInfo.cpp
Cache.cpp
CASOptions.cpp
ClusteredBitVector.cpp
DiverseStack.cpp
Edit.cpp
EditorPlaceholder.cpp
ExponentialGrowthAppendingBinaryByteStream.cpp
FileSystem.cpp
FileTypes.cpp
Fingerprint.cpp
ParseableOutput.cpp
JSONSerialization.cpp
LangOptions.cpp
Located.cpp
Mangler.cpp
OutputFileMap.cpp
Platform.cpp
PrefixMap.cpp
PrettyStackTrace.cpp
PrimitiveParsing.cpp
Program.cpp
QuotedString.cpp
Sandbox.cpp
SmallBitVector.cpp
SourceLoc.cpp
StableHasher.cpp
Statistic.cpp
StringExtras.cpp
TargetInfo.cpp
TaskQueue.cpp
ThreadSafeRefCounted.cpp
Unicode.cpp
UUID.cpp
Version.cpp
BlockList.cpp
${llvm_revision_inc}
${clang_revision_inc}
${swift_revision_inc}
# Platform-specific TaskQueue implementations
Unix/TaskQueue.inc
# Platform-agnostic fallback TaskQueue implementation
Default/TaskQueue.inc
LLVM_LINK_COMPONENTS support targetparser)
_swift_gyb_target_sources(swiftBasic PRIVATE
UnicodeExtendedGraphemeClusters.cpp.gyb)
target_include_directories(swiftBasic PRIVATE
${UUID_INCLUDE})
target_link_libraries(swiftBasic PUBLIC
swiftDemangling)
target_link_libraries(swiftBasic PRIVATE
${UUID_LIBRARIES})
include(${CMAKE_CURRENT_LIST_DIR}/../../cmake/SwiftVersion.cmake)
message(STATUS "Swift version: ${SWIFT_VERSION}")
message(STATUS "Swift vendor: ${SWIFT_VENDOR}")
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" SWIFT_VERSION_MAJOR
${SWIFT_VERSION})
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" SWIFT_VERSION_MINOR
${SWIFT_VERSION})
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -DSWIFT_VERSION=${SWIFT_VERSION} -DSWIFT_VERSION_MAJOR=${SWIFT_VERSION_MAJOR} -DSWIFT_VERSION_MINOR=${SWIFT_VERSION_MINOR}")
if ("${SWIFT_VERSION}" MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" SWIFT_VERSION_PATCHLEVEL
${SWIFT_VERSION})
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -DSWIFT_HAS_VERSION_PATCHLEVEL=1 -DSWIFT_VERSION_PATCHLEVEL=${SWIFT_VERSION_PATCHLEVEL}")
else()
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -DSWIFT_HAS_VERSION_PATCHLEVEL=0")
endif()
if(NOT "${SWIFT_VENDOR}" STREQUAL "")
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -DSWIFT_VENDOR=\"\\\"${SWIFT_VENDOR}\\\"\"")
endif()
set(SWIFT_COMPILER_VERSION "" CACHE STRING
"The string that identifies the SCM commit(s) for this build")
message(STATUS "Swift compiler version: ${SWIFT_COMPILER_VERSION}")
message(STATUS "Embedded clang compiler version: ${CLANG_COMPILER_VERSION}")
if(SWIFT_COMPILER_VERSION)
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -DSWIFT_COMPILER_VERSION=\"\\\"${SWIFT_COMPILER_VERSION}\\\"\"")
endif()
if(CLANG_COMPILER_VERSION)
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -DCLANG_COMPILER_VERSION=\"\\\"${CLANG_COMPILER_VERSION}\\\"\"")
endif()