From 7e2383799356a974aa736d8cf485c0ac44bd0532 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Wed, 2 Oct 2019 09:48:52 +0200 Subject: [PATCH] fix(NAPI): wrong include path --- CMakeLists.txt | 5 +++-- cmake/utils.cmake | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7efcfe7..5acef44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,10 +63,11 @@ target_include_directories(genepi PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/node_modules/node-addon-api - ${PROJECT_SOURCE_DIR}/../node-addon-api + PRIVATE + ${NODE_ADDON_API_DIR} ${CMAKE_JS_INC} ) + target_link_libraries(genepi PUBLIC ${CMAKE_JS_LIB}) export(TARGETS genepi NAMESPACE genepi:: FILE genepi_target.cmake) include(GenerateExportHeader) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index e88fd52..338dd5f 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -22,12 +22,32 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +execute_process( + COMMAND node -p "require('node-addon-api').include" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE NODE_ADDON_API_DIR +) +string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) +string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) + macro(add_genepi_library target_name files) add_library(${target_name} SHARED ${files} ${CMAKE_JS_SRC}) + target_include_directories(${target_name} + PUBLIC + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_BINARY_DIR} + PRIVATE + ${NODE_ADDON_API_DIR} + ${CMAKE_JS_INC} + ) set_target_properties(${target_name} PROPERTIES PREFIX "" SUFFIX ".node" ) - target_link_libraries(${target_name} genepi::genepi ${CMAKE_JS_LIB}) + target_link_libraries(${target_name} + PUBLIC + genepi::genepi + ${CMAKE_JS_LIB} + ) endmacro()