Skip to content

Commit 264139e

Browse files
authored
Merge pull request #9 from saxbophone/my-hovercraft-is-full-of-eels
Various usability improvements
2 parents bfa9982 + 8731082 commit 264139e

File tree

17 files changed

+167
-160
lines changed

17 files changed

+167
-160
lines changed

.github/workflows/build-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Upload
5656
uses: actions/upload-artifact@v2
5757
with:
58-
name: project_build_${{ github.run_number }}_${{ matrix.platform_name }}
58+
name: my-hovercraft-is-full-of-eels_build_${{ github.run_number }}_${{ matrix.platform_name }}
5959
path: ${{github.workspace}}/artifacts
6060
build-docs:
6161
runs-on: ubuntu-20.04

CMakeLists.txt

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# minimum CMake version required for C++20 support, among other things
33
cmake_minimum_required(VERSION 3.15)
44

5-
# detect if Project is being used as a sub-project of another CMake project
5+
# detect if MyHovercraftIsFullOfEels is being used as a sub-project of another CMake project
66
if(NOT DEFINED PROJECT_NAME)
7-
set(PROJECT_SUBPROJECT OFF)
7+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_SUBPROJECT OFF)
88
else()
9-
set(PROJECT_SUBPROJECT ON)
9+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_SUBPROJECT ON)
1010
endif()
1111

12-
project(project VERSION 0.3.0 LANGUAGES CXX)
12+
project(my-hovercraft-is-full-of-eels VERSION 0.3.0 LANGUAGES CXX)
1313

1414
find_program(CCACHE_PROGRAM ccache)
1515
if(CCACHE_PROGRAM)
@@ -27,24 +27,24 @@ endif()
2727

2828
# set some handy custom variables to detect Release-type builds from Debug-type ones
2929
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
30-
set(PROJECT_BUILD_DEBUG ON)
31-
set(PROJECT_BUILD_RELEASE OFF)
30+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_BUILD_DEBUG ON)
31+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_BUILD_RELEASE OFF)
3232
else()
33-
set(PROJECT_BUILD_DEBUG OFF)
34-
set(PROJECT_BUILD_RELEASE ON)
33+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_BUILD_DEBUG OFF)
34+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_BUILD_RELEASE ON)
3535
endif()
3636

37-
message(STATUS "[project] Build Mode: ${CMAKE_BUILD_TYPE}")
37+
message(STATUS "[my-hovercraft-is-full-of-eels] Build Mode: ${CMAKE_BUILD_TYPE}")
3838

3939
# set the C++ standard to use to C++20 always
40-
set(PROJECT_CXX_STANDARD "20")
41-
message(STATUS "[project] C++ Standard set to C++${PROJECT_CXX_STANDARD}")
42-
set(CMAKE_CXX_STANDARD ${PROJECT_CXX_STANDARD})
40+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_CXX_STANDARD "20")
41+
message(STATUS "[my-hovercraft-is-full-of-eels] C++ Standard set to C++${MY_HOVERCRAFT_IS_FULL_OF_EELS_CXX_STANDARD}")
42+
set(CMAKE_CXX_STANDARD ${MY_HOVERCRAFT_IS_FULL_OF_EELS_CXX_STANDARD})
4343
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4444

4545
include(CMakeDependentOption)
4646
# if building in Release mode, provide an option to explicitly enable tests if desired (always ON for other builds, OFF by default for Release builds)
47-
cmake_dependent_option(ENABLE_TESTS "Build the unit tests in release mode?" OFF PROJECT_BUILD_RELEASE ON)
47+
cmake_dependent_option(ENABLE_TESTS "Build the unit tests in release mode?" OFF MY_HOVERCRAFT_IS_FULL_OF_EELS_BUILD_RELEASE ON)
4848

4949
# Premature Optimisation causes problems. Commented out code below allows detection and enabling of LTO.
5050
# It's not being used currently because it seems to cause linker errors with Clang++ on Ubuntu if the library
@@ -54,45 +54,44 @@ cmake_dependent_option(ENABLE_TESTS "Build the unit tests in release mode?" OFF
5454

5555
# include(CheckIPOSupported)
5656
# check_ipo_supported(RESULT IPO_SUPPORTED)
57-
# # If we're in Release mode, set PROJECT_USE_IPO to ON by default if it's detected as supported (user can always explicitly enable it in Release mode)
58-
# cmake_dependent_option(PROJECT_USE_IPO "Use Link-Time/Inter-Procedural Optimisation?" ${IPO_SUPPORTED} PROJECT_BUILD_RELEASE OFF)
59-
# if(PROJECT_USE_IPO)
60-
# message(STATUS "[project] Link-Time-Optimisation Enabled")
57+
# # If we're in Release mode, set MY_HOVERCRAFT_IS_FULL_OF_EELS_USE_IPO to ON by default if it's detected as supported (user can always explicitly enable it in Release mode)
58+
# cmake_dependent_option(MY_HOVERCRAFT_IS_FULL_OF_EELS_USE_IPO "Use Link-Time/Inter-Procedural Optimisation?" ${IPO_SUPPORTED} MY_HOVERCRAFT_IS_FULL_OF_EELS_BUILD_RELEASE OFF)
59+
# if(MY_HOVERCRAFT_IS_FULL_OF_EELS_USE_IPO)
60+
# message(STATUS "[my-hovercraft-is-full-of-eels] Link-Time-Optimisation Enabled")
6161
# endif()
6262

6363
set(
64-
PROJECT_VERSION_STRING
64+
MY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_STRING
6565
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
6666
)
67-
set(PROJECT_ESCAPED_VERSION_STRING "\"${PROJECT_VERSION_STRING}\"")
67+
set(MY_HOVERCRAFT_IS_FULL_OF_EELS_ESCAPED_VERSION_STRING "\"${MY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_STRING}\"")
6868
# end basic metadata
6969

7070
# This is a special target which only exists to capture compilation options
71-
# used for project and its tests. This is to avoid setting global compiler
71+
# used for my-hovercraft-is-full-of-eels and its tests. This is to avoid setting global compiler
7272
# options which would be inherited by dependencies as well, which is bad
73-
# because project uses strict compiler warning options which not all other
73+
# because my-hovercraft-is-full-of-eels uses strict compiler warning options which not all other
7474
# projects can build successfully with.
7575
# Any target linked with this one will inherit the compiler options used for
76-
# project.
77-
add_library(project-compiler-options INTERFACE)
76+
# my-hovercraft-is-full-of-eels.
77+
add_library(my-hovercraft-is-full-of-eels-compiler-options INTERFACE)
7878

7979
# used for enabling additional compiler options if supported
8080
include(CheckCXXCompilerFlag)
8181

8282
function(enable_cxx_compiler_flag_if_supported flag)
83-
message(STATUS "[project] Checking if compiler supports warning flag '${flag}'")
83+
message(STATUS "[my-hovercraft-is-full-of-eels] Checking if compiler supports warning flag '${flag}'")
8484
check_cxx_compiler_flag("${flag}" flag_supported)
8585
if(flag_supported)
86-
message(STATUS "[project] Enabling warning flag '${flag}'")
87-
target_compile_options(project-compiler-options INTERFACE "${flag}")
86+
message(STATUS "[my-hovercraft-is-full-of-eels] Enabling warning flag '${flag}'")
87+
target_compile_options(my-hovercraft-is-full-of-eels-compiler-options INTERFACE "${flag}")
8888
endif()
8989
unset(flag_supported CACHE)
9090
endfunction()
9191

9292
# enable a large amount of extra warnings, regardless of build mode
9393
if (MSVC) # MSVC supports different warning options to GCC/Clang
94-
# add_compile_options(/W4) # set warning level 4
95-
enable_cxx_compiler_flag_if_supported("/W4")
94+
enable_cxx_compiler_flag_if_supported("/W3") # set warning level 3
9695
# if tests are enabled, enable converting all warnings to errors too
9796
if (ENABLE_TESTS)
9897
# add_compile_options(/WX)
@@ -126,6 +125,7 @@ else() # GCC/Clang warning option
126125
enable_cxx_compiler_flag_if_supported("-Wno-error=unused-variable")
127126
enable_cxx_compiler_flag_if_supported("-Wno-error=unused-parameter")
128127
enable_cxx_compiler_flag_if_supported("-Wno-error=unused-private-field")
128+
enable_cxx_compiler_flag_if_supported("-Wno-error=unused-but-set-variable")
129129
endif()
130130
endif()
131131

@@ -136,10 +136,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Mo
136136
include(CPM)
137137

138138
# library
139-
add_subdirectory(project)
139+
add_subdirectory(my-hovercraft-is-full-of-eels)
140140
# unit tests --only enable if requested AND we're not building as a sub-project
141-
if(ENABLE_TESTS AND NOT PROJECT_SUBPROJECT)
142-
message(STATUS "[project] Unit Tests Enabled")
141+
if(ENABLE_TESTS AND NOT MY_HOVERCRAFT_IS_FULL_OF_EELS_SUBPROJECT)
142+
message(STATUS "[my-hovercraft-is-full-of-eels] Unit Tests Enabled")
143143
add_subdirectory(tests)
144144
enable_testing()
145145
endif()

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ WARN_LOGFILE =
771771
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
772772
# Note: If this tag is empty the current directory is searched.
773773

774-
INPUT = project
774+
INPUT = my-hovercraft-is-full-of-eels
775775

776776
# This tag can be used to specify the character encoding of the source files
777777
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,37 @@ A template for a cross-platform C++20 project including modern CMake, unit-testi
44
## What's included
55
- CMake C++20 project skeleton, with strict warning flags enabled when using GCC or Clang.
66
- Usage of modern CMake practices for setting project-wide compiler options, etc. in a target-focused way.
7-
- Properly exported CMake project that can be used by other CMake projects with minimal effort (no hand-written `FindMyProject.cmake` files)
7+
- Properly exported CMake project that can be used by other CMake projects with minimal effort (no hand-written `FindProject.cmake` files)
88
- Unit testing using [Catch2](https://github.com/catchorg/Catch2), with automatic test discovery integration with CTest.
99
- Github Actions config files supporting building and running tests on Linux, macOS and Windows using the following compilers:
1010
- Linux: GCC-10, Clang-10
1111
- macOS: GCC-10, Clang-12
1212
- Windows: MSVC 2019
1313
- Building Releases on each platform when a Github Release is published, uploading these as build Artifacts.
1414
- Doxygen config file with tweaks from the default config settings to provide a few more graphs (usage, caller/callee relationships) than are enabled by default.
15+
- Doxygen docs are also built as part of release builds, and these are uploaded to the gh-pages branch under a versioned URL, versioned to the minor version.
16+
> For these docs to work properly, you need to observe the expected tag naming format for the tags you select for your Github Releases. The system expects semantic-versioning to be used, with tags of the format `vX.X.X` where `X` is a number. Docs of previous versions of the same minor version are overwritten when a new version for that same minor version is released. Docs of other minor versions are never deleted automatically.
1517
1618
> **Note** There's also a Travis-CI build config for a cross-platform build of similar structure to the Github Actions builds, however this is no longer maintained as Travis-CI has been found to not support more recent versions of CMake on all platforms.
1719
1820
## Usage
1921
1. Click the <kbd>Use this template</kbd> button at the top of this page to create your own new copy of this template
2022
2. Fill in the project details on the next page as you desire
21-
3. Once you've got your new project produced from this template, make changes in the following files:
22-
- `CMakeLists.txt`, `project/CMakeLists.txt`, `project/src/CMakeLists.txt`, `tests/CMakeLists.txt`:
23-
- Replace all instances of `PROJECT`, `project` and `Project` with your project's name, capitalised or uncapitalised as appropriate
24-
- `Doxyfile`:
25-
- Change the `PROJECT_NAME` and `INPUT` settings to your project's name.
26-
- `project`:
27-
- Rename this directory to the name of your project.
23+
3. Once you've got your new project produced from this template, do a find-and-replace globally within the project with the following substitutions:
24+
- `my-hovercraft-is-full-of-eels` -> your project name in lowercase. You could use `-` to separate words if you like.
25+
- `MyHovercraftIsFullOfEels` -> your project name in UpperCamelCase. Recommended to capitalise each word.
26+
- `MY_HOVERCRAFT_IS_FULL_OF_EELS` -> your project name in UPPER_SNAKE_CASE. Recommended to separate at the words.
27+
- `com::saxbophone::my_hovercraft_is_full_of_eels` -> an appropriate C++ namespace for your project.
28+
29+
Also rename the following directories in the same way:
30+
- `my-hovercraft-is-full-of-eels`
31+
- `my-hovercraft-is-full-of-eels/include/my-hovercraft-is-full-of-eels`
32+
2833
- **Choose a Software License for your code** if it is open-source and you want other people to be able to use it with ease!
2934

30-
This _project template_ is placed into the public domain, but you may want to use a different license for your own projects that you create from this template. Here is the public domain dedication text for this project:
35+
This _project template_ is placed into the public domain, but you should make your own choice of software license to use for projects that you create from this template.
36+
37+
Here is the public domain dedication text for this project:
3138

3239
```
3340
This is free and unencumbered software released into the public domain.
@@ -57,4 +64,4 @@ A template for a cross-platform C++20 project including modern CMake, unit-testi
5764
```
5865
4. Enjoy!
5966
60-
> The above instructions are the bare minimum required to get your own project based on this template off of the ground. You'll almost certainly want to change more things in `Doxyfile` and definitely `README.md`, but that should be well within the capabilities of a developer and also beyond the scope of this guide.
67+
> The above instructions are the bare minimum required to get your own project based on this template off of the ground. You'll almost certainly want to change more things in `Doxyfile` and definitely `README.md`, but these are documented better in other places and also beyond the scope of this guide.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
include(GNUInstallDirs)
2+
3+
add_library(my-hovercraft-is-full-of-eels STATIC)
4+
# ALIAS target to export a namespaced target even when building in-tree
5+
add_library(MyHovercraftIsFullOfEels::my-hovercraft-is-full-of-eels ALIAS my-hovercraft-is-full-of-eels)
6+
# add source files
7+
add_subdirectory(src)
8+
# library public header files location
9+
target_include_directories(
10+
my-hovercraft-is-full-of-eels PUBLIC
11+
# different include directory path depending on if using the local or installed version of library
12+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
13+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
14+
)
15+
# pass in version of project as preprocessor definitions
16+
target_compile_definitions(
17+
my-hovercraft-is-full-of-eels PRIVATE
18+
-DMY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
19+
-DMY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_MINOR=${PROJECT_VERSION_MINOR}
20+
-DMY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_PATCH=${PROJECT_VERSION_PATCH}
21+
-DMY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_STRING=${MY_HOVERCRAFT_IS_FULL_OF_EELS_ESCAPED_VERSION_STRING}
22+
)
23+
# set up version and soversion for the main library object
24+
set_target_properties(
25+
my-hovercraft-is-full-of-eels PROPERTIES
26+
VERSION ${MY_HOVERCRAFT_IS_FULL_OF_EELS_VERSION_STRING}
27+
SOVERSION ${PROJECT_VERSION_MAJOR}
28+
INTERFACE_MyHovercraftIsFullOfEels_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
29+
INTERFACE_MyHovercraftIsFullOfEels_MINOR_VERSION ${PROJECT_VERSION_MINOR}
30+
)
31+
set_property(
32+
TARGET my-hovercraft-is-full-of-eels
33+
APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "${MyHovercraftIsFullOfEels_MAJOR_VERSION}.${MyHovercraftIsFullOfEels_MINOR_VERSION}"
34+
)
35+
# inherit common project compiler options
36+
target_link_libraries(
37+
my-hovercraft-is-full-of-eels
38+
PRIVATE
39+
$<BUILD_INTERFACE:my-hovercraft-is-full-of-eels-compiler-options>
40+
)
41+
42+
# install if we're not being built as a sub-project
43+
if (NOT MY_HOVERCRAFT_IS_FULL_OF_EELS_SUBMY_HOVERCRAFT_IS_FULL_OF_EELS)
44+
# library
45+
install(
46+
TARGETS my-hovercraft-is-full-of-eels
47+
EXPORT MyHovercraftIsFullOfEelsTargets
48+
# when a static library
49+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
50+
# when a shared library on UNIX
51+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
52+
# when a DLL on Windows
53+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
54+
)
55+
# public headers
56+
install(
57+
DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
58+
)
59+
# CMake export
60+
install(
61+
EXPORT MyHovercraftIsFullOfEelsTargets
62+
FILE MyHovercraftIsFullOfEelsTargets.cmake
63+
NAMESPACE MyHovercraftIsFullOfEels::
64+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MyHovercraftIsFullOfEels"
65+
)
66+
# CMake package
67+
include(CMakePackageConfigHelpers)
68+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
69+
"${CMAKE_CURRENT_BINARY_DIR}/MyHovercraftIsFullOfEelsConfig.cmake"
70+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MyHovercraftIsFullOfEels"
71+
)
72+
# generate the version file for the config file
73+
write_basic_package_version_file(
74+
"${CMAKE_CURRENT_BINARY_DIR}/MyHovercraftIsFullOfEelsConfigVersion.cmake"
75+
VERSION "${version}"
76+
COMPATIBILITY SameMinorVersion
77+
)
78+
install(
79+
FILES
80+
"${CMAKE_CURRENT_BINARY_DIR}/MyHovercraftIsFullOfEelsConfig.cmake"
81+
"${CMAKE_CURRENT_BINARY_DIR}/MyHovercraftIsFullOfEelsConfigVersion.cmake"
82+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MyHovercraftIsFullOfEels"
83+
)
84+
endif()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/MyHovercraftIsFullOfEelsTargets.cmake")
4+
5+
check_required_components(MyHovercraftIsFullOfEels)

project/include/project/Public.hpp renamed to my-hovercraft-is-full-of-eels/include/my-hovercraft-is-full-of-eels/Public.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
*
1515
*/
1616

17-
#ifndef COM_SAXBOPHONE_PROJECT_PUBLIC_HPP
18-
#define COM_SAXBOPHONE_PROJECT_PUBLIC_HPP
17+
#ifndef COM_SAXBOPHONE_MY_HOVERCRAFT_IS_FULL_OF_EELS_PUBLIC_HPP
18+
#define COM_SAXBOPHONE_MY_HOVERCRAFT_IS_FULL_OF_EELS_PUBLIC_HPP
1919

20-
namespace com::saxbophone::project {
20+
namespace com::saxbophone::my_hovercraft_is_full_of_eels {
2121
/**
2222
* @brief Stub test function for sample project
2323
* @returns Whether the test library "works" or not, which is a vague

project/src/CMakeLists.txt renamed to my-hovercraft-is-full-of-eels/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# top-level namespace source files
22
target_sources(
3-
project
3+
my-hovercraft-is-full-of-eels
44
PRIVATE
55
Private.cpp
66
Public.cpp

project/src/Private.cpp renamed to my-hovercraft-is-full-of-eels/src/Private.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "Private.hpp"
88

9-
namespace com::saxbophone::project::PRIVATE {
9+
namespace com::saxbophone::my_hovercraft_is_full_of_eels::PRIVATE {
1010
bool library_works() {
1111
return true;
1212
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* This is a sample private compilation unit.
3+
*
4+
* <Copyright information goes here>
5+
*/
6+
7+
#ifndef COM_SAXBOPHONE_MY_HOVERCRAFT_IS_FULL_OF_EELS_PRIVATE_HPP
8+
#define COM_SAXBOPHONE_MY_HOVERCRAFT_IS_FULL_OF_EELS_PRIVATE_HPP
9+
10+
#include <my-hovercraft-is-full-of-eels/Public.hpp>
11+
12+
namespace com::saxbophone::my_hovercraft_is_full_of_eels::PRIVATE {
13+
bool library_works();
14+
}
15+
16+
#endif // include guard

0 commit comments

Comments
 (0)