diff --git a/CMakeLists.txt b/CMakeLists.txt index c25f4b8..0f52ece 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,31 @@ set(CMAKE_SYSTEM_PROCESSOR ${NODE_ARCH}) string(TOLOWER ${CMAKE_SYSTEM_NAME} PLATFORM) string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} ARCH) +# normalize platform to nodejs +string(REPLACE "windows" "win32" PLATFORM ${PLATFORM}) + +# normalize arch to nodejs: 'arm', 'arm64', 'ia32', 'loong64', 'mips', 'mipsel', 'ppc', 'ppc64', 'riscv64', 's390', 's390x', and 'x64'. +string(REPLACE "amd64" "x64" ARCH ${ARCH}) +string(REPLACE "x86_64" "x64" ARCH ${ARCH}) +string(REPLACE "i686" "ia32" ARCH ${ARCH}) +string(REPLACE "i386" "ia32" ARCH ${ARCH}) +string(REPLACE "armv7l" "arm" ARCH ${ARCH}) +string(REPLACE "arm" "arm" ARCH ${ARCH}) +string(REPLACE "arm64ex" "arm64" ARCH ${ARCH}) +string(REPLACE "aarch64" "arm64" ARCH ${ARCH}) + +if(DEFINED VARIANT) + set(VARIANT -${VARIANT}) +else() + set(VARIANT "") +endif() + +set(PLATFORM_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin/${PLATFORM}${VARIANT}/${ARCH}) + message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") message(STATUS "Platform: ${PLATFORM}") -message(STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR}") +message(STATUS "Architecture: ${ARCH}") +message(STATUS "PLATFORM_BINARY_DIR: ${PLATFORM_BINARY_DIR}") # set strip flags if(CMAKE_BUILD_TYPE STREQUAL "Release") @@ -45,34 +67,19 @@ add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC}) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} llama ggml common) -string(REPLACE "amd64" "x64" ARCH ${ARCH}) -string(REPLACE "x86_64" "x64" ARCH ${ARCH}) -string(REPLACE "i686" "x86" ARCH ${ARCH}) -string(REPLACE "i386" "x86" ARCH ${ARCH}) -string(REPLACE "arm" "arm" ARCH ${ARCH}) -string(REPLACE "aarch64" "arm64" ARCH ${ARCH}) - -if(DEFINED VARIANT) - set(VARIANT -${VARIANT}) -else() - set(VARIANT "") -endif() - -set(PLATFORM_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin/${PLATFORM}${VARIANT}/${ARCH}) -message(STATUS "PLATFORM_BINARY_DIR: ${PLATFORM_BINARY_DIR}") - 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}) # copy target to bin folder + get_filename_component(CMAKE_JS_NODELIB_TARGET_NAME ${CMAKE_JS_NODELIB_TARGET} NAME) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_JS_NODELIB_TARGET} ${PLATFORM_BINARY_DIR}/${CMAKE_JS_NODELIB_TARGET} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_JS_NODELIB_TARGET} ${PLATFORM_BINARY_DIR}/${CMAKE_JS_NODELIB_TARGET_NAME} COMMENT "Copying to bin folder" ) endif() # copy target to bin folder add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ ${PLATFORM_BINARY_DIR}/$ - COMMENT "Copying to bin folder" + COMMAND ${CMAKE_COMMAND} -E copy $ ${PLATFORM_BINARY_DIR}/$ + COMMENT "Copying to bin folder" )