Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(cmake): Extract CMake project name and version from package.json. #45

Merged
merged 6 commits into from
Dec 29, 2024
31 changes: 29 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,39 @@ Emscripten.cmake"
)
endif()

# Extract the project name & version from package.json
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/package.json")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.json" PACKAGE_JSON_CONTENT)
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
else()
message(FATAL_ERROR "`package.json` not found in ${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(${PACKAGE_JSON_CONTENT} MATCHES "\"name\":[ ]*\"([^\"]+)\"")
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
set(CLP_FFI_JS_PROJECT_NAME
${CMAKE_MATCH_1}
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
CACHE STRING
"The name of the project parsed from `package.json`."
FORCE
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
)
else()
set(CLP_FFI_JS_PROJECT_NAME "clp-ffi-js" CACHE STRING "Use a placeholder project name." FORCE)
endif()
if(${PACKAGE_JSON_CONTENT} MATCHES "\"version\":[ ]*\"([^\"]+)\"")
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
set(CLP_FFI_JS_VERSION
${CMAKE_MATCH_1}
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
CACHE STRING
"The version of the project parsed from `package.json`."
FORCE
)
else()
set(CLP_FFI_JS_VERSION "0.0.0" CACHE STRING "Use a placeholder version." FORCE)
endif()

project(
clp-ffi-js
${CLP_FFI_JS_PROJECT_NAME}
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
LANGUAGES
C
CXX
VERSION 0.3.1
VERSION "${CLP_FFI_JS_VERSION}"
)

# Enable exporting compile commands
Expand Down
Loading