Skip to content

Commit

Permalink
Merge pull request #310 from christian-rauch/ci_cmake_all
Browse files Browse the repository at this point in the history
cmake CI
  • Loading branch information
christian-rauch authored Jan 21, 2024
2 parents 5c2753e + 1e95b41 commit 13f3042
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 106 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: windows-latest
c_compiler: gcc
cpp_compiler: g++
- os: windows-latest
c_compiler: clang
cpp_compiler: clang++
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
- os: macos-latest
c_compiler: gcc
cpp_compiler: g++
exclude:
- os: ubuntu-latest
c_compiler: cl
- os: macos-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- uses: seanmiddleditch/gha-setup-ninja@master

- uses: ilammy/msvc-dev-cmd@v1

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
name: ROS workspace CI
name: colcon workspace

on: [push, pull_request]

jobs:
# build on Ubuntu docker images
build_linux:
name: Ubuntu (${{ matrix.ros_distribution }}, ${{ matrix.config }})
name: "Ubuntu (${{ matrix.ros_distribution }}, shared: ${{ matrix.cmake_shared_libs }})"

runs-on: ubuntu-latest

strategy:
matrix:
ros_distribution: [noetic, humble]
config: ["default"] # nice name
cmake_args: ['[ ]'] # empty list of options
cmake_shared_libs: ['ON', 'OFF']
include:
- docker_image: ubuntu:20.04
ros_distribution: noetic
Expand All @@ -23,13 +22,6 @@ jobs:
ros_distribution: humble
ros_version: 2

# build static library, this will set BUILD_PYTHON_WRAPPER to OFF
- docker_image: ubuntu:22.04
ros_distribution: humble
ros_version: 2
config: "static"
cmake_args: '[ "-DBUILD_SHARED_LIBS=OFF" ]'

container:
image: ${{ matrix.docker_image }}

Expand All @@ -40,8 +32,6 @@ jobs:
apt install --no-install-recommends -y git ca-certificates
- uses: actions/checkout@v4
#with:
# submodules: recursive

- name: Setup ROS environment
uses: ros-tooling/[email protected]
Expand All @@ -52,30 +42,27 @@ jobs:
with:
package-name: apriltag
target-ros1-distro: ${{ matrix.ros_distribution }}
extra-cmake-args: "-DBUILD_SHARED_LIBS=${{ matrix.cmake_shared_libs }}"

- name: ROS 2 CI Action
if: ${{ matrix.ros_version == 2 }}
uses: ros-tooling/[email protected]
with:
package-name: apriltag
target-ros2-distro: ${{ matrix.ros_distribution }}
colcon-defaults: |
{
"build": {
"cmake-args": ${{ matrix.cmake_args }}
}
}
extra-cmake-args: "-DBUILD_SHARED_LIBS=${{ matrix.cmake_shared_libs }}"


# build on Windows native
build_windows:
name: Windows (${{ matrix.ros_distribution }})
name: "Windows (${{ matrix.ros_distribution }}, shared: ${{ matrix.cmake_shared_libs }})"

runs-on: windows-2019

strategy:
matrix:
ros_distribution: [noetic, humble]
cmake_shared_libs: ['OFF']
include:
- ros_distribution: noetic
ros_version: 1
Expand All @@ -97,36 +84,26 @@ jobs:
with:
package-name: apriltag
target-ros1-distro: ${{ matrix.ros_distribution }}
colcon-defaults: |
{
"build": {
"cmake-args": [ "-DBUILD_SHARED_LIBS=OFF" ]
}
}
extra-cmake-args: "-DBUILD_SHARED_LIBS=${{ matrix.cmake_shared_libs }}"

- name: ROS 2 CI Action
if: ${{ matrix.ros_version == 2 }}
uses: ros-tooling/[email protected]
with:
package-name: apriltag
target-ros2-distro: ${{ matrix.ros_distribution }}
colcon-defaults: |
{
"build": {
"cmake-args": [ "-DBUILD_SHARED_LIBS=OFF" ]
}
}
extra-cmake-args: "-DBUILD_SHARED_LIBS=${{ matrix.cmake_shared_libs }}"

# build on macOS native
build_macos:
name: macOS (${{ matrix.ros_distribution }})
name: "macOS (${{ matrix.ros_distribution }}, shared: ${{ matrix.cmake_shared_libs }})"

runs-on: macos-latest

strategy:
fail-fast: false
matrix:
ros_distribution: [humble]
cmake_shared_libs: ['OFF']

steps:
- uses: actions/checkout@v4
Expand All @@ -145,9 +122,4 @@ jobs:
with:
package-name: apriltag
target-ros2-distro: ${{ matrix.ros_distribution }}
colcon-defaults: |
{
"build": {
"cmake-args": [ "-DBUILD_PYTHON_WRAPPER=OFF" ]
}
}
extra-cmake-args: "-DBUILD_SHARED_LIBS=${{ matrix.cmake_shared_libs }}"
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ endif()
# Set a default build type if none was specified
set(default_build_type "Release")

SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
Expand All @@ -43,9 +45,19 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Werror)
# add_compile_options(-Wpedantic)
add_compile_options(-Wno-shift-negative-value)
if(NOT CMAKE_C_COMPILER_ID MATCHES "AppleClang")
add_link_options("-Wl,-z,relro,-z,now,-z,defs")
endif()
endif()

if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_ID MATCHES "AppleClang" AND NOT CMAKE_C_SIMULATE_ID MATCHES "MSVC")
add_link_options("-Wl,-z,relro,-z,now,-z,defs")
endif()

if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_SIMULATE_ID MATCHES "MSVC")
# error: 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.
# "strdup" is standard since C23
add_definitions(-D _CRT_NONSTDC_NO_DEPRECATE)
# ignore "'fopen' is deprecated" and "'strncpy' is deprecated" warnings
# TODO: replace by fopen_s and strncpy_s in C11
add_definitions(-D _CRT_SECURE_NO_WARNINGS)
endif()

aux_source_directory(common COMMON_SRC)
Expand Down
5 changes: 1 addition & 4 deletions apriltag.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ either expressed or implied, of the Regents of The University of Michigan.

#include "apriltag.h"

#define _USE_MATH_DEFINES
#include <math.h>
#include <assert.h>
#include <stdint.h>
Expand All @@ -53,10 +54,6 @@ either expressed or implied, of the Regents of The University of Michigan.

#include "common/postscript_utils.h"

#ifndef M_PI
# define M_PI 3.141592653589793238462643383279502884196
#endif

#ifdef _WIN32
static inline void srandom(unsigned int seed)
{
Expand Down
5 changes: 1 addition & 4 deletions apriltag_quad_thresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ either expressed or implied, of the Regents of The University of Michigan.
// limitation: image size must be <32768 in width and height. This is
// because we use a fixed-point 16 bit integer representation with one
// fractional bit.
#define _USE_MATH_DEFINES
#include <math.h>
#include <assert.h>
#include <string.h>
Expand Down Expand Up @@ -62,10 +63,6 @@ struct uint64_zarray_entry
struct uint64_zarray_entry *next;
};

#ifndef M_PI
# define M_PI 3.141592653589793238462643383279502884196
#endif

struct pt
{
// Note: these represent 2*actual value.
Expand Down
14 changes: 7 additions & 7 deletions common/g2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ either expressed or implied, of the Regents of The University of Michigan.
#include "g2d.h"
#include "common/math_util.h"

#ifdef _WIN32
static inline long int random(void)
{
return rand();
}
#endif

double g2d_distance(const double a[2], const double b[2])
{
return sqrtf(sq(a[0]-b[0]) + sq(a[1]-b[1]));
Expand Down Expand Up @@ -725,6 +718,13 @@ int g2d_polygon_rasterize(const zarray_t *poly, double y, double *x)
*/
#if 0

#ifdef _WIN32
static inline long int random(void)
{
return rand();
}
#endif

#include "timeprofile.h"

int main(int argc, char *argv[])
Expand Down
11 changes: 8 additions & 3 deletions common/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ void getopt_option_destroy(getopt_option_t *goo)
free(goo);
}

void getopt_option_destroy_void(void *goo)
{
getopt_option_destroy((getopt_option_t *)goo);
}

void getopt_destroy(getopt_t *gopt)
{
// free the extra arguments and container
Expand All @@ -94,7 +99,7 @@ void getopt_destroy(getopt_t *gopt)

// deep free of the getopt_option structs. Also frees key/values, so
// after this loop, hash tables will no longer work
zarray_vmap(gopt->options, getopt_option_destroy);
zarray_vmap(gopt->options, getopt_option_destroy_void);
zarray_destroy(gopt->options);

// free tables
Expand Down Expand Up @@ -506,10 +511,10 @@ char * getopt_get_usage(getopt_t *gopt)
if (goo->spacer)
continue;

longwidth = max(longwidth, (int) strlen(goo->lname));
longwidth = imax(longwidth, (int) strlen(goo->lname));

if (goo->type == GOO_STRING_TYPE)
valuewidth = max(valuewidth, (int) strlen(goo->svalue));
valuewidth = imax(valuewidth, (int) strlen(goo->svalue));
}

for (int i = 0; i < zarray_size(gopt->options); i++) {
Expand Down
1 change: 1 addition & 0 deletions common/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct getopt getopt_t;

getopt_t *getopt_create();
void getopt_destroy(getopt_t *gopt);
void getopt_option_destroy_void(void *goo);

// Parse args. Returns 1 on success
int getopt_parse(getopt_t *gopt, int argc, char *argv[], int showErrors);
Expand Down
Loading

0 comments on commit 13f3042

Please sign in to comment.