Skip to content

Commit 526eb88

Browse files
committed
fix: use static linking for vcpkg on Windows
1 parent f7f6356 commit 526eb88

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,33 @@ set_option_from_env(ZMQ_NO_SYNC_RESOLVE)
4646
if(APPLE)
4747
option(MACOSX_DEPLOYMENT_TARGET "MacOS deployment target" "10.15")
4848
set_option_from_env(MACOSX_DEPLOYMENT_TARGET)
49+
set(CMAKE_OSX_DEPLOYMENT_TARGET
50+
${MACOSX_DEPLOYMENT_TARGET}
51+
CACHE STRING "MacOS deployment target")
4952
endif()
5053

51-
# MacOS deployment target
54+
# Set the target system on Windows (for cross-compiling x86)
5255
if(WIN32)
5356
if("${PLATFORM}" STREQUAL "x86")
5457
set(CMAKE_SYSTEM_PROCESSOR "x86")
5558
set(CMAKE_SYSTEM_HOST_PROCESSOR "x86")
59+
# static linking for vcpkg
60+
set(VCPKG_TARGET_TRIPLET "x86-windows-static")
5661
elseif(NOT "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "")
5762
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
5863
set(CMAKE_SYSTEM_HOST_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
64+
# static linking for vcpkg
65+
set(VCPKG_TARGET_TRIPLET "x86-windows-static")
5966
else()
6067
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
6168
set(CMAKE_SYSTEM_HOST_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
69+
# static linking for vcpkg
70+
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
6271
endif()
72+
# Avoid loading of project_optinos/WindowsToolchain
6373
set(CMAKE_TOOLCHAIN_FILE ";")
74+
# use static runtime library
75+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
6476
endif()
6577

6678
include(FetchContent)
@@ -82,13 +94,9 @@ FetchContent_MakeAvailable(_project_options)
8294
include(${_project_options_SOURCE_DIR}/Index.cmake)
8395

8496
# MacOS flags that should be set prior to any project calls
85-
if(DEFINED APPLE AND APPLE)
97+
if(APPLE)
8698
set(CMAKE_SHARED_LINKER_FLAGS
8799
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
88-
set(CMAKE_OSX_DEPLOYMENT_TARGET
89-
"10.15"
90-
CACHE STRING "Minimum OS X deployment version")
91-
add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=101500)
92100
endif()
93101

94102
run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV
@@ -133,7 +141,7 @@ endif()
133141
# Use `.node` for the library without any "lib" prefix
134142
set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node")
135143

136-
# Windows workaround
144+
# Windows
137145
if(WIN32)
138146
set_property(TARGET addon PROPERTY LINK_FLAGS "-Xlinker /DELAYLOAD:NODE.EXE")
139147
target_link_libraries(addon PRIVATE "ShLwApi.lib" "delayimp.lib")

0 commit comments

Comments
 (0)