Files
CMake/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake
AJIOB 6874efb592 MSVC: Always define a character set
When targeting the MSVC ABI, define `_MBCS` by default if the project
does not define `_SBCS` or `_UNICODE`.  Visual Studio has long defined
one of the three character set macros automatically.  For consistency,
define it when compiling for the MSVC ABI with other generators.
Add policy CMP0204 for compatibility.

Fixes: #27275
2025-10-07 09:29:32 -04:00

45 lines
1.5 KiB
CMake

set(CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE "73194a1d-c0b5-41b9-9190-a4512925e192")
# _MBCS default append for MSVC ABI workaround: see CMP0204
# So, force add the default value for all platforms to be consistent.
cmake_policy(SET CMP0204 NEW)
add_compile_definitions(_MBCS)
get_property(is_multiconfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (is_multiconfig)
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release")
endif ()
set(CMAKE_EXPORT_BUILD_DATABASE 1)
# Mock up depfile flags to keep things consistent; we don't need accurate
# dependency tracking for this test case anyways.
set(CMAKE_CXX_DEPFILE_FORMAT gcc)
set(CMAKE_DEPFILE_FLAGS_CXX "-Ddepflag=\\\"<DEP_FILE>\\\"")
unset(CMAKE_CXX_DEPFILE_EXTENSION_REPLACE)
# Disable MSVC flag injection from CMake abstractions.
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "")
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
if (CMAKE_CXX_MODULE_BMI_ONLY_FLAG MATCHES "ifcOutput")
# Make a single flag for BMI-only to make the JSON expectations simpler.
set(CMAKE_CXX_MODULE_BMI_ONLY_FLAG
"-ifcOnly;-ifcOutput<OBJECT>")
endif ()
# Disable extensions to keep flag selection simpler.
set(CMAKE_CXX_EXTENSIONS 0)
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
set(output_flag "-Fo")
else ()
set(output_flag "-o")
endif ()
set(CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> ${output_flag}<OBJECT> -c <SOURCE>")
set(CMAKE_CXX_FLAGS "-Dfrom_cmake_cxx_flags")
set(CMAKE_CXX_FLAGS_DEBUG "-Dfrom_cmake_cxx_debug_flags")
set(CMAKE_CXX_FLAGS_RELEASE "-Dfrom_cmake_cxx_release_flags")