diff --git a/CMakeLists.txt b/CMakeLists.txt index 90cfaaf0..2732fa25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -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$<$:Debug>") endif() include(FetchContent) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") cmake_policy(SET CMP0135 NEW) endif() @@ -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) @@ -103,15 +109,20 @@ 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") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL MSVC) + # disable 'default' but no 'case' labels + target_compile_options(project_warnings INTERFACE "/wd4065") 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() @@ -129,6 +140,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")