Skip to content

Commit

Permalink
build: disable MSVC default no case warning
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 6, 2024
1 parent f4d0996 commit 0e675f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
29 changes: 19 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@ cmake_minimum_required(VERSION 3.16)

macro(set_option_from_env OPTION_NAME)
string(TOLOWER ${OPTION_NAME} OPTION_NAME_LOWER)

if(DEFINED ENV{npm_config_${OPTION_NAME_LOWER}})
if("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "true")
set("${OPTION_NAME}"
ON
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
ON
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
elseif("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "false")
set("${OPTION_NAME}"
OFF
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
OFF
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
else()
set("${OPTION_NAME}"
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
endif()
endif()

if(${OPTION_NAME})
string(REPLACE "zmq_" "" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
string(REPLACE "_" "-" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
list(APPEND VCPKG_MANIFEST_FEATURES ${OPTION_NAME_LOWER})
endif()

message(STATUS "${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

Expand Down Expand Up @@ -61,13 +64,16 @@ if(WIN32)
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
endif()

# Avoid loading of project_optinos/WindowsToolchain
set(CMAKE_TOOLCHAIN_FILE ";")

# use static runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

include(FetchContent)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
Expand All @@ -88,11 +94,11 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
# MacOS flags that should be set prior to any project calls
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
endif()

run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")

# Name of the project (will be the name of the plugin)
project(addon LANGUAGES C CXX)
Expand All @@ -103,15 +109,17 @@ file(GLOB_RECURSE SOURCES "./src/*.cc")
add_library(addon SHARED ${SOURCES})

if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
target_compile_options(project_warnings INTERFACE "-Wno-shadow")
endif()

target_link_libraries(addon PRIVATE project_options project_warnings)

if(ZMQ_DRAFT)
target_compile_definitions(addon PRIVATE ZMQ_BUILD_DRAFT_API)
endif()

if(ZMQ_NO_SYNC_RESOLVE)
target_compile_definitions(addon PRIVATE ZMQ_NO_SYNC_RESOLVE)
endif()
Expand All @@ -129,6 +137,7 @@ target_compile_definitions(addon PRIVATE V8_31BIT_SMIS_ON_64BIT_ARCH)
target_compile_definitions(addon PRIVATE V8_REVERSE_JSARGS)
target_compile_definitions(addon PRIVATE BUILDING_NODE_EXTENSION)
target_compile_definitions(addon PRIVATE NAPI_CPP_EXCEPTIONS)

if(WIN32)
target_compile_definitions(addon PRIVATE "NOMINMAX")
target_compile_definitions(addon PRIVATE "NOGDI")
Expand Down
3 changes: 3 additions & 0 deletions src/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ void Socket::Close(const Napi::CallbackInfo& info) {
}

Napi::Value Socket::Send(const Napi::CallbackInfo& info) {
#ifdef _MSC_VER
#pragma warning(disable : 4065)
#endif
switch (type) {
#ifdef ZMQ_HAS_POLLABLE_THREAD_SAFE
case ZMQ_SERVER:
Expand Down

0 comments on commit 0e675f2

Please sign in to comment.