Skip to content

Commit

Permalink
chore: Refactor build
Browse files Browse the repository at this point in the history
* [graphviz](https://www.graphviz.org/) - v5.0.0
* [expat](https://libexpat.github.io/) - v2.4.8
* [emsdk](https://github.com/emscripten-core/emsdk) - v3.1.15

Use vcpkgs when possible
Clean up cmake file structure

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Jul 8, 2022
1 parent 6dfe196 commit c6e6f1e
Show file tree
Hide file tree
Showing 59 changed files with 945 additions and 402 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
scripts/cpp-build.sh eol=lf
scripts/cpp-install-emsdk.sh eol=lf
scripts/cpp-install-expat.sh eol=lf
scripts/cpp-install-graphviz.sh eol=lf
scripts/cpp-update-emsdk.sh eol=lf
scripts/cpp-install-vcpkg.sh eol=lf
25 changes: 13 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/.nyc_output
.vscode/ipch
build/
dist/
emsdk/
src-expat/
src-graphviz/
lib-*/
node_modules/
types/
/build
/coverage
/dist
/emsdk*
/src-expat
/src-graphviz
/lib-*
/node_modules
/types
/vcpkg
*.tsbuildinfo
.nyc_output/
coverage/
.vscode/c_cpp_properties.json
.vscode/settings.json
/.vscode/c_cpp_properties.json
/.vscode/settings.json
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "helloworld.html",
"type": "pwa-msedge",
"request": "launch",
"url": "file://${workspaceRoot}/helloworld.html",
"url": "http://localhost:8000/helloworld.html",
"webRoot": "${workspaceRoot}"
},
{
Expand Down
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.9.2)

PROJECT(cpp)

SET(CMAKE_INSTALL_PREFIX "..")
SET(VCPKG_INCLUDE_DIR ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include)

# See: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
SET(EM_FLAGS
"-s ASSERTIONS=0"
"-s INVOKE_RUN=0"
"-s ALLOW_MEMORY_GROWTH=1"
"-s WASM=1"
"-s MODULARIZE"
"-s ENVIRONMENT=web,worker,node"
"-s FILESYSTEM=0"
"-s MINIMAL_RUNTIME=2"
"-s MODULARIZE=1"
"-s EXPORT_ES6=1"
"-s IGNORE_CLOSURE_COMPILER_ERRORS=0"
"-s USE_ES6_IMPORT_META=0"
"--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/pre.js"
"--post-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/post.js"
)

IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(EM_FLAGS
${EM_FLAGS}
"-gsource-map"
"--source-map-base ${CMAKE_CURRENT_SOURCE_DIR}"
)
ENDIF()

SET(EMSDK_DIR "${CMAKE_SOURCE_DIR}/emsdk")
SET(EXPAT_DIR "${CMAKE_SOURCE_DIR}/src-expat/expat")
SET(GRAPHVIZ_DIR "${CMAKE_SOURCE_DIR}/src-graphviz")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

ADD_SUBDIRECTORY(cpp)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,5 @@ This has been made a manual step as the downloads are quite large and the auto-c
### Clean dependencies:
_It is worth noting that `npm run clean` will only clean any artifacts associated with the build, but won't clean clean any of the third party dependencies. To remove those for a "full clean", run:_
```
npm run clean-build-deps
npm run uninstall-build-deps
```
10 changes: 0 additions & 10 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.9.2)

PROJECT(cpp)

SET(CMAKE_INSTALL_PREFIX "..")

SET(EMSDK_DIR "${CMAKE_SOURCE_DIR}/../emsdk")
SET(EXPAT_DIR "${CMAKE_SOURCE_DIR}/../src-expat/expat")
SET(GRAPHVIZ_DIR "${CMAKE_SOURCE_DIR}/../src-graphviz")

ADD_SUBDIRECTORY(expat)
ADD_SUBDIRECTORY(graphviz)
19 changes: 0 additions & 19 deletions cpp/expat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
set(CMAKE_CXX_STANDARD 17)

SET(EXPAT_LIB_DIR "${EXPAT_DIR}/lib")

ADD_DEFINITIONS(-DXML_POOR_ENTROPY)

INCLUDE_DIRECTORIES(
${EXPAT_LIB_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

ADD_LIBRARY(expat STATIC
${EXPAT_LIB_DIR}/xmlparse.c
${EXPAT_LIB_DIR}/xmlrole.c
${EXPAT_LIB_DIR}/xmltok_impl.c
${EXPAT_LIB_DIR}/xmltok_ns.c
${EXPAT_LIB_DIR}/xmltok.c
)

ADD_SUBDIRECTORY(expatlib)
37 changes: 19 additions & 18 deletions cpp/expat/expatlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
PROJECT(expatlib)

SET(EM_FLAGS "-s WASM=1 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME='${CMAKE_PROJECT_NAME}' -s EXPORTED_FUNCTIONS=\"['_malloc']\" --post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js")
find_package(expat CONFIG REQUIRED)

# See: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
SET(EM_FLAGS
${EM_FLAGS}
"-s FILESYSTEM=1"
"-s EXPORT_NAME='${CMAKE_PROJECT_NAME}'"
"-s EXPORTED_FUNCTIONS=\"['_malloc']\""
"-s EXPORTED_RUNTIME_METHODS=\"[]\""
"--post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js"
)
STRING(REPLACE ";" " " LINK_FLAGS "${EM_FLAGS}")

# Generate Glue from IDL file ---
ADD_CUSTOM_COMMAND(
Expand All @@ -12,32 +23,22 @@ SET_PROPERTY(SOURCE main.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINA
# --- --- ---

INCLUDE_DIRECTORIES(
${VCPKG_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${EXPAT_LIB_DIR}
)

ADD_EXECUTABLE(expatlib
main.cpp
)

SET_TARGET_PROPERTIES(expatlib PROPERTIES LINK_FLAGS "-s ENVIRONMENT=web ${EM_FLAGS}")
SET_TARGET_PROPERTIES(expatlib PROPERTIES LINK_FLAGS ${LINK_FLAGS})

TARGET_LINK_LIBRARIES(expatlib
expat
)

ADD_EXECUTABLE(expatlib.node
main.cpp
expat::expat
)

SET_TARGET_PROPERTIES(expatlib.node PROPERTIES LINK_FLAGS "-s ENVIRONMENT=node ${EM_FLAGS}")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/expatlib.wasm DESTINATION dist COMPONENT runtime)

TARGET_LINK_LIBRARIES(expatlib.node
expat
)

INSTALL(FILES
${CMAKE_CURRENT_BINARY_DIR}/expatlib.wasm
DESTINATION dist
COMPONENT runtime
)
IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/expatlib.wasm.map DESTINATION dist COMPONENT runtime)
ENDIF ()
4 changes: 2 additions & 2 deletions cpp/expat/expatlib/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../config.h"
#include "stack_parser.h"

#include <string>
#include <expat.h>

class CExpat : public CExpatImpl<CExpat>
{
Expand All @@ -16,7 +16,7 @@ class CExpat : public CExpatImpl<CExpat>
public:
static const char *version()
{
return PACKAGE_VERSION;
return XML_ExpatVersion();
}

CExpat()
Expand Down
68 changes: 48 additions & 20 deletions cpp/graphviz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
PROJECT(graphlayout)

find_package(expat CONFIG REQUIRED)

SET(GRAPHVIZ_LIB_DIR "${GRAPHVIZ_DIR}/lib")
SET(GRAPHVIZ_PLUGIN_DIR "${GRAPHVIZ_DIR}/plugin")
SET(GRAPHVIZ_BUILD_DIR "${GRAPHVIZ_DIR}/build")

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${VCPKG_INCLUDE_DIR}
)

option(enable_ltdl "Support on-demand plugin loading" OFF)
Expand All @@ -18,30 +21,55 @@ option(with_smyrna "SMYRNA large graph viewer (disabled by default - experim
option(with_zlib "Support raster image compression through zlib" OFF)
option(use_sanitizers "enables using address and undefined behavior sanitizer" OFF)
option(use_coverage "enables analyzing code coverage" OFF)
option(with_cxx_api "enables building the C++ API" OFF)
option(with_cxx_api "enables building the C++ API" ON)
option(with_cxx_tests "enables building the C++ tests" OFF)
option(use_win_pre_inst_libs "enables building using pre-installed Windows libraries" ON)

if(with_digcola)
add_definitions(-DDIGCOLA)
endif()

if(with_ipsepcola)
add_definitions(-DIPSEPCOLA)
endif()

if(with_ortho)
add_definitions(-DORTHO)
endif()

if(with_sfdp)
add_definitions(-DSFDP)
endif()

# ===================== Append local CMake module directory ====================
list(APPEND CMAKE_MODULE_PATH "${GRAPHVIZ_DIR}/cmake")

# find_package(ANN)

# find_package(CAIRO)

if (with_digcola)
add_definitions(-DDIGCOLA)
endif (with_digcola)
if(with_expat)
find_package(EXPAT)
endif()

if (with_ipsepcola)
add_definitions(-DIPSEPCOLA)
endif (with_ipsepcola)
# find_package(GD)

if (with_ortho)
add_definitions(-DORTHO)
endif (with_ortho)
if(enable_ltdl)
find_package(LTDL)
if(LTDL_FOUND)
add_definitions(-DENABLE_LTDL)
endif()
endif()

if (with_sfdp)
add_definitions(-DSFDP)
endif (with_sfdp)
# find_package(PANGOCAIRO)

if (with_smyrna)
# TODO include dependency checks
add_definitions(-DSMYRNA)
endif (with_smyrna)
if(with_zlib)
find_package(ZLIB)
endif()

ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(plugin)
ADD_SUBDIRECTORY(graphvizlib)
# if(UNIX)
# find_library(MATH_LIB m)
# endif()
add_subdirectory(lib)
add_subdirectory(plugin)
add_subdirectory(graphvizlib)
44 changes: 18 additions & 26 deletions cpp/graphviz/graphvizlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
PROJECT(graphvizlib)

SET(EM_FLAGS "-s WASM=1 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME='${CMAKE_PROJECT_NAME}' -s EXPORTED_FUNCTIONS=\"['_free']\" --post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js")
# See: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
SET(EM_FLAGS
${EM_FLAGS}
"-s EXPORT_NAME='${CMAKE_PROJECT_NAME}'"
"-s EXPORTED_FUNCTIONS=\"[_free]\""
"-s EXPORTED_RUNTIME_METHODS=\"[]\""
"--post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js"
)
STRING(REPLACE ";" " " LINK_FLAGS "${EM_FLAGS}")

# Generate Glue from IDL file ---
ADD_CUSTOM_COMMAND(
Expand All @@ -20,8 +28,10 @@ INCLUDE_DIRECTORIES(
${GRAPHVIZ_LIB_DIR}
${GRAPHVIZ_LIB_DIR}/cdt
${GRAPHVIZ_LIB_DIR}/cgraph
${GRAPHVIZ_LIB_DIR}/cgraph++
${GRAPHVIZ_LIB_DIR}/common
${GRAPHVIZ_LIB_DIR}/gvc
${GRAPHVIZ_LIB_DIR}/gvc++
${GRAPHVIZ_LIB_DIR}/pathplan
${GRAPHVIZ_LIB_DIR}/sparse
)
Expand All @@ -30,36 +40,18 @@ ADD_EXECUTABLE(graphvizlib
${SRCS}
)

SET_TARGET_PROPERTIES(graphvizlib PROPERTIES LINK_FLAGS "-s ENVIRONMENT=web ${EM_FLAGS}")
message("EM_FLAGS: ${EM_FLAGS}")
SET_TARGET_PROPERTIES(graphvizlib PROPERTIES LINK_FLAGS ${LINK_FLAGS})

TARGET_LINK_LIBRARIES(graphvizlib
TARGET_LINK_LIBRARIES(graphvizlib PRIVATE
gvplugin_core
gvplugin_dot_layout
gvplugin_neato_layout
common
label
ortho
pack
)

ADD_EXECUTABLE(graphvizlib.node
${SRCS}
)

SET_TARGET_PROPERTIES(graphvizlib.node PROPERTIES LINK_FLAGS "-s ENVIRONMENT=node ${EM_FLAGS}")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphvizlib.wasm DESTINATION dist COMPONENT runtime)

TARGET_LINK_LIBRARIES(graphvizlib.node
gvplugin_core
gvplugin_dot_layout
gvplugin_neato_layout
common
label
ortho
pack
)

INSTALL(FILES
${CMAKE_CURRENT_BINARY_DIR}/graphvizlib.wasm
DESTINATION dist
COMPONENT runtime
)
IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphvizlib.wasm.map DESTINATION dist COMPONENT runtime)
ENDIF ()
Loading

0 comments on commit c6e6f1e

Please sign in to comment.