Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
{ "stdlibs": ["libstdc++"],
"tests": [
"Debug.Default", "Release.Default", "Release.TSan",
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic",
"Release.MaxSan", "Debug.Werror",
"Debug.Coverage"
]
}
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
{ "stdlibs": ["libstdc++", "libc++"],
"tests": [
"Debug.Default", "Release.Default", "Release.TSan",
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic"
"Release.MaxSan", "Debug.Werror"
]
}
]
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/static_exemplar_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

name: Static Exemplar Test
on:
push:
branches:
- main
pull_request:

jobs:
static-exemplar-test:
runs-on: ubuntu-latest
container: ghcr.io/bemanproject/infra-containers-gcc:latest
name: "Static exemplar smoke test"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test static exemplar
run: |
cd cookiecutter
source ./check_cookiecutter.sh
cookiecutter_venv_path=$(mktemp --directory --dry-run)
setup_venv "$cookiecutter_venv_path"
stamp "$PWD" "./static_exemplar" "static"
cd static_exemplar/exemplar
cmake -B build -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./infra/cmake/use-fetch-content.cmake -DCMAKE_CXX_STANDARD=20 -DCMAKE_INSTALL_PREFIX=$PWD/dist
cmake --build build
ctest --test-dir build
cmake --install build
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ option(
# for find of beman-install-library
include(infra/cmake/beman-install-library-config.cmake)

add_subdirectory(src/beman/exemplar)
add_library(beman.exemplar INTERFACE)
add_library(beman::exemplar ALIAS beman.exemplar)

target_sources(
beman.exemplar
PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

set_target_properties(beman.exemplar PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)

add_subdirectory(include/beman/exemplar)

beman_install_library(beman.exemplar)

Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ cmake -B build -S . -DCMAKE_CXX_STANDARD=20 -DBEMAN_EXEMPLAR_BUILD_TESTS=OFF

Enable building examples. Default: ON. Values: { ON, OFF }.


#### `BEMAN_EXEMPLAR_INSTALL_CONFIG_FILE_PACKAGE`

Enable installing the CMake config file package. Default: ON.
Expand Down Expand Up @@ -358,10 +357,9 @@ any libraries or executables that include `beman.exemplar` headers.
target_link_libraries(yourlib PUBLIC beman::exemplar)
```

### Produce beman.exemplar static library
### Produce beman.exemplar interface library

You can include exemplar's headers locally
by producing a static `libbeman.exemplar.a` library.
You can produce exemplar's interface library locally by:

```bash
cmake --workflow --preset gcc-release
Expand All @@ -377,11 +375,9 @@ This will generate the following directory structure at `/opt/beman`.
│ └── exemplar
│ └── identity.hpp
└── lib
├── cmake
│   └── beman.exemplar
│   ├── beman.exemplar-config-version.cmake
│   ├── beman.exemplar-config.cmake
│   ├── beman.exemplar-targets-debug.cmake
│   └── beman.exemplar-targets.cmake
└── libbeman.exemplar.a
└── cmake
└── beman.exemplar
├── beman.exemplar-config-version.cmake
├── beman.exemplar-config.cmake
└── beman.exemplar-targets.cmake
```
34 changes: 24 additions & 10 deletions cookiecutter/check_cookiecutter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ set -euo pipefail

declare script_dir=$(realpath $(dirname "$BASH_SOURCE"))

function check_consistency() {
local out_dir_path
out_dir_path=$(mktemp --directory --dry-run)
cd /tmp
function stamp() {
local cookiecutter_dir="$1" ; shift
local output_dir="$1" ; shift
local library_type="$1" ; shift
python3 \
-m cookiecutter \
--no-input \
--output-dir "$out_dir_path" \
"$script_dir" \
--output-dir "$output_dir" \
"$cookiecutter_dir" \
project_name="exemplar" \
cpp_build_version="17" \
paper="P0898R3" \
owner="bemanproject" \
description="A Beman Library Exemplar" \
godbolt_link="https://godbolt.org/z/4qEPK87va"
godbolt_link="https://godbolt.org/z/4qEPK87va" \
library_type="$library_type"
}

function check_consistency() {
local out_dir_path
out_dir_path=$(mktemp --directory --dry-run)
cd /tmp
stamp "$script_dir" "$out_dir_path" "interface"
cp "$script_dir"/../.github/workflows/cookiecutter_test.yml "$out_dir_path"/exemplar/.github/workflows
cp "$script_dir"/../.github/workflows/static_exemplar_test.yml "$out_dir_path"/exemplar/.github/workflows
local diff_path
diff_path=$(mktemp)
diff -r "$script_dir/.." "$out_dir_path/exemplar" \
Expand Down Expand Up @@ -65,12 +74,17 @@ function check_templating() {
rm "$grep_path"
}

function main() {
local cookiecutter_venv_path
cookiecutter_venv_path=$(mktemp --directory --dry-run)
function setup_venv() {
local path="$1" ; shift
python3 -m venv "$cookiecutter_venv_path"
source "$cookiecutter_venv_path/bin/activate"
python3 -m pip install cookiecutter >& /dev/null
}

function main() {
local cookiecutter_venv_path
cookiecutter_venv_path=$(mktemp --directory --dry-run)
setup_venv "$cookiecutter_venv_path"
check_consistency
check_templating
rm -rf "$cookiecutter_venv_path"
Expand Down
1 change: 1 addition & 0 deletions cookiecutter/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"owner": "github-user-name",
"description": "Short project description.",
"godbolt_link": "https://www.example.com",
"library_type": ["interface", "static"],
"_copy_without_render": [
"infra"
],
Expand Down
17 changes: 17 additions & 0 deletions cookiecutter/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

"""Post-generation hook to clean up template files based on library_type."""

import shutil
from pathlib import Path
import os

# Get the library type from cookiecutter context
library_type = "{{ cookiecutter.library_type }}"

# If interface library, remove the src/ directory (not needed for header-only)
if library_type == "interface":
src_dir = Path("src")
if src_dir.exists():
shutil.rmtree(src_dir)
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ jobs:
{ "stdlibs": ["libstdc++"],
"tests": [
"Debug.Default", "Release.Default", "Release.TSan",
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic",
"Debug.Coverage"
"Release.MaxSan", "Debug.Werror",
"Debug.Coverage"{% if cookiecutter.library_type == "static" %}, "Debug.Dynamic"{% endif %}

]
}
]
Expand Down Expand Up @@ -78,7 +79,8 @@ jobs:
{ "stdlibs": ["libstdc++", "libc++"],
"tests": [
"Debug.Default", "Release.Default", "Release.TSan",
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic"
"Release.MaxSan", "Debug.Werror"{% if cookiecutter.library_type == "static" %}, "Debug.Dynamic"{% endif %}

]
}
]
Expand Down
17 changes: 17 additions & 0 deletions cookiecutter/{{cookiecutter.project_name}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,24 @@ option(
# for find of beman-install-library
include(infra/cmake/beman-install-library-config.cmake)

{% if cookiecutter.library_type == "interface" %}
add_library(beman.{{cookiecutter.project_name}} INTERFACE)
{% else %}
add_library(beman.{{cookiecutter.project_name}})
{% endif %}
add_library(beman::{{cookiecutter.project_name}} ALIAS beman.{{cookiecutter.project_name}})

target_sources(
beman.{{cookiecutter.project_name}}
PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

set_target_properties(beman.{{cookiecutter.project_name}} PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)

add_subdirectory(include/beman/{{cookiecutter.project_name}})
{% if cookiecutter.library_type == "static" %}
add_subdirectory(src/beman/{{cookiecutter.project_name}})
{% endif %}

beman_install_library(beman.{{cookiecutter.project_name}})

Expand Down
36 changes: 27 additions & 9 deletions cookiecutter/{{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ cmake -B build -S . -DCMAKE_CXX_STANDARD=20 -DBEMAN_{{cookiecutter.project_name.

Enable building examples. Default: ON. Values: { ON, OFF }.


#### `BEMAN_{{cookiecutter.project_name.upper()}}_INSTALL_CONFIG_FILE_PACKAGE`

Enable installing the CMake config file package. Default: ON.
Expand Down Expand Up @@ -358,10 +357,13 @@ any libraries or executables that include `beman.{{cookiecutter.project_name}}`
target_link_libraries(yourlib PUBLIC beman::{{cookiecutter.project_name}})
```

### Produce beman.{{cookiecutter.project_name}} static library
### Produce beman.{{cookiecutter.project_name}} {{ cookiecutter.library_type }} library

You can include {{cookiecutter.project_name}}'s headers locally
by producing a static `libbeman.{{cookiecutter.project_name}}.a` library.
{% if cookiecutter.library_type == "interface" %}
You can produce {{cookiecutter.project_name}}'s interface library locally by:
{% else %}
You can produce {{cookiecutter.project_name}}'s static library `libbeman.{{cookiecutter.project_name}}.a` by:
{% endif %}

```bash
cmake --workflow --preset gcc-release
Expand All @@ -370,6 +372,21 @@ cmake --install build/gcc-release --prefix /opt/beman

This will generate the following directory structure at `/opt/beman`.

{% if cookiecutter.library_type == "interface" %}
```txt
/opt/beman
├── include
│ └── beman
│ └── {{cookiecutter.project_name}}
│ └── identity.hpp
└── lib
└── cmake
└── beman.{{cookiecutter.project_name}}
├── beman.{{cookiecutter.project_name}}-config-version.cmake
├── beman.{{cookiecutter.project_name}}-config.cmake
└── beman.{{cookiecutter.project_name}}-targets.cmake
```
{% else %}
```txt
/opt/beman
├── include
Expand All @@ -378,10 +395,11 @@ This will generate the following directory structure at `/opt/beman`.
│ └── identity.hpp
└── lib
├── cmake
│   └── beman.{{cookiecutter.project_name}}
│   ├── beman.{{cookiecutter.project_name}}-config-version.cmake
│   ├── beman.{{cookiecutter.project_name}}-config.cmake
│   ├── beman.{{cookiecutter.project_name}}-targets-debug.cmake
│   └── beman.{{cookiecutter.project_name}}-targets.cmake
│ └── beman.{{cookiecutter.project_name}}
│ ├── beman.{{cookiecutter.project_name}}-config-version.cmake
│ ├── beman.{{cookiecutter.project_name}}-config.cmake
│ ├── beman.{{cookiecutter.project_name}}-targets-debug.cmake
│ └── beman.{{cookiecutter.project_name}}-targets.cmake
└── libbeman.{{cookiecutter.project_name}}.a
```
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

target_sources(beman.{{cookiecutter.project_name}} PUBLIC FILE_SET HEADERS FILES identity.hpp)
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

add_library(beman.{{cookiecutter.project_name}})
add_library(beman::{{cookiecutter.project_name}} ALIAS beman.{{cookiecutter.project_name}})

target_sources(beman.{{cookiecutter.project_name}} PRIVATE identity.cpp)

target_sources(
beman.{{cookiecutter.project_name}}
PUBLIC
FILE_SET HEADERS
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../include"
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/../../../include/beman/{{cookiecutter.project_name}}/identity.hpp"
PRIVATE
identity.cpp
)

set_target_properties(beman.{{cookiecutter.project_name}} PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/{{cookiecutter.project_name}}/identity.hpp>

// Implementation file for static library build.
// For a simple identity function, there's nothing to implement here,
// but this file exists to demonstrate the static library structure.
3 changes: 3 additions & 0 deletions include/beman/exemplar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

target_sources(beman.exemplar PUBLIC FILE_SET HEADERS FILES identity.hpp)
17 changes: 0 additions & 17 deletions src/beman/exemplar/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions src/beman/exemplar/identity.cpp

This file was deleted.