forked from REVrobotics/node-can-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'REV/main' into fix/upstream-build-changes
Refactored 'runtimeArtifactsPath' to use 'path' instead of manual entry, which might break on some platforms. Also updated names of prebuild artifacts.
- Loading branch information
Showing
14 changed files
with
1,018 additions
and
2,108 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ prebuilds/ | |
dist/ | ||
externalCompileTimeDeps/ | ||
temp/ | ||
cmake-build-*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
cmake_policy(SET CMP0091 NEW) | ||
cmake_policy(SET CMP0042 NEW) | ||
|
||
set (CMAKE_CXX_STANDARD 20) | ||
|
||
project(node_canbridge) | ||
|
||
if(NOT CMAKE_JS_INC) | ||
include("cmake-js.cmake") | ||
setup_cmakejs() | ||
endif () | ||
|
||
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/node_modules) | ||
message(FATAL_ERROR "You must run 'npm install' in order for NAPI to be available") | ||
endif() | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) | ||
# Generate node.lib | ||
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) | ||
endif() | ||
|
||
# Set some things up for cross-compiling on Linux using clang | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
if(SYSTEM STREQUAL "LinuxX64") | ||
add_compile_options("-target" "x86_64-pc-linux-gnu") | ||
elseif(SYSTEM STREQUAL "LinuxArm64") | ||
add_compile_options("-target" "aarch64-pc-linux-gnu") | ||
add_link_options("-target" "aarch64-pc-linux-gnu" "-fuse-ld=/usr/bin/aarch64-linux-gnu-ld") | ||
endif() | ||
endif() | ||
|
||
add_definitions(-DNAPI_VERSION=9) # Keep in sync with binding-options.cjs, package.json binary.napi_version, and package.json prepublishOnly | ||
add_definitions(-DNAPI_DISABLE_CPP_EXCEPTIONS) | ||
|
||
set(SOURCES | ||
src/addon.cc | ||
src/canWrapper.cc | ||
) | ||
|
||
# Include the node-addon-api wrapper for Node-API | ||
# TODO: Figure out if this todo applies. I honestly copied it from an older project | ||
# TODO: Figure out why the build breaks without this, given that the CMake.js README | ||
# says that it will "add [node-addon-api] to the include search path automatically" | ||
# https://github.com/cmake-js/cmake-js/tree/6a2a50ba3d2e82a0ea80a8bb77cd2d3a03fb838c#node-api-and-node-addon-api | ||
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}) | ||
|
||
include_directories(${NODE_ADDON_API_DIR} ${CMAKE_JS_INC} ${CMAKE_CURRENT_SOURCE_DIR}/src | ||
${CMAKE_CURRENT_SOURCE_DIR}/externalCompileTimeDeps/include) | ||
|
||
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${CMAKE_JS_SRC}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") | ||
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} CANBridge wpiHal wpiutil) | ||
|
||
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/externalCompileTimeDeps) | ||
|
||
# The ones that don't exist are just skipped | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-x64) | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm64) | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm32) | ||
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-darwin-osxuniversal) | ||
|
||
include(move-files.cmake) | ||
|
||
foreach(CONFIG_TYPE IN LISTS CMAKE_CONFIGURATION_TYPES) | ||
# Windows | ||
create_move_target(CANBridge.dll ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-win32-x64/CANBridge.dll ${CONFIG_TYPE}/CANBridge.dll) | ||
create_move_target(wpiHal.dll ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-win32-x64/wpiHal.dll ${CONFIG_TYPE}/wpiHal.dll) | ||
create_move_target(wpiUtil.dll ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-win32-x64/wpiUtil.dll ${CONFIG_TYPE}/wpiUtil.dll) | ||
|
||
# Linux x64 | ||
create_move_target(CANBridge.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-x64/CANBridge.so ${CONFIG_TYPE}/CANBridge.so) | ||
create_move_target(wpiHal.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-x64/wpiHal.so ${CONFIG_TYPE}/wpiHal.so) | ||
create_move_target(wpiUtil.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-x64/wpiUtil.so ${CONFIG_TYPE}/wpiUtil.so) | ||
|
||
# Linux Arm 32 | ||
create_move_target(CANBridge.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm32/CANBridge.so ${CONFIG_TYPE}/CANBridge.so) | ||
create_move_target(wpiHal.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm32/wpiHal.so ${CONFIG_TYPE}/wpiHal.so) | ||
create_move_target(wpiUtil.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm32/wpiUtil.so ${CONFIG_TYPE}/wpiUtil.so) | ||
|
||
# Linux Arm 64 | ||
create_move_target(CANBridge.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm64/CANBridge.so ${CONFIG_TYPE}/CANBridge.so) | ||
create_move_target(wpiHal.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm64/wpiHal.so ${CONFIG_TYPE}/wpiHal.so) | ||
create_move_target(wpiUtil.so ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-linux-arm64/wpiUtil.so ${CONFIG_TYPE}/wpiUtil.so) | ||
|
||
# macOS | ||
create_move_target(CANBridge.dylib ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-darwin-osxuniversal/CANBridge.dylib ${CONFIG_TYPE}/CANBridge.dylib) | ||
create_move_target(wpiHal.dylib ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-darwin-osxuniversal/wpiHal.dylib ${CONFIG_TYPE}/wpiHal.dylib) | ||
create_move_target(wpiUtil.dylib ${CMAKE_CURRENT_SOURCE_DIR}/prebuilds/node_canbridge-darwin-osxuniversal/wpiUtil.dylib ${CONFIG_TYPE}/wpiUtil.dylib) | ||
endforeach() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
name: 'node_canbridge', | ||
napi_versions: [9], // Keep in sync with CMakeLists.txt, package.json binary.napi_version, and package.json prepublishOnly | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# This exists for pure-CMake builds, mainly useful for IDEs. | ||
function(setup_cmakejs) | ||
find_program(CMAKEJS "cmake-js") | ||
find_program(NPM "npm") | ||
# first, check if we have NPM: | ||
if(NPM) | ||
message(VERBOSE "NPM found.") | ||
else() | ||
message(FATAL_ERROR "NPM not found. This project requires Node.js") | ||
endif() | ||
|
||
if(CMAKEJS) | ||
message(VERBOSE "CMake.js found.") | ||
else() | ||
message(ERROR "CMake.js not found, installing globally...") | ||
execute_process(COMMAND ${NPM_COMMAND} install -g cmake-js | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE NPM_OUTPUT) | ||
message(STATUS "CMake.js should now be installed.") | ||
message(VERBOSE ${NPM_OUTPUT}) | ||
endif() | ||
|
||
|
||
if(WIN32) | ||
set(NPM_COMMAND ${NPM}.cmd) | ||
set(CMAKEJS_CMD ${CMAKEJS}.cmd) | ||
else() | ||
set(NPM_COMMAND ${NPM}) | ||
set(CMAKEJS_CMD ${CMAKEJS}) | ||
endif() | ||
|
||
function(GET_VARIABLE INPUT_STRING VARIABLE_TO_SELECT OUTPUT_VARIABLE) | ||
set(SEARCH_STRING "${VARIABLE_TO_SELECT}=\"") | ||
string(LENGTH "${SEARCH_STRING}" SEARCH_STRING_LENGTH) | ||
string(LENGTH "${INPUT_STRING}" INPUT_STRING_LENGTH) | ||
|
||
string(REPLACE "\\\\" "\\" INPUT_STRING "${INPUT_STRING}") | ||
|
||
string(FIND "${INPUT_STRING}" "${VARIABLE_TO_SELECT}=\"" SEARCH_STRING_INDEX) | ||
|
||
if(SEARCH_STRING_INDEX EQUAL -1) | ||
string(FIND "${INPUT_STRING}" "${VARIABLE_TO_SELECT}=" SEARCH_STRING_INDEX) | ||
|
||
math(EXPR SEARCH_STRING_INDEX "${SEARCH_STRING_INDEX}+${SEARCH_STRING_LENGTH}-1") | ||
|
||
string(SUBSTRING "${INPUT_STRING}" ${SEARCH_STRING_INDEX} ${INPUT_STRING_LENGTH} AFTER_SEARCH_STRING) | ||
string(FIND "${AFTER_SEARCH_STRING}" "'" QUOTE_INDEX) | ||
string(SUBSTRING "${AFTER_SEARCH_STRING}" "0" "${QUOTE_INDEX}" RESULT_STRING) | ||
set("${OUTPUT_VARIABLE}" "${RESULT_STRING}" PARENT_SCOPE) | ||
|
||
else() | ||
math(EXPR SEARCH_STRING_INDEX "${SEARCH_STRING_INDEX}+${SEARCH_STRING_LENGTH}") | ||
|
||
string(SUBSTRING "${INPUT_STRING}" ${SEARCH_STRING_INDEX} ${INPUT_STRING_LENGTH} AFTER_SEARCH_STRING) | ||
string(FIND "${AFTER_SEARCH_STRING}" "\"" QUOTE_INDEX) | ||
string(SUBSTRING "${AFTER_SEARCH_STRING}" "0" "${QUOTE_INDEX}" RESULT_STRING) | ||
set("${OUTPUT_VARIABLE}" "${RESULT_STRING}" PARENT_SCOPE) | ||
|
||
endif() | ||
endfunction(GET_VARIABLE) | ||
|
||
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) | ||
if (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") | ||
execute_process(COMMAND "${CMAKEJS_CMD}" print-configure --debug | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE CMAKE_JS_OUTPUT | ||
) | ||
else() | ||
execute_process(COMMAND "${CMAKEJS_CMD}" print-configure | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE CMAKE_JS_OUTPUT | ||
) | ||
endif () | ||
|
||
message(VERBOSE ${CMAKE_JS_OUTPUT}) | ||
|
||
get_variable("${CMAKE_JS_OUTPUT}" "CMAKE_JS_INC" CMAKE_JS_INC) | ||
set(CMAKE_JS_INC "${CMAKE_JS_INC}" PARENT_SCOPE) | ||
|
||
get_variable("${CMAKE_JS_OUTPUT}" "CMAKE_JS_LIB" CMAKE_JS_LIB) | ||
set(CMAKE_JS_LIB "${CMAKE_JS_LIB}" PARENT_SCOPE) | ||
|
||
get_variable("${CMAKE_JS_OUTPUT}" "CMAKE_LIBRARY_OUTPUT_DIRECTORY" CMAKE_LIBRARY_OUTPUT_DIRECTORY) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" PARENT_SCOPE) | ||
|
||
message(STATUS "[CMakeJS] Set up variables.") | ||
endfunction(setup_cmakejs) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
function (create_move_target name src dest) | ||
if(EXISTS ${src}) | ||
configure_file(${src} ${dest} COPYONLY) | ||
endif() | ||
endfunction() |
Oops, something went wrong.