Skip to content

Commit 40dcdbd

Browse files
authored
build: allow building in Debug mode on Windows (#7152)
With this tweak, we should be able to build the package in debug mode even on Windows. We always use the release mode DLL form of the C/C++ runtime on Windows and can build the Swift code in Debug or Release mode optimizations.
1 parent a54dd3b commit 40dcdbd

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
if(POLICY CMP0091)
10+
cmake_policy(SET CMP0091 NEW)
11+
endif()
12+
913
cmake_minimum_required(VERSION 3.19)
1014

1115
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
1216

1317
project(SwiftPM LANGUAGES C Swift)
1418

19+
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
20+
option(FIND_PM_DEPS "Search for all external Package Manager dependencies" YES)
21+
1522
set(CMAKE_Swift_LANGUAGE_VERSION 5)
1623
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
24+
set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
1725

1826
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1927
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2028
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2129

22-
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
23-
option(FIND_PM_DEPS "Search for all external Package Manager dependencies" YES)
30+
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
31+
set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
2432

2533
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} Windows CMAKE_INSTALL_DEFAULT)
2634
option(USE_CMAKE_INSTALL
2735
"Install build products using cmake's install() instead of the bootstrap script's install()"
2836
${CMAKE_INSTALL_DEFAULT})
2937

30-
if(BUILD_SHARED_LIBS)
31-
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
32-
endif()
33-
3438
add_compile_options(-DUSE_IMPL_ONLY_IMPORTS)
3539

3640
if(FIND_PM_DEPS)

0 commit comments

Comments
 (0)