@@ -6,10 +6,6 @@ cmake_policy(SET CMP0042 NEW)
66
77project (nudelta)
88
9- if (NOT DEFINED NODE_RUNTIME)
10- message ( FATAL_ERROR "NODE_RUNTIME is not defined. Use `cmake-js` from the root of the repo." )
11- endif ()
12-
139# Get version from package.json
1410file (READ ${CMAKE_CURRENT_SOURCE_DIR } /package.json PACKAGE_JSON )
1511string (JSON NUDELTA_VERSION GET ${PACKAGE_JSON} "version" )
@@ -22,11 +18,11 @@ set(BUILD_SHARED_LIBS FALSE)
2218set (CMAKE_OSX_DEPLOYMENT_TARGET "11.3" )
2319
2420if (APPLE )
25- set (CMAKE_THREAD_LIBS_INIT "-lpthread" )
26- set (CMAKE_HAVE_THREADS_LIBRARY 1)
27- set (CMAKE_USE_WIN32_THREADS_INIT 0)
28- set (CMAKE_USE_PTHREADS_INIT 1)
29- set (THREADS_PREFER_PTHREAD_FLAG ON )
21+ set (CMAKE_THREAD_LIBS_INIT "-lpthread" )
22+ set (CMAKE_HAVE_THREADS_LIBRARY 1)
23+ set (CMAKE_USE_WIN32_THREADS_INIT 0)
24+ set (CMAKE_USE_PTHREADS_INIT 1)
25+ set (THREADS_PREFER_PTHREAD_FLAG ON )
3026endif ()
3127
3228# Dependencies
@@ -37,57 +33,64 @@ include_directories(include)
3733
3834# YAML Data
3935file (GLOB_RECURSE yml_files "res/**/*.yml" )
36+ find_program (RUBY_EXECUTABLE ruby )
37+ if (RUBY_EXECUTABLE)
38+ message (STATUS "ruby found at: ${RUBY_EXECUTABLE} " )
39+ else ()
40+ message (FATAL_ERROR "ruby not found in PATH and is required for an intermediate build step." )
41+ endif ()
4042add_custom_command (
41- OUTPUT ${CMAKE_CURRENT_BINARY_DIR } /res.cpp
42- COMMAND node ${CMAKE_CURRENT_LIST_DIR } /util/res_to_cpp.js ${CMAKE_CURRENT_LIST_DIR } /res > ${CMAKE_CURRENT_BINARY_DIR } /res.cpp
43- DEPENDS ${yml_files} util/res_to_cpp.js
43+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR } /res.cpp
44+ COMMAND ${RUBY_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR } /util/res2cxx.rb ${CMAKE_CURRENT_LIST_DIR } /res > ${CMAKE_CURRENT_BINARY_DIR } /res.cpp
45+ DEPENDS ${yml_files} util/res2cxx.rb
4446)
4547add_custom_target (res_file ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR } /res.cpp )
4648
4749include_directories (res )
4850
4951# libnd
52+ include_directories (${CMAKE_JS_INC} )
5053file (GLOB nudelta_lib_src "lib/*.cpp" )
5154add_library (nd ${nudelta_lib_src} ${CMAKE_CURRENT_BINARY_DIR } /res.cpp )
5255add_dependencies (nd res_file )
5356if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
54- target_link_libraries (nd hidapi::hidraw )
57+ target_link_libraries (nd PUBLIC hidapi::hidraw )
5558else ()
56- target_link_libraries (nd hidapi )
59+ target_link_libraries (nd PUBLIC hidapi )
5760endif ()
58- target_link_libraries (nd yaml-cpp )
59- target_link_libraries (nd fmt )
60- target_link_libraries (nd scope_guard )
61+ target_link_libraries (nd PRIVATE yaml-cpp )
62+ target_link_libraries (nd PRIVATE fmt )
63+ target_link_libraries (nd PRIVATE $< COMPILE_ONLY : scope_guard > )
6164
6265if (!MSVC )
6366 target_compile_options (nd -Wall -Wextra -Wpedantic -Werror )
6467endif ()
6568
69+ if (DEFINED NODE_RUNTIME)
70+ # node-libnd
71+ add_definitions (-DNAPI_VERSION=4 )
72+ include_directories (${CMAKE_JS_INC} )
73+ include_directories (${CMAKE_SOURCE_DIR } /node_modules/node-addon-api )
74+ include_directories (${CMAKE_SOURCE_DIR } /node_modules/node-api-headers/include )
6675
67- # node-libnd
68- add_definitions (-DNAPI_VERSION=4 )
69- include_directories (${CMAKE_JS_INC} )
70- include_directories (${CMAKE_SOURCE_DIR } /node_modules/node-addon-api )
71- include_directories (${CMAKE_SOURCE_DIR } /node_modules/node-api-headers/include )
72- add_library (node-libnd SHARED src/node.cpp ${CMAKE_JS_SRC} )
73- target_link_libraries (node-libnd nd )
74- target_link_libraries (node-libnd ${CMAKE_JS_LIB} )
76+ add_library (node-libnd SHARED src/node.cpp ${CMAKE_JS_SRC} )
77+ target_link_libraries (node-libnd nd )
78+ target_link_libraries (node-libnd ${CMAKE_JS_LIB} )
7579
76- set_target_properties (node-libnd PROPERTIES PREFIX "" SUFFIX ".node" )
80+ set_target_properties (node-libnd PROPERTIES PREFIX "" SUFFIX ".node" )
81+ endif ()
7782
7883# nudelta
79- add_executable (nudelta src/main.cpp )
84+ add_executable (nudelta-cli src/main.cpp )
8085add_compile_definitions (NUDELTA_VERSION= "${CMAKE_PROJECT_VERSION} " )
81- target_link_libraries (nudelta nd )
86+ target_link_libraries (nudelta-cli PUBLIC nd )
8287if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
83- target_link_libraries (nudelta hidapi::hidraw )
88+ target_link_libraries (nudelta-cli PUBLIC hidapi::hidraw )
8489else ()
85- target_link_libraries (nudelta hidapi )
90+ target_link_libraries (nudelta-cli PUBLIC hidapi )
8691endif ()
87- target_link_libraries (nudelta yaml-cpp )
88- target_link_libraries (nudelta fmt )
89- target_link_libraries (nudelta ssco )
90- target_link_libraries (nudelta scope_guard )
92+ target_link_libraries (nudelta-cli PRIVATE ssco )
93+
9194
9295
93- install (TARGETS nudelta)
96+ install (TARGETS nudelta-cli )
0 commit comments