Skip to content

Commit ff1933c

Browse files
committed
perf: add a module type
Signed-off-by: l.feng <43399351+msclock@users.noreply.github.com>
1 parent dadb271 commit ff1933c

16 files changed

Lines changed: 230 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,24 @@ jobs:
177177
- name: Install compilers and tools
178178
run: |
179179
brew install ${{ matrix.compiler }} cmake ninja ccache lcov
180+
brew link ${{ matrix.compiler }} --force
180181
181182
- name: Prepare PATH for compilers
182183
run: echo "PATH=/usr/local/opt/${{ matrix.compiler }}/bin:$PATH" >> $GITHUB_ENV
183184

184185
- name: Prepare for llvm
185186
if: contains(matrix.compiler, 'llvm')
186187
run: |
188+
clang --version
189+
clang++ --version
187190
echo "CC=clang" >> $GITHUB_ENV
188191
echo "CXX=clang++" >> $GITHUB_ENV
189192
190193
- name: Prepare for gcc
191194
if: contains(matrix.compiler, 'gcc')
192195
run: |
196+
gcc --version
197+
g++ --version
193198
echo "CC=gcc" >> $GITHUB_ENV
194199
echo "CXX=g++" >> $GITHUB_ENV
195200
compiler=${{ matrix.compiler }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A continuously evolving basic template for cpp development.
3939
- Provides `static/runtime analysis`including [clang-tidy](https://clang.llvm.org/extra/clang-tidy/), [cppcheck](http://cppcheck.net/manual.html), [sanitizers](https://clang.llvm.org/docs/index.html), [valgrind](https://valgrind.org/docs/manual/manual.html).
4040
- Supports `code coverage` with [lcov](https://github.com/linux-test-project/lcov), [gcovr](https://github.com/gcovr/gcovr), llvm-cov, and [opencppcoverage](https://github.com/OpenCppCoverage/OpenCppCoverage).
4141
- Supports `hardening compilation `for MSVC, Clang, and GCC.
42-
- Provides compile, header, application target generation.
42+
- Provide generation of various targets for compile library, header library, application and so on.
4343
- Build with preset build types: Debug(Default), Release, RelWithDebInfo, MinSizeRel.
4444
- Supports package managers: [vcpkg](https://github.com/microsoft/vcpkg), [conan](https://github.com/conan-io/cmake-conan), and [cpm](https://github.com/cpm-cmake/CPM.cmake).
4545
- Use [cmake-registry](https://github.com/msclock/cmake-registry) to provide various cmake modules and scripts.

copier.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ compile_target:
179179
help: Add a compile lib target, and skip leaving it empty.
180180
type: str
181181

182+
compile_module_target:
183+
default: compile_module
184+
help: Add a compile module lib target, and skip leaving it empty.
185+
type: str
186+
182187
use_codecov:
183188
default: true
184189
help: 'Whether to add codecov integration:'

includes/copier-answers-sample.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ author_name: msclock
44
codecov_notify_builds: 1
55
codecov_threshold: 5%
66
compile_target: compile
7+
compile_module_target: compile_module
78
copyright_holder: Serious Scaffold
89
copyright_license: MIT License
910
copyright_year: 2022-2024

src/compile_module/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#[[
2+
To build this requires cmake specification from [cxxmodules](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html).
3+
4+
]]
5+
cmake_minimum_required(VERSION 3.28.2)
6+
7+
set(target_name compile_module)
8+
9+
file(GLOB _interfaces "include/*.ixx")
10+
file(GLOB _srcs "src/*.cpp")
11+
12+
add_library(${target_name})
13+
warn_target(${target_name})
14+
harden_target(${target_name})
15+
sanitize_target(${target_name})
16+
target_code_coverage(${target_name} ALL)
17+
18+
generate_git_header(VERSION_NAMESPACE_PREFIX ${target_name})
19+
20+
target_sources(
21+
${target_name}
22+
PUBLIC FILE_SET
23+
cxx_modules
24+
TYPE
25+
CXX_MODULES
26+
FILES
27+
${_interfaces}
28+
BASE_DIRS
29+
${CMAKE_CURRENT_SOURCE_DIR}/include
30+
PRIVATE ${_srcs})
31+
32+
target_include_interface_directories(
33+
${target_name} ${CMAKE_CURRENT_SOURCE_DIR}/include
34+
${CMAKE_CURRENT_BINARY_DIR}/git_version)
35+
36+
target_compile_features(${target_name} PUBLIC cxx_std_23)
37+
set_property(TARGET ${target_name} PROPERTY CXX_SCAN_FOR_MODULES ON)
38+
39+
install_dependency(TARGETS ${target_name})
40+
41+
if(BUILD_TESTING)
42+
add_test_subdirectory(tests)
43+
endif()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module;
2+
3+
export module compile_module;
4+
5+
namespace compile_module {
6+
namespace distribution {
7+
export bool is_debug() noexcept;
8+
} // namespace distribution
9+
} // namespace compile_module
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module;
2+
3+
module compile_module;
4+
5+
namespace compile_module {
6+
namespace distribution {
7+
bool is_debug() noexcept {
8+
#ifdef _DEBUG
9+
return true;
10+
#else
11+
return false;
12+
#endif
13+
}
14+
} // namespace distribution
15+
} // namespace compile_module
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
find_package(GTest CONFIG REQUIRED)
2+
3+
include(GoogleTest)
4+
5+
file(GLOB files "*.cpp")
6+
7+
foreach(_file ${files})
8+
get_filename_component(file_basename ${_file} NAME_WE)
9+
add_executable(${file_basename} ${_file})
10+
target_link_libraries(${file_basename} PRIVATE GTest::gtest_main
11+
compile_module)
12+
target_compile_features(${file_basename} PUBLIC cxx_std_23)
13+
set_property(TARGET ${file_basename} PROPERTY CXX_SCAN_FOR_MODULES ON)
14+
warn_target(${file_basename})
15+
harden_target(${file_basename})
16+
sanitize_target(${file_basename})
17+
target_code_coverage(${file_basename} ALL)
18+
gtest_discover_tests(${file_basename})
19+
endforeach()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import compile_module;
2+
3+
#include <gtest/gtest.h>
4+
#include "_version.hpp"
5+
6+
#ifdef _DEBUG
7+
#define DIST_FLAG 1
8+
#else
9+
#define DIST_FLAG 0
10+
#endif
11+
12+
TEST(compile_module, version) {
13+
const auto* const version = git_ProjectVersion();
14+
EXPECT_STRNE(version, "");
15+
}
16+
17+
TEST(compile_module, distribution) {
18+
const auto is_debug = compile_module::distribution::is_debug();
19+
EXPECT_EQ(is_debug, DIST_FLAG);
20+
}

template/README.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
- Provides `static/runtime analysis`including [clang-tidy](https://clang.llvm.org/extra/clang-tidy/), [cppcheck](http://cppcheck.net/manual.html), [sanitizers](https://clang.llvm.org/docs/index.html), [valgrind](https://valgrind.org/docs/manual/manual.html).
4545
- Supports `code coverage` with [lcov](https://github.com/linux-test-project/lcov), [gcovr](https://github.com/gcovr/gcovr), llvm-cov, and [opencppcoverage](https://github.com/OpenCppCoverage/OpenCppCoverage).
4646
- Supports `hardening compilation `for MSVC, Clang, and GCC.
47-
- Provides compile, header, application target generation.
47+
- Provide generation of various targets for compile library, header library, application and so on.
4848
- Build with preset build types: Debug(Default), Release, RelWithDebInfo, MinSizeRel.
4949
- Supports package managers: [vcpkg](https://github.com/microsoft/vcpkg), [conan](https://github.com/conan-io/cmake-conan), and [cpm](https://github.com/cpm-cmake/CPM.cmake).
5050
- Use [cmake-registry](https://github.com/msclock/cmake-registry) to provide various cmake modules and scripts.

0 commit comments

Comments
 (0)