|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | + |
| 3 | +include(FetchContent) |
| 4 | +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") |
| 5 | + cmake_policy(SET CMP0135 NEW) |
| 6 | +endif() |
| 7 | + |
| 8 | +# Add project_options from https://github.com/aminya/project_options Change the |
| 9 | +# version in the following URL to update the package (watch the releases of the |
| 10 | +# repository for future updates) |
| 11 | +set(PROJECT_OPTIONS_VERSION "v0.36.6") |
| 12 | +FetchContent_Declare( |
| 13 | + _project_options |
| 14 | + URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip |
| 15 | +) |
| 16 | +FetchContent_MakeAvailable(_project_options) |
| 17 | +include(${_project_options_SOURCE_DIR}/Index.cmake) |
| 18 | + |
| 19 | +# MacOS flags that should be set prior to any project calls |
| 20 | +if(DEFINED APPLE AND APPLE) |
| 21 | + set(CMAKE_SHARED_LINKER_FLAGS |
| 22 | + "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup") |
| 23 | + set(CMAKE_OSX_DEPLOYMENT_TARGET |
| 24 | + "10.15" |
| 25 | + CACHE STRING "Minimum OS X deployment version") |
| 26 | + add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=101500) |
| 27 | +endif() |
| 28 | + |
| 29 | +run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV |
| 30 | + "ee2d2a100103e0f3613c60655dcf15be7d5157b8") |
| 31 | + |
| 32 | +# Name of the project (will be the name of the plugin) |
| 33 | +project(addon LANGUAGES C CXX) |
| 34 | + |
| 35 | +project_options(ENABLE_CACHE) |
| 36 | + |
| 37 | +add_library( |
| 38 | + addon SHARED |
| 39 | + "src/context.cc" |
| 40 | + "src/incoming_msg.cc" |
| 41 | + "src/module.cc" |
| 42 | + "src/observer.cc" |
| 43 | + "src/outgoing_msg.cc" |
| 44 | + "src/proxy.cc" |
| 45 | + "src/socket.cc") |
| 46 | + |
| 47 | +target_link_libraries(addon PRIVATE project_options project_warnings) |
| 48 | + |
| 49 | +# ZeroMQ |
| 50 | +find_package(ZeroMQ CONFIG REQUIRED) |
| 51 | +target_link_system_libraries(addon PRIVATE libzmq libzmq-static) |
| 52 | + |
| 53 | +# Node specific |
| 54 | +target_include_directories(addon PRIVATE ${CMAKE_JS_INC}) |
| 55 | +target_link_system_libraries(addon ${CMAKE_JS_LIB}) |
| 56 | + |
| 57 | +target_compile_definitions(addon PRIVATE V8_COMPRESS_POINTERS) |
| 58 | +target_compile_definitions(addon PRIVATE V8_31BIT_SMIS_ON_64BIT_ARCH) |
| 59 | +target_compile_definitions(addon PRIVATE V8_REVERSE_JSARGS) |
| 60 | +target_compile_definitions(addon PRIVATE BUILDING_NODE_EXTENSION) |
| 61 | +target_compile_definitions(addon PRIVATE NAPI_CPP_EXCEPTIONS) |
| 62 | + |
| 63 | +# if(WIN32) |
| 64 | +# target_compile_definitions(addon PRIVATE "NOMINMAX") |
| 65 | +# target_compile_definitions(addon PRIVATE "NOGDI") |
| 66 | +# target_compile_definitions(addon PRIVATE "WIN32_LEAN_AND_MEAN") |
| 67 | +# endif() |
| 68 | + |
| 69 | +# Use `.node` for the library without any "lib" prefix |
| 70 | +set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node") |
| 71 | + |
| 72 | +# Windows workaround |
| 73 | +if(WIN32) |
| 74 | + set_property(TARGET addon PROPERTY LINK_FLAGS "-Xlinker /DELAYLOAD:NODE.EXE") |
| 75 | + target_link_libraries(addon "ShLwApi.lib" "delayimp.lib") |
| 76 | +endif() |
0 commit comments