Skip to content

Commit

Permalink
Merge pull request #202 from mgastner/pr/adisidev/201
Browse files Browse the repository at this point in the history
  • Loading branch information
adisidev authored Nov 7, 2024
2 parents 1cbde40 + 9377065 commit 85068c7
Show file tree
Hide file tree
Showing 19 changed files with 2,870 additions and 1,972 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build and Release (on GitHub only)

on:
# when a push is made to the main branch (like when a pull request is merged, or something is pushed directly)
workflow_dispatch:
push:
branches: [ "main" ]

env:
BUILD_TYPE: Release

jobs:

set-outputs:
runs-on: ubuntu-latest
outputs:
short_sha: ${{ steps.vars.outputs.short_sha }}
steps:

- name: Checkout Repository
uses: actions/checkout@v4

- name: Calculate short_sha
id: vars
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

build-and-upload:

runs-on: ubuntu-latest
needs: set-outputs
container:
image: gocartio/cartogram-web:latest
steps:

- name: Install Dependencies
run: |
apt update -y
apt install -y git g++-11 build-essential cmake libboost-all-dev
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRELEASE_TAG=${{ needs.set-outputs.outputs.short_sha }}

- name: Build
run: |
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target install -j4 --
# - name: Run CTest
# working-directory: ${{github.workspace}}/build
# # Execute tests defined by the CMake configuration.
# # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# run: ctest -C ${{env.BUILD_TYPE}}

# - name: Run Stress Test
# run: |
# sudo make install -C build
# cd tests/
# chmod +x stress_test.sh
# bash stress_test.sh

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: cartogram
path: /usr/local/bin/cartogram

release:

runs-on: ubuntu-latest
needs: [build-and-upload, set-outputs]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: cartogram

- name: Push tag
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ needs.set-outputs.outputs.short_sha }}
git push origin ${{ needs.set-outputs.outputs.short_sha }}
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.set-outputs.outputs.short_sha }}
files: cartogram
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ cartogram
/*.geojson
/sample_data/*.geojson

# Ignore files generated by Visual Studio Code
.vscode

# Ignore DS_Store files created by macOS
**/.DS_Store
**/.cache*
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/cgal"]
path = external/cgal
url = https://github.com/CGAL/cgal.git
78 changes: 78 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"files.associations": {
"__config": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdlib": "cpp",
"initializer_list": "cpp",
"limits": "cpp",
"numbers": "cpp",
"concepts": "cpp",
"algorithm": "cpp",
"type_traits": "cpp",
"__hash_table": "cpp",
"__split_buffer": "cpp",
"__tree": "cpp",
"atomic": "cpp",
"deque": "cpp",
"hash_map": "cpp",
"forward_list": "cpp",
"ios": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"system_error": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"*.tcc": "cpp",
"any": "cpp",
"cmath": "cpp",
"cstdio": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"compare": "cpp",
"exception": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"utility": "cpp",
"format": "cpp",
"fstream": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"new": "cpp",
"ostream": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"__bit_reference": "cpp",
"__threading_support": "cpp",
"execution": "cpp"
},
"files.exclude": {
"**/external": true
}
}
76 changes: 45 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cmake_minimum_required(VERSION 3.27)
cmake_minimum_required(VERSION 3.25)

if(UNIX AND NOT APPLE)
set(CMAKE_CXX_COMPILER "g++-11")
endif()

project(cartogram LANGUAGES CXX)

# ========== Project Setup ==========
Expand All @@ -7,52 +12,61 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Assume development build by default
set(RELEASE_TAG "development" CACHE STRING "Release tag for the build")

# Default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()

# ========== Dependencies Setup ==========

# Direct CMake to local CGAL installation
set(CGAL_DIR ${PROJECT_SOURCE_DIR}/external/cgal)
find_package(CGAL REQUIRED)

# Boost
find_package(Boost REQUIRED COMPONENTS unit_test_framework)

# Matplot++
find_package(Matplot++ REQUIRED)

# PkgConfig, fftw, and cairo
find_package(PkgConfig REQUIRED)
pkg_search_module(fftw REQUIRED fftw3 IMPORTED_TARGET)
pkg_search_module(CAIRO REQUIRED CAIRO IMPORTED_TARGET)
pkg_search_module(cairo REQUIRED cairo IMPORTED_TARGET)

# ========== Source Files ==========
file(GLOB_RECURSE CARTOGRAM_SOURCES "src/*.cpp")
add_executable(cartogram ${CARTOGRAM_SOURCES})

target_compile_definitions(cartogram PRIVATE RELEASE_TAG="${RELEASE_TAG}")

# ========== Include Directories ==========
target_include_directories(cartogram PUBLIC
${PROJECT_SOURCE_DIR}/include
${Boost_INCLUDE_DIRS}
PkgConfig::fftw
PkgConfig::CAIRO
target_include_directories(cartogram
PUBLIC
${PROJECT_SOURCE_DIR}/include
)

target_include_directories(cartogram
SYSTEM PUBLIC
${CGAL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/external
)

# ========== Compile Options ==========
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(cartogram PRIVATE -isystem ${Boost_INCLUDE_DIRS})
target_compile_options(cartogram PRIVATE -ffp-contract=off)
elseif(MSVC)
target_compile_options(cartogram PRIVATE /external:I ${Boost_INCLUDE_DIRS})
endif()
target_compile_options(cartogram PRIVATE -ffp-contract=off)

# Compiler warnings
target_compile_options(cartogram PRIVATE -Wall -Wextra -pedantic -Wno-deprecated-declarations)
target_compile_options(cartogram PRIVATE
-Wall # Enable all warnings
-Wextra # Enable extra warnings
-Wpedantic # Enable pedantic warnings
)

# ========== Linking Libraries ==========
target_link_libraries(cartogram
PkgConfig::fftw
PkgConfig::CAIRO
Matplot++::matplot
PkgConfig::fftw
PkgConfig::cairo
)

# ========== Installation ==========
Expand Down Expand Up @@ -80,18 +94,18 @@ foreach(TEST_FILE ${TEST_FILES})
add_executable(${TEST_NAME} ${TEST_FILE} ${CARTOGRAM_TEST_SOURCES_FROM_SRC})

# Include directories for the test executable
target_include_directories(${TEST_NAME} PUBLIC
${PROJECT_SOURCE_DIR}/include
${Boost_INCLUDE_DIRS}
PkgConfig::fftw
target_include_directories(${TEST_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
target_include_directories(${TEST_NAME}
SYSTEM PUBLIC
${CGAL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/external
)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${TEST_NAME} PRIVATE -isystem ${Boost_INCLUDE_DIRS})
target_compile_options(${TEST_NAME} PRIVATE -ffp-contract=off)
elseif(MSVC)
target_compile_options(${TEST_NAME} PRIVATE /external:I ${Boost_INCLUDE_DIRS})
endif()
target_compile_options(${TEST_NAME} PRIVATE -ffp-contract=off)

# Compiler warnings for the test executable
target_compile_options(${TEST_NAME} PRIVATE -Wall -Wextra -pedantic -Wno-deprecated-declarations)
Expand All @@ -113,4 +127,4 @@ add_custom_command(
POST_BUILD
COMMENT "Uninstalling cartogram..."
COMMAND xargs rm -vf < install_manifest.txt || echo "Nothing in install_manifest.txt to be uninstalled!"
)
)
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ Gastner MT, Seguy V, More P. _Fast flow-based algorithm for creating density-equ

Data produced by code in this repository are subject to the MIT license found [here](./LICENSE) and should cite the aforementioned paper by Gastner et al. (2018).

While cloning this repository, please ensure you use the `--recurse-submodules` flag like so:
-
git clone --recurse-submodules https://github.com/mgastner/cartogram-cpp.git

## Dependencies

Please note, we only support UNIX-based systems, and have only tested on macOS, Linux, and GNU.

### macOS

#### Installing Homebrew
Expand All @@ -22,25 +28,17 @@ Install [homebrew](brew.sh) by running the following command:

#### Installing dependencies through Homebrew

Install llvm, pkg-config, boost, fftw, cgal, nlohmann-json, and cmake by running the following command:
Install pkg-config, boost, fftw, nlohmann-json, and cmake by running the following command:

brew install llvm@17 libomp pkg-config boost fftw cgal nlohmann-json cmake cairo matplotplusplus
brew install libomp pkg-config boost fftw nlohmann-json cmake cairo

### Debian-based distributions (Ubuntu, Arch Linux etc.)

#### Installing GNU g++-13

Run the following commands to install it:

sudo apt install build-essential manpages-dev software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update && sudo apt install gcc-13 g++-13

#### Installing dependencies through apt
#### Installing relevant dependencies through apt:

Install nlohmann-json, cgal, openmp, fftw3, cairo, matplot++, boost, and cmake by running the following command:
Have a look through to apt-requirements.txt if you'd like to see what all will be installed. Then, run the following commands to install all dependencies through apt:

sudo apt install nlohmann-json3-dev libcgal-dev libomp-dev libfftw3-dev libcairo2-dev libmatplot++-dev libboost-all-dev cmake
apt install -y g++-11 build-essential cmake libboost-all-dev nlohmann-json3-dev libomp-dev libfftw3-dev libcairo2-dev

### Installation

Expand All @@ -62,6 +60,7 @@ Using lesser cores than you have is recommended so that your computer still has
- If running `cmake -B build` gives you an error, it is likely that a dependency was not installed correctly. Rerun the appropriate commands above to install the required dependencies and try again.
- If you get an error which mentions permission issues, try running the command that gave you the error with `sudo` prefixed, as done with `sudo make install -C build` above.
- If `cmake` complains that it could not find a particular library, please try uninstalling it and installing it again. After reinstalling it, please also unlink it and link it with the `--force` flag.
- If you get errors related to CGAL, it's likely you have another version of CGAL installed on your computer that is getting chosen instead of the one contained as a submodule within this repository. It's also possible that when cloning this repository, the `--recurse-submodule` flag was missing. Try running `git submodule init` and `git submodule update` in the root directory of the repository.

### Usage

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions external/cgal
Submodule cgal added at 188e51
Loading

0 comments on commit 85068c7

Please sign in to comment.