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

Move to CMake based build system #140

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*tgz
build
lib/binding
lib/*.node
mason_packages
node_modules
npm-debug.log
Expand Down
21 changes: 21 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[submodule "vendor/node-api-headers"]
path = vendor/node-api-headers
url = [email protected]:nodejs/node-api-headers.git
[submodule "vendor/node-addon-api"]
path = vendor/node-addon-api
url = [email protected]:nodejs/node-addon-api.git
[submodule "vendor/geometry-hpp-internal"]
path = vendor/geometry-hpp-internal
url = [email protected]:mapbox/geometry-hpp-internal.git
[submodule "vendor/spatial-algorithms"]
path = vendor/spatial-algorithms
url = [email protected]:mapbox/spatial-algorithms.git
[submodule "vendor/protozero"]
path = vendor/protozero
url = [email protected]:mapbox/protozero.git
[submodule "vendor/vtzero"]
path = vendor/vtzero
url = [email protected]:mapbox/vtzero.git
[submodule "vendor/gzip-hpp"]
path = vendor/gzip-hpp
url = [email protected]:mapbox/gzip-hpp.git
92 changes: 92 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
cmake_policy(SET CMP0167 OLD)
project("vtcomposite" LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

add_compile_options(-Wall -Wextra -Werror -pedantic -Wshadow -Wsign-compare -Wfloat-equal -Wconversion -Wunused-parameter)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
add_compile_options(-Wno-unsequenced -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-exit-time-destructors)
endif()

find_package(Boost 1.73 REQUIRED)
add_library(vendor-boost INTERFACE)
target_include_directories(vendor-boost INTERFACE ${Boost_INCLUDE_DIR})
target_link_libraries(vendor-boost INTERFACE ${Boost_LIBRARIES})

include(${PROJECT_SOURCE_DIR}/vendor/geometry.hpp.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/gzip.hpp.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/spatial-algorithms.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/protozero.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/vtzero.cmake)

find_program(NODEJS_EXECUTABLE NAMES node nodejs)

if ("${NODEJS_EXECUTABLE}" MATCHES "NOTFOUND")
message(FATAL_ERROR "Could not find Node.js")
endif()

if(NOT NODE_PLATFORM_ARCH_SLUG)
execute_process(
COMMAND "${NODEJS_EXECUTABLE}" -p "process.platform + '-' + process.arch"
OUTPUT_VARIABLE NODE_PLATFORM_ARCH_SLUG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

add_library(vtcomposite SHARED
src/module.cpp
src/feature_builder.hpp
src/module_utils.hpp
src/vtcomposite.cpp
src/vtcomposite.hpp
src/zxy_math.hpp
)

target_include_directories(
vtcomposite
PRIVATE
${PROJECT_SOURCE_DIR}/vendor/node-api-headers/include
${PROJECT_SOURCE_DIR}/vendor/node-addon-api
)

target_link_libraries(vtcomposite
PRIVATE vendor-protozero
vendor-vtzero
vendor-geometry.hpp
vendor-gzip.hpp
vendor-spatial-algorithms
vendor-boost)

set_target_properties(
vtcomposite
PROPERTIES
PREFIX ""
OUTPUT_NAME "vtcomposite-${NODE_PLATFORM_ARCH_SLUG}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib/$<0:>"
SUFFIX ".node"
)

target_compile_definitions(
vtcomposite
PRIVATE
NAPI_VERSION=7
NODE_ADDON_API_DISABLE_DEPRECATED
)

# Ensures that linked symbols are loaded when the module is loaded
# instead of causing unresolved symbol errors later during runtime.
if(APPLE)
set_target_properties(
vtcomposite
PROPERTIES LINK_FLAGS "-undefined dynamic_lookup -bind_at_load -Xlinker -dead_strip -Xlinker -exported_symbols_list -Xlinker ${CMAKE_CURRENT_SOURCE_DIR}/cmake/symbols.txt"
)
else()
set_target_properties(
vtcomposite
PROPERTIES LINK_FLAGS "-z now -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/cmake/symbols.ld"
)
endif()
6 changes: 6 additions & 0 deletions cmake/symbols.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VERSION {
global:
_napi_register_module_v1;
local:
*;
};
1 change: 1 addition & 0 deletions cmake/symbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_napi_register_module_v1
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use strict";

module.exports.composite = require('./binding/vtcomposite.node').composite;
module.exports.localize = require('./binding/vtcomposite.node').localize;
module.exports = require(`./vtcomposite-${process.platform}-${process.arch}.node`);
12 changes: 12 additions & 0 deletions src/feature_builder.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#pragma once

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wc++11-narrowing"
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#pragma GCC diagnostic ignored "-Wfloat-conversion"
#pragma GCC diagnostic ignored "-Wunused-parameter"

// geometry.hpp
#include <mapbox/geometry.hpp>
#include <mapbox/geometry/algorithms/detail/boost_adapters.hpp>
Expand All @@ -9,6 +18,9 @@
// boost
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/intersects.hpp>

#pragma GCC diagnostic pop

// stl
#include <algorithm>
//BOOST_GEOMETRY_REGISTER_POINT_2D(mapbox::geometry::point<int>, int, boost::geometry::cs::cartesian, x, y)
Expand Down
4 changes: 4 additions & 0 deletions src/vtcomposite.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#include <napi.h>
#pragma GCC diagnostic pop

namespace vtile {

Expand Down
1 change: 1 addition & 0 deletions vendor/geometry-hpp-internal
Submodule geometry-hpp-internal added at a0404b
9 changes: 9 additions & 0 deletions vendor/geometry.hpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(TARGET vendor-geometry.hpp)
return()
endif()

add_library(vendor-geometry.hpp INTERFACE)

target_include_directories(
vendor-geometry.hpp
INTERFACE ${PROJECT_SOURCE_DIR}/vendor/geometry-hpp-internal/include)
1 change: 1 addition & 0 deletions vendor/gzip-hpp
Submodule gzip-hpp added at 7546b3
9 changes: 9 additions & 0 deletions vendor/gzip.hpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(TARGET vendor-gzip.hpp)
return()
endif()

add_library(vendor-gzip.hpp INTERFACE)

target_include_directories(
vendor-gzip.hpp
INTERFACE ${PROJECT_SOURCE_DIR}/vendor/gzip-hpp/include)
1 change: 1 addition & 0 deletions vendor/node-addon-api
Submodule node-addon-api added at 5b1a57
1 change: 1 addition & 0 deletions vendor/node-api-headers
Submodule node-api-headers added at 129454
1 change: 1 addition & 0 deletions vendor/protozero
Submodule protozero added at 542fcf
9 changes: 9 additions & 0 deletions vendor/protozero.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(TARGET vendor-protozero)
return()
endif()

add_library(vendor-protozero INTERFACE)

target_include_directories(
vendor-protozero
INTERFACE ${PROJECT_SOURCE_DIR}/vendor/protozero/include)
1 change: 1 addition & 0 deletions vendor/spatial-algorithms
Submodule spatial-algorithms added at 1762b6
9 changes: 9 additions & 0 deletions vendor/spatial-algorithms.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(TARGET vendor-spatial-algorithms)
return()
endif()

add_library(vendor-spatial-algorithms INTERFACE)

target_include_directories(
vendor-spatial-algorithms
INTERFACE ${PROJECT_SOURCE_DIR}/vendor/spatial-algorithms/include)
1 change: 1 addition & 0 deletions vendor/vtzero
Submodule vtzero added at 67f934
9 changes: 9 additions & 0 deletions vendor/vtzero.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(TARGET vendor-vtzero)
return()
endif()

add_library(vendor-vtzero INTERFACE)

target_include_directories(
vendor-vtzero
INTERFACE ${PROJECT_SOURCE_DIR}/vendor/vtzero/include)