summaryrefslogtreecommitdiff
path: root/cmake/mbgl.cmake
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-01-18 11:57:27 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-01-19 10:50:07 +0100
commitdbd7186bc55e801e4541b5d3ecb9181224ea667c (patch)
tree2546e8e1bd33a9f383b572da06fe253df6225af8 /cmake/mbgl.cmake
parenta2ceeb4a5b7a8db4bbd852c5e51085d9220a5c3d (diff)
downloadqtlocation-mapboxgl-dbd7186bc55e801e4541b5d3ecb9181224ea667c.tar.gz
[build] Run submodule update on every build, and npm install when the package.json changed
We're now running a submodule update as part of every build, and when the project files are generated. We also run an npm install whenever the package.json was updated, both during project generation and as part of every build.
Diffstat (limited to 'cmake/mbgl.cmake')
-rw-r--r--cmake/mbgl.cmake60
1 files changed, 60 insertions, 0 deletions
diff --git a/cmake/mbgl.cmake b/cmake/mbgl.cmake
index b2b959e6c1..4002257bb4 100644
--- a/cmake/mbgl.cmake
+++ b/cmake/mbgl.cmake
@@ -23,6 +23,66 @@ set(NodeJS_USE_CLANG_STDLIB OFF CACHE BOOL "Don't use libc++ by default" FORCE)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/node_modules/node-cmake)
find_package(NodeJS)
+find_program(npm_EXECUTABLE
+ NAMES npm
+ PATHS ${NodeJS_ROOT_DIR})
+
+if (NOT npm_EXECUTABLE)
+ message(FATAL_ERROR "Could not find npm")
+endif()
+
+function(_npm_install DIRECTORY NAME ADDITIONAL_DEPS)
+ SET(NPM_INSTALL_FAILED FALSE)
+ if("${DIRECTORY}/package.json" IS_NEWER_THAN "${DIRECTORY}/node_modules/.${NAME}.stamp")
+ message(STATUS "Running 'npm install' for ${NAME}...")
+ execute_process(
+ COMMAND ${NodeJS_EXECUTABLE} ${npm_EXECUTABLE} install --ignore-scripts
+ WORKING_DIRECTORY "${DIRECTORY}"
+ RESULT_VARIABLE NPM_INSTALL_FAILED)
+ if(NOT NPM_INSTALL_FAILED)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E touch "${DIRECTORY}/node_modules/.${NAME}.stamp")
+ endif()
+ endif()
+
+ add_custom_command(
+ OUTPUT "${DIRECTORY}/node_modules/.${NAME}.stamp"
+ COMMAND ${NodeJS_EXECUTABLE} ${npm_EXECUTABLE} install --ignore-scripts
+ COMMAND ${CMAKE_COMMAND} -E touch "${DIRECTORY}/node_modules/.${NAME}.stamp"
+ WORKING_DIRECTORY "${DIRECTORY}"
+ DEPENDS ${ADDITIONAL_DEPS} "${DIRECTORY}/package.json"
+ COMMENT "Running 'npm install' for ${NAME}...")
+endfunction()
+
+# Run submodule update
+message(STATUS "Updating submodules...")
+execute_process(
+ COMMAND git submodule update --init .mason mapbox-gl-js
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+if(NOT EXISTS "${CMAKE_SOURCE_DIR}/mapbox-gl-js/node_modules")
+ # Symlink mapbox-gl-js/node_modules so that the modules that are
+ # about to be installed get cached between CI runs.
+ execute_process(
+ COMMAND ln -sF ../node_modules .
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mapbox-gl-js")
+endif()
+
+# Add target for running submodule update during builds
+add_custom_target(
+ update-submodules ALL
+ COMMAND git submodule update --init .mason mapbox-gl-js
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+ COMMENT "Updating submodules..."
+)
+
+# Run npm install for both directories, and add custom commands, and a target that depends on them.
+_npm_install("${CMAKE_SOURCE_DIR}" mapbox-gl-native update-submodules)
+_npm_install("${CMAKE_SOURCE_DIR}/mapbox-gl-js" mapbox-gl-js "${CMAKE_SOURCE_DIR}/node_modules/.mapbox-gl-native.stamp")
+add_custom_target(
+ npm-install ALL
+ DEPENDS "${CMAKE_SOURCE_DIR}/node_modules/.mapbox-gl-js.stamp"
+)
+
# Generate source groups so the files are properly sorted in IDEs like Xcode.
function(create_source_groups target)
get_target_property(sources ${target} SOURCES)