@@ -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" )
@@ -19,86 +15,78 @@ set(CMAKE_CXX_STANDARD 17)
1915set (CMAKE_CXX_STANDARD_REQUIRED True )
2016set (CMAKE_POSITION_INDEPENDENT_CODE ON )
2117set (BUILD_SHARED_LIBS FALSE )
22- set (CMAKE_OSX_DEPLOYMENT_TARGET "11" )
18+ set (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
32- # Hidapi does not use `option`
33- set (HIDAPI_WITH_LIBUSB FALSE )
34- set (HIDAPI_WITH_HIDRAW TRUE )
35- add_subdirectory (submodules/hidapi )
36-
37- option (YAML_CPP_BUILD_TOOLS OFF )
38- add_subdirectory (submodules/yaml-cpp )
39-
40- add_subdirectory (submodules/scope_guard )
41-
42- add_subdirectory (submodules/fmt )
43-
44- add_subdirectory (submodules/ssco )
28+ # Dependencies
29+ include (third_party/CMakeLists.txt )
4530
4631# Common
4732include_directories (include )
4833
4934# YAML Data
5035file (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 ()
5142add_custom_command (
52- OUTPUT ${CMAKE_CURRENT_BINARY_DIR } /res.cpp
53- COMMAND node ${CMAKE_CURRENT_LIST_DIR } /util/res_to_cpp.js ${CMAKE_CURRENT_LIST_DIR } /res > ${CMAKE_CURRENT_BINARY_DIR } /res.cpp
54- 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
5546)
5647add_custom_target (res_file ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR } /res.cpp )
5748
5849include_directories (res )
5950
6051# libnd
52+ include_directories (${CMAKE_JS_INC} )
6153file (GLOB nudelta_lib_src "lib/*.cpp" )
6254add_library (nd ${nudelta_lib_src} ${CMAKE_CURRENT_BINARY_DIR } /res.cpp )
6355add_dependencies (nd res_file )
56+ target_link_libraries (nd PUBLIC fmt )
6457if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
65- target_link_libraries (nd hidapi::hidraw )
58+ target_link_libraries (nd PUBLIC hidapi::hidraw )
6659else ()
67- target_link_libraries (nd hidapi )
60+ target_link_libraries (nd PUBLIC hidapi )
6861endif ()
69- target_link_libraries (nd yaml-cpp )
70- target_link_libraries (nd fmt )
71- target_link_libraries (nd scope_guard )
62+ target_link_libraries (nd PRIVATE yaml-cpp )
63+ target_link_libraries (nd PRIVATE $<COMPILE_ONLY :scope_guard >)
7264
7365if (!MSVC )
7466 target_compile_options (nd -Wall -Wextra -Wpedantic -Werror )
7567endif ()
7668
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 )
7775
78- # node-libnd
79- add_definitions (-DNAPI_VERSION=4 )
80- include_directories (${CMAKE_JS_INC} )
81- include_directories (${CMAKE_SOURCE_DIR } /node_modules/node-addon-api )
82- include_directories (${CMAKE_SOURCE_DIR } /node_modules/node-api-headers/include )
83- add_library (node-libnd SHARED src/node.cpp ${CMAKE_JS_SRC} )
84- target_link_libraries (node-libnd nd )
85- 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} )
8679
87- set_target_properties (node-libnd PROPERTIES PREFIX "" SUFFIX ".node" )
80+ set_target_properties (node-libnd PROPERTIES PREFIX "" SUFFIX ".node" )
81+ endif ()
8882
8983# nudelta
90- add_executable (nudelta src/main.cpp )
84+ add_executable (nudelta-cli src/main.cpp )
9185add_compile_definitions (NUDELTA_VERSION= "${CMAKE_PROJECT_VERSION} " )
92- target_link_libraries (nudelta nd )
93- if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
94- target_link_libraries (nudelta hidapi::hidraw )
95- else ()
96- target_link_libraries (nudelta hidapi )
97- endif ()
98- target_link_libraries (nudelta yaml-cpp )
99- target_link_libraries (nudelta fmt )
100- target_link_libraries (nudelta ssco )
101- target_link_libraries (nudelta scope_guard )
86+ target_link_libraries (nudelta-cli PUBLIC nd )
87+ target_link_libraries (nudelta-cli PRIVATE $<COMPILE_ONLY :scope_guard >)
88+ target_link_libraries (nudelta-cli PRIVATE ssco )
89+
10290
10391
104- install (TARGETS nudelta)
92+ install (TARGETS nudelta-cli )
0 commit comments