2019-09-05 01:57:56 +03:00
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2024-07-12 00:55:18 +03:00
cmake_minimum_required ( VERSION 3.29.0 )
2022-12-16 00:34:36 +03:00
2019-09-05 22:29:04 +03:00
set ( CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )
2019-09-05 01:57:56 +03:00
project ( msvc_standard_libraries LANGUAGES CXX )
2022-05-24 03:57:01 +03:00
include ( CheckCXXSourceCompiles )
check_cxx_source_compiles ( [=[
#include <sdkddkver.h>
2024-03-16 08:06:09 +03:00
static_assert ( WDK_NTDDI_VERSION >= NTDDI_WIN10_NI, "Inspecting WDK_NTDDI_VERSION, the Windows SDK version." ) ;
2022-05-24 03:57:01 +03:00
i n t main ( ) { }
] = ] W I N D O W S _ S D K _ V E R S I O N _ C H E C K )
2022-06-26 01:21:09 +03:00
2022-05-24 03:57:01 +03:00
if ( NOT WINDOWS_SDK_VERSION_CHECK )
2024-03-16 08:06:09 +03:00
message ( FATAL_ERROR "The STL must be built with the Windows 11 SDK (10.0.22621.0) or later. Make sure it's available by selecting it in the Individual Components tab of the VS Installer." )
2022-05-24 03:57:01 +03:00
endif ( )
2022-05-24 04:36:43 +03:00
if ( NOT DEFINED VCLIBS_TARGET_ARCHITECTURE )
set ( VCLIBS_TARGET_ARCHITECTURE "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" )
endif ( )
2022-06-26 01:21:09 +03:00
2022-05-24 04:36:43 +03:00
string ( TOLOWER "${VCLIBS_TARGET_ARCHITECTURE}" VCLIBS_TARGET_ARCHITECTURE )
if ( VCLIBS_TARGET_ARCHITECTURE MATCHES "^x64$|^x86$" )
enable_language ( ASM_MASM )
endif ( )
2022-05-05 12:40:19 +03:00
# add the tools subdirectory _before_ we change all the flags
add_subdirectory ( tools EXCLUDE_FROM_ALL )
2022-06-26 01:21:09 +03:00
2022-05-05 12:40:19 +03:00
# these allow the targets to show up in the top-level
# (as opposed to under the tools subdirectory)
if ( TARGET run-format )
add_custom_target ( format )
add_dependencies ( format run-format )
endif ( )
2022-06-26 01:21:09 +03:00
2022-05-05 12:40:19 +03:00
if ( TARGET run-validate )
add_custom_target ( validate )
add_dependencies ( validate run-validate )
endif ( )
2020-04-14 18:10:37 +03:00
option ( BUILD_TESTING "Enable testing" ON )
2020-04-01 21:41:55 +03:00
set ( VCLIBS_SUFFIX "_oss" CACHE STRING "suffix for built DLL names to avoid conflicts with distributed DLLs" )
2019-09-05 01:57:56 +03:00
2022-06-26 01:21:09 +03:00
option ( STL_USE_ANALYZE "Pass the /analyze flag to MSVC" OFF )
2024-01-17 14:44:07 +03:00
option ( STL_ASAN_BUILD "Build the STL with ASan enabled" OFF )
2022-06-26 01:21:09 +03:00
2023-05-31 02:55:31 +03:00
set ( VCLIBS_EXPLICIT_MACHINE "" )
2023-08-11 03:44:26 +03:00
if ( "${VCLIBS_TARGET_ARCHITECTURE}" STREQUAL "x86" )
2019-09-07 05:23:11 +03:00
set ( VCLIBS_TARGET_ARCHITECTURE "x86" )
2019-09-05 01:57:56 +03:00
set ( VCLIBS_I386_OR_AMD64 "i386" )
set ( VCLIBS_X86_OR_X64 "x86" )
2022-06-26 01:21:09 +03:00
2019-09-07 05:23:11 +03:00
# Note that we set _WIN32_WINNT to a high level to make declarations available, but still engage downlevel
# runtime dynamic linking by setting our own _STL_WIN32_WINNT back to Windows XP.
2022-05-12 23:36:47 +03:00
add_compile_definitions ( _X86_ _VCRT_WIN32_WINNT=0x0501 _STL_WIN32_WINNT=0x0501 )
2023-08-11 03:44:26 +03:00
elseif ( VCLIBS_TARGET_ARCHITECTURE STREQUAL "x64" )
2019-09-07 05:23:11 +03:00
set ( VCLIBS_TARGET_ARCHITECTURE "x64" )
2019-09-05 01:57:56 +03:00
set ( VCLIBS_I386_OR_AMD64 "amd64" )
set ( VCLIBS_X86_OR_X64 "x64" )
2022-05-12 23:36:47 +03:00
add_compile_definitions ( _AMD64_ _VCRT_WIN32_WINNT=0x0501 _STL_WIN32_WINNT=0x0501 )
2023-08-11 03:44:26 +03:00
elseif ( VCLIBS_TARGET_ARCHITECTURE STREQUAL "armv7" )
2019-09-07 05:23:11 +03:00
set ( VCLIBS_TARGET_ARCHITECTURE "arm" )
2019-09-05 01:57:56 +03:00
set ( VCLIBS_I386_OR_AMD64 "arm" )
set ( VCLIBS_X86_OR_X64 "arm" )
2022-05-12 23:36:47 +03:00
add_compile_definitions ( _ARM_ _VCRT_WIN32_WINNT=0x0602 _STL_WIN32_WINNT=0x0602 )
2023-08-11 03:44:26 +03:00
elseif ( VCLIBS_TARGET_ARCHITECTURE STREQUAL "arm64" )
2019-09-07 05:23:11 +03:00
set ( VCLIBS_TARGET_ARCHITECTURE "arm64" )
2019-09-05 01:57:56 +03:00
set ( VCLIBS_I386_OR_AMD64 "arm64" )
set ( VCLIBS_X86_OR_X64 "arm64" )
2022-05-12 23:36:47 +03:00
add_compile_definitions ( _ARM64_ _VCRT_WIN32_WINNT=0x0A00 _STL_WIN32_WINNT=0x0A00 )
2023-08-11 03:44:26 +03:00
elseif ( VCLIBS_TARGET_ARCHITECTURE STREQUAL "arm64ec" )
2023-05-31 02:55:31 +03:00
set ( VCLIBS_TARGET_ARCHITECTURE "arm64ec" )
set ( VCLIBS_I386_OR_AMD64 "arm64ec" )
set ( VCLIBS_X86_OR_X64 "arm64" ) # Yes, really: `%VCToolsInstallDir%lib\arm64ec` only contains the Link Options
add_compile_definitions ( _AMD64_ _ARM64EC_ _VCRT_WIN32_WINNT=0x0501 _STL_WIN32_WINNT=0x0501 )
add_compile_options ( $< $<COMPILE_LANGUAGE:CXX > :/arm64EC> )
set ( VCLIBS_EXPLICIT_MACHINE "/machine:arm64ec" )
2019-09-05 01:57:56 +03:00
else ( )
2019-09-07 05:23:11 +03:00
message ( FATAL_ERROR "Could not determine target architecture: VCLIBS_TARGET_ARCHITECTURE: ${VCLIBS_TARGET_ARCHITECTURE}" )
2019-09-05 01:57:56 +03:00
endif ( )
2022-07-01 05:14:34 +03:00
get_filename_component ( TOOLSET_BINARIES_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY ) # Example: $\VC\Tools\MSVC\14.23.27931\bin\Hostx86\x86
get_filename_component ( TOOLSET_ROOT_DIR "${TOOLSET_BINARIES_DIR}" DIRECTORY ) # $\VC\Tools\MSVC\14.23.27931\bin\Hostx86
get_filename_component ( TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY ) # $\VC\Tools\MSVC\14.23.27931\bin
get_filename_component ( TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY ) # $\VC\Tools\MSVC\14.23.27931
set ( TOOLSET_LIB "${TOOLSET_ROOT_DIR}/lib/${VCLIBS_X86_OR_X64}" )
set ( STL_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}" )
set ( STL_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}" )
set ( STL_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/bin/${VCLIBS_I386_OR_AMD64}" )
2019-09-07 05:23:11 +03:00
add_compile_definitions (
2019-09-05 01:57:56 +03:00
_ A L L O W _ I T E R A T O R _ D E B U G _ L E V E L _ M I S M A T C H W I N 3 2 _ L E A N _ A N D _ M E A N S T R I C T _ C R T _ S T D I O _ A R B I T R A R Y _ W I D E _ S P E C I F I E R S
2024-03-16 08:06:09 +03:00
_ W I N 3 2 _ W I N N T = 0 x 0 A 0 0 N T D D I _ V E R S I O N = N T D D I _ W I N 1 0 _ N I )
2019-09-05 01:57:56 +03:00
2022-06-26 01:21:09 +03:00
if ( STL_USE_ANALYZE )
# TRANSITION OS-40109504: Windows SDK: incorrect SAL annotations on functions the STL uses
# warning C6553: The annotation for function 'LCMapStringEx' on _Param_(9)
# does not apply to a value type.
# There's a bug in the declaration for LCMapStringEx - it applies _In_opt_ to an LPARAM.
# LPARAM is a LONG_PTR (intptr_t), and it's invalid to apply _In_opt_ to a non-pointer.
2024-03-16 08:06:09 +03:00
# As of the Windows 11 SDK (10.0.22621.0), there are 5 total occurrences of warning C6553 affecting the STL's build.
2022-06-26 01:21:09 +03:00
add_compile_options ( "$<$<COMPILE_LANGUAGE:CXX>:/analyze:autolog-;/wd6553>" )
endif ( )
2022-05-24 04:36:43 +03:00
set ( VCLIBS_DEBUG_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:/Od>" )
2022-05-05 12:53:26 +03:00
# TRANSITION: Potentially remove `/Os` if it results in speed improvements.
# This requires benchmarking!
# Note that in MSVC version 19.32.31328,
# `/Os` results in a binary size difference of 102K
# in the release DLL (a gain of 18.4%).
# So, make certain that that tradeoff is considered when or if `/Os` is removed.
# See GH-2108 for more info.
2022-05-24 04:36:43 +03:00
set ( VCLIBS_RELEASE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:/O2;/Os>" )
2019-09-05 01:57:56 +03:00
2020-04-02 23:23:34 +03:00
if ( BUILD_TESTING )
2020-04-01 00:05:46 +03:00
enable_testing ( )
add_subdirectory ( tests )
endif ( )
2024-01-17 14:44:07 +03:00
if ( STL_ASAN_BUILD )
message ( STATUS "Building with ASan enabled" )
add_compile_options ( "$<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address;-fno-sanitize-address-vcasan-lib>" )
endif ( )
add_subdirectory ( boost-math )
add_subdirectory ( stl )