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

Experiment: Add example CMake and meson build files #2071

Merged
merged 4 commits into from
Mar 1, 2022
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CMake

on:
workflow_dispatch:
push:
pull_request:
branches: [ master, development ]

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build C amalgamation
run: python ${{github.workspace}}/do.py build-c

- name: Configure CMake
run: cmake -S ${{github.workspace}}/code-experiments/build/c/ -B ${{github.workspace}}/code-experiments/build/c/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/code-experiments/build/c/build --config ${{env.BUILD_TYPE}}
27 changes: 27 additions & 0 deletions code-experiments/build/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.19)
project(ExampleExperiment
DESCRIPTION "Example COCO experiment"
LANGUAGES C)

find_library(MATH_LIBRARY m)

include(CheckCompilerFlag)
check_compiler_flag(C "-pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion" CC_HAS_WALL_ETC)

add_library(coco STATIC coco.c coco.h)
target_include_directories(coco PUBLIC .)
if(MATH_LIBRARY)
target_link_libraries(coco PUBLIC ${MATH_LIBRARY})
endif()
# Add warning flags
if (MSVC)
target_compile_options(coco PRIVATE "/W3")
elseif (CC_HAS_WALL_ETC)
target_compile_options(coco PRIVATE -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion)
endif()

add_executable(example_experiment example_experiment.c)
target_link_libraries(example_experiment PUBLIC coco)
if(MATH_LIBRARY)
target_link_libraries(example_experiment PUBLIC ${MATH_LIBRARY})
endif()
2 changes: 1 addition & 1 deletion code-experiments/build/c/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## or installing Cygwin and running GNU make from within Cygwin.

LDFLAGS += -lm
CCFLAGS = -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion
CCFLAGS ?= -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion

########################################################################
## Toplevel targets
Expand Down
19 changes: 19 additions & 0 deletions code-experiments/build/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ the following is lacking:

Instead of `make` and `Makefile` you can use `nmake` and the corresponding `NMakefile`

### CMake

Instead of `make` you can use `cmake` and the corresponding `CMakeLists.txt`:

```
mkdir build
cd build
cmake ../
ninja # or make, depending on your version of CMake
```

### meson

Instead of `make` you can use `meson` and `ninja`:

```
meson setup build
meson compile -C build
```

Getting Started
---------------
Expand Down
18 changes: 18 additions & 0 deletions code-experiments/build/c/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
project('example_experiment', 'c',
default_options: ['warning_level=3', 'buildtype=release']
)

cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false)

coco_lib = static_library('coco',
sources: 'coco.c',
dependencies: m_dep
)

executable('example_experiment',
sources: 'example_experiment.c',
link_with: coco_lib,
dependencies: m_dep
)