summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-08-15 14:36:16 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-08-16 15:29:34 +0200
commit51391740bf324fd7131f069d1d2d106113560df3 (patch)
tree93b93bd806525966b531ed8d7b1aeeee43705058
parent4e211548d5029a353aaa8814c40599970a8098bd (diff)
downloadqtlocation-mapboxgl-51391740bf324fd7131f069d1d2d106113560df3.tar.gz
[build] convert build-shaders script from Python to Node.js
-rw-r--r--CMakeLists.txt2
-rw-r--r--Makefile1
-rw-r--r--cmake/mbgl.cmake11
-rw-r--r--cmake/node.cmake10
-rw-r--r--cmake/npm.cmake20
-rw-r--r--cmake/shaders.cmake2
-rw-r--r--cmake/test.cmake4
-rw-r--r--package.json1
-rwxr-xr-xscripts/build-shaders.js71
-rwxr-xr-xscripts/build-shaders.py76
10 files changed, 86 insertions, 112 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0421ad52c0..3489f6cd4f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,8 +11,6 @@ endif()
include(.mason/mason.cmake)
-include(cmake/npm.cmake)
-
option(WITH_CXX11ABI "Use cxx11abi mason packages" OFF)
option(WITH_COVERAGE "Enable coverage reports" OFF)
diff --git a/Makefile b/Makefile
index 70a2cfefe6..980b45f676 100644
--- a/Makefile
+++ b/Makefile
@@ -57,6 +57,7 @@ node_modules: package.json
BUILD_DEPS += .mason/mason
BUILD_DEPS += Makefile
BUILD_DEPS += node_modules
+BUILD_DEPS += CMakeLists.txt
#### macOS targets ##############################################################
diff --git a/cmake/mbgl.cmake b/cmake/mbgl.cmake
index c73127ab3f..f20f49004c 100644
--- a/cmake/mbgl.cmake
+++ b/cmake/mbgl.cmake
@@ -12,6 +12,17 @@ endif()
set(MBGL_GENERATED ${CMAKE_BINARY_DIR}/generated/${CMAKE_CFG_INTDIR})
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/node_modules/node-cmake/FindNodeJS.cmake)
+ message(FATAL_ERROR "Can't find node-cmake")
+endif()
+
+# Load Node.js
+set(NodeJS_CXX_STANDARD 14 CACHE INTERNAL "Use C++14" FORCE)
+set(NodeJS_DOWNLOAD ON CACHE INTERNAL "Download node.js sources" FORCE)
+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)
+
# 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/node.cmake b/cmake/node.cmake
index 081b158d41..034216b617 100644
--- a/cmake/node.cmake
+++ b/cmake/node.cmake
@@ -1,13 +1,3 @@
-if(NOT EXISTS ${CMAKE_SOURCE_DIR}/node_modules/node-cmake/FindNodeJS.cmake)
- message(FATAL_ERROR "Can't find node-cmake")
-endif()
-
-set(NodeJS_CXX_STANDARD 14 CACHE INTERNAL "Use C++14" FORCE)
-set(NodeJS_DOWNLOAD ON CACHE INTERNAL "Download node.js sources" FORCE)
-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)
-
add_nodejs_module(mbgl-node
platform/node/src/node_mapbox_gl_native.cpp
)
diff --git a/cmake/npm.cmake b/cmake/npm.cmake
deleted file mode 100644
index bb456666e2..0000000000
--- a/cmake/npm.cmake
+++ /dev/null
@@ -1,20 +0,0 @@
-function(cache_executable_path name variable)
- # Obtain paths to node and npm and cache it, so when e.g. Xcode reruns CMake, we still have the
- # variables from the original invocation
- if(NOT ${variable})
- set(_which_output)
- execute_process(
- COMMAND which ${name}
- OUTPUT_VARIABLE _which_output
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- if(_which_output STREQUAL "")
- message(STATUS "Using cached ${name}: ${${variable}}")
- else()
- set(${variable} "${_which_output}" CACHE PATH "Path to ${name} executable")
- message(STATUS "Using ${name}: ${${variable}}")
- endif()
- endif()
-endfunction()
-
-cache_executable_path(node _node)
-cache_executable_path(npm _npm)
diff --git a/cmake/shaders.cmake b/cmake/shaders.cmake
index 5a16fa682f..5495f5b281 100644
--- a/cmake/shaders.cmake
+++ b/cmake/shaders.cmake
@@ -1,5 +1,5 @@
function(add_shader VAR name)
- set(shader_build_cmd ${CMAKE_SOURCE_DIR}/scripts/build-shaders.py)
+ set(shader_build_cmd ${NodeJS_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/build-shaders.js)
set(shader_file_prefix ${CMAKE_SOURCE_DIR}/node_modules/mapbox-gl-shaders/src)
set(shader_source_prefix ${MBGL_GENERATED}/include/mbgl/shader)
diff --git a/cmake/test.cmake b/cmake/test.cmake
index 6cce8d248d..29975662ce 100644
--- a/cmake/test.cmake
+++ b/cmake/test.cmake
@@ -2,13 +2,11 @@ add_executable(mbgl-test
${MBGL_TEST_FILES}
)
-cache_executable_path(node _node)
-
target_compile_options(mbgl-test
PRIVATE -fvisibility-inlines-hidden
)
-set_source_files_properties(test/src/mbgl/test/util.cpp PROPERTIES COMPILE_FLAGS -DNODE_EXECUTABLE="${_node}")
+set_source_files_properties(test/src/mbgl/test/util.cpp PROPERTIES COMPILE_FLAGS -DNODE_EXECUTABLE="${NodeJS_EXECUTABLE}")
target_include_directories(mbgl-test
PRIVATE include
diff --git a/package.json b/package.json
index d7e07288f8..68775b37b0 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#de2ab007455aa2587c552694c68583f94c9f2747",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#83b1a3e5837d785af582efd5ed1a212f2df6a4ae",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#7babab52fb02788ebbc38384139bf350e8e38552",
+ "mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"request": "^2.72.0",
"tape": "^4.5.1"
diff --git a/scripts/build-shaders.js b/scripts/build-shaders.js
new file mode 100755
index 0000000000..9090f19e6d
--- /dev/null
+++ b/scripts/build-shaders.js
@@ -0,0 +1,71 @@
+#!/usr/bin/env node
+
+var path = require('path');
+var fs = require('fs');
+var mkdirp = require('mkdirp');
+
+var input_file = process.argv[2]
+var output_file = process.argv[3];
+
+if (!input_file || !output_file) {
+ console.warn('No input or output file given.');
+ console.warn('Usage: %s [input.vertex.glsl] [output.vertex.hpp]', path.basename(process.argv[1]));
+ process.exit(1);
+}
+
+var components = path.basename(input_file).split('.');
+
+var shader_name = components[0];
+var shader_type = components[1];
+var extension = components[2];
+
+var data = fs.readFileSync(input_file, 'utf8');
+
+// Replace uniform pragmas
+
+var pragma_mapbox_regex = /(\s*)#pragma\s+mapbox\s*:\s+(define|initialize)\s+(low|medium|high)p\s+(float|vec(?:2|3|4))\s+(.*)/;
+
+var data = data.split('\n').map(function(line) {
+ var params = line.match(pragma_mapbox_regex);
+ if (params) {
+ if (params[2] === 'define') {
+ return params[1] + 'uniform ' + params[3] + 'p ' + params[4] + ' u_' + params[5] + ';';
+ } else {
+ return params[1] + params[3] + 'p ' + params[4] + ' ' + params[5] + ' = u_' + params[5] + ';';
+ }
+ } else {
+ return line;
+ }
+}).join('\n');
+
+
+var content =
+ '#pragma once\n' +
+ '\n' +
+ '// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n' +
+ '\n' +
+ '#include <mbgl/gl/gl.hpp>\n' +
+ '\n' +
+ 'namespace mbgl {\n' +
+ 'namespace shaders {\n' +
+ 'namespace ' + shader_name + ' {\n' +
+ '\n' +
+ '#ifndef MBGL_SHADER_NAME_' + shader_name.toUpperCase() + '\n' +
+ '#define MBGL_SHADER_NAME_' + shader_name.toUpperCase() + '\n' +
+ 'constexpr const char* name = "' + shader_name + '";\n' +
+ '#endif // MBGL_SHADER_NAME_' + shader_name.toUpperCase() + '\n' +
+ '\n' +
+ 'constexpr const char* ' + shader_type + ' =\n' +
+ '#ifdef GL_ES_VERSION_2_0\n' +
+ ' "precision highp float;"\n' +
+ '#else\n' +
+ ' "#version 120"\n' +
+ '#endif\n' +
+ ' R"MBGL_SHADER(\n' + data + ')MBGL_SHADER";\n' +
+ '\n' +
+ '} // namespace ' + shader_name + '\n' +
+ '} // namespace shaders\n' +
+ '} // namespace mbgl\n';
+
+mkdirp.sync(path.dirname(output_file));
+fs.writeFileSync(output_file, content);
diff --git a/scripts/build-shaders.py b/scripts/build-shaders.py
deleted file mode 100755
index d679172554..0000000000
--- a/scripts/build-shaders.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-
-import sys, re, os, errno
-
-input_file = sys.argv[1]
-output_file = sys.argv[2]
-
-def mkdir_p(path):
- try:
- os.makedirs(path)
- except OSError as exc: # Python >2.5
- if exc.errno == errno.EEXIST and os.path.isdir(path):
- pass
- else: raise
-
-shader_name, shader_type, extension = os.path.basename(input_file).split('.')
-
-with open(input_file, "r") as f:
- data = f.read()
-
-# Replace uniform pragmas
-
-pragma_mapbox_regex = re.compile("(\s*)\#pragma \mapbox\: (define|initialize) (low|medium|high)p (float|vec(2|3|4)) (.*)")
-
-def replace_uniform_pragmas(line):
- if pragma_mapbox_regex.match(line):
- params = line.split()
- if params[2] == "define":
- return """uniform {u_precision} {u_type} u_{u_name};""".format(
- u_precision = params[3],
- u_type = params[4],
- u_name = params[5])
- else:
- return """ {u_precision} {u_type} {u_name} = u_{u_name};""".format(
- u_precision = params[3],
- u_type = params[4],
- u_name = params[5])
- else:
- return line
-
-data = "\n".join([replace_uniform_pragmas(line) for line in data.split("\n")])
-
-content = """#pragma once
-
-// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
-
-#include <mbgl/gl/gl.hpp>
-
-namespace mbgl {{
-namespace shaders {{
-namespace {name} {{
-
-#ifndef MBGL_SHADER_NAME_{NAME}
-#define MBGL_SHADER_NAME_{NAME}
-constexpr const char* name = "{name}";
-#endif // MBGL_SHADER_NAME_{NAME}
-
-#ifdef GL_ES_VERSION_2_0
-constexpr const char* {type} = R"MBGL_SHADER(precision highp float;\n{data})MBGL_SHADER";
-#else
-constexpr const char* {type} = R"MBGL_SHADER(#version 120\n{data})MBGL_SHADER";
-#endif
-
-}} // namespace {name}
-}} // namespace shaders
-}} // namespace mbgl
-""".format(
- name = shader_name,
- NAME = shader_name.upper(),
- type = shader_type,
- TYPE = shader_type.upper(),
- data = data,
-)
-
-mkdir_p(os.path.dirname(output_file))
-with open(output_file, 'w') as f: f.write(content)