summaryrefslogtreecommitdiff
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
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.
-rw-r--r--CMakeLists.txt21
-rw-r--r--cmake/mbgl.cmake60
-rw-r--r--cmake/shaders.cmake1
3 files changed, 61 insertions, 21 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59d84d33fc..92b0715b5e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,27 +3,6 @@ project(mbgl LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 14)
include(cmake/mbgl.cmake)
-
-if(NOT EXISTS ".mason/mason.cmake")
- execute_process(
- COMMAND git submodule update --init .mason
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
-endif()
-
-if(NOT EXISTS "mapbox-gl-js/package.json")
- execute_process(
- COMMAND git submodule update --init mapbox-gl-js
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
- # 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)
- execute_process(
- COMMAND npm install
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/mapbox-gl-js)
-endif()
-
include(.mason/mason.cmake)
option(WITH_CXX11ABI "Use cxx11abi mason packages" OFF)
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)
diff --git a/cmake/shaders.cmake b/cmake/shaders.cmake
index fc6575537a..a9ded80a6c 100644
--- a/cmake/shaders.cmake
+++ b/cmake/shaders.cmake
@@ -6,6 +6,7 @@ function(add_shader VAR name)
add_custom_command(
OUTPUT ${shader_source_prefix}/${name}.hpp
COMMAND ${shader_build_cmd} ${name} ${shader_file_prefix} ${shader_source_prefix}
+ DEPENDS npm-install
DEPENDS ${CMAKE_SOURCE_DIR}/scripts/build-shaders.js
DEPENDS ${shader_file_prefix}/${name}.vertex.glsl
DEPENDS ${shader_file_prefix}/${name}.fragment.glsl