Last active
May 13, 2020 08:41
-
-
Save s1hofmann/aa9e83a54f3422566b2f51df9ace4346 to your computer and use it in GitHub Desktop.
N-API CMakeLists.txt template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.5) | |
set(CMAKE_CXX_STANDARD 17) | |
project(YOUR_PROJECT_NAME_HERE) | |
# Source | |
set(SOURCE_FILES "src/main.cc" "..." "...") | |
if (UNIX AND NOT APPLE) | |
set(SOURCE_FILES "${SOURCE_FILES}" "..." "...") | |
elseif (UNIX AND APPLE) | |
set(SOURCE_FILES "${SOURCE_FILES}" "..." "...") | |
elseif (WIN32) | |
set(SOURCE_FILES "${SOURCE_FILES}" "..." "...") | |
endif() | |
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC}) | |
set(LIBS "") | |
set(INCLUDES "") | |
# External libs | |
if (UNIX AND APPLE) | |
message(STATUS "macOS build") | |
set(LIBS "${LIBS}" "..." "...") | |
elseif (WIN32) | |
message(STATUS "Windows build") | |
set(LIBS "${LIBS}" "..." "...") | |
elseif (UNIX AND NOT APPLE) | |
message(STATUS "Linux build") | |
set(LIBS "${LIBS}" "..." "...") | |
endif() | |
add_compile_definitions(NAPI_CPP_EXCEPTIONS) | |
add_compile_definitions(NAPI_VERSION=3) | |
# cmake-js | |
set(INCLUDES ${INCLUDES} ${CMAKE_JS_INC}) | |
message(STATUS "Includes: ${INCLUDES}") | |
set(LIBS ${LIBS} ${CMAKE_JS_LIB}) | |
message(STATUS "Libs: ${LIBS}") | |
# N-API | |
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/node_modules/node-addon-api") | |
# Change suffix to *.node | |
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") | |
# BUILD | |
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDES}) | |
target_link_libraries(${PROJECT_NAME} ${LIBS}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment