Skip to content

Commit ad3c64f

Browse files
committed
add single header generation
1 parent f320581 commit ad3c64f

File tree

11 files changed

+96
-36
lines changed

11 files changed

+96
-36
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,31 @@ project(7bitDI LANGUAGES CXX VERSION ${_7BIT_DI_VERSION})
1010

1111
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Cmake")
1212

13-
include_directories(Include)
1413
include(Setup)
1514

1615
set(CMAKE_CXX_STANDARD 17)
1716
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1817

18+
include_directories(${CMAKE_SOURCE_DIR}/Include)
19+
1920
add_subdirectory(Source)
2021

2122
if(_7BIT_DI_BUILD_DOCS)
2223
add_subdirectory(Docs)
2324
endif()
2425

2526
if(_7BIT_DI_BUILD_TESTS)
26-
include(GoogleTest)
27-
enable_testing()
28-
2927
add_subdirectory(Tests)
3028
endif()
3129

3230
if(_7BIT_DI_BUILD_EXAMPLES)
3331
add_subdirectory(Examples)
3432
endif()
3533

34+
if(_7BIT_DI_BUILD_SINGLE_HEADER)
35+
add_subdirectory(SingleHeader)
36+
endif()
37+
3638
if(_7BIT_DI_INSTALL)
3739
install(DIRECTORY ${_7BIT_DI_HEADERS_DIR}/ DESTINATION include)
3840

Cmake/FindQuom.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
find_program(QUOM_EXECUTABLE
2+
NAMES quom
3+
DOC "Path to quom executable")
4+
5+
include(FindPackageHandleStandardArgs)
6+
7+
find_package_handle_standard_args(quom
8+
"Failed to find quom executable"
9+
QUOM_EXECUTABLE)

Cmake/Setup.cmake

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,27 @@ set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:\$ORIGIN/../bin:\$ORIGIN)
3232

3333
set(_7BIT_DI_HEADERS_DIR "${CMAKE_SOURCE_DIR}/Include")
3434

35+
set(_7BIT_DI_MAIN_HEADER "${_7BIT_DI_HEADERS_DIR}/SevenBit/DI.hpp")
3536
file(GLOB _7BIT_DI_TOP_HEADERS "${_7BIT_DI_HEADERS_DIR}/SevenBit/DI/*.hpp")
3637
file(GLOB _7BIT_DI_DETAILS_HEADERS "${_7BIT_DI_HEADERS_DIR}/SevenBit/DI/Details/*.hpp")
3738
file(GLOB _7BIT_DI_IMPL_HEADERS "${_7BIT_DI_HEADERS_DIR}/SevenBit/DI/Impl/*.hpp")
38-
set(_7BIT_DI_ALL_HEADERS ${_7BIT_DI_TOP_HEADERS} ${_7BIT_DI_DETAILS_HEADERS} ${_7BIT_DI_IMPL_HEADERS})
39+
set(_7BIT_DI_ALL_HEADERS ${_7BIT_DI_MAIN_HEADER} ${_7BIT_DI_TOP_HEADERS} ${_7BIT_DI_DETAILS_HEADERS} ${_7BIT_DI_IMPL_HEADERS})
3940

4041
source_group("Header Files\\SevenBit" FILES ${_7BIT_DI_TOP_HEADERS})
4142
source_group("Header Files\\SevenBit\\Details" FILES ${_7BIT_DI_DETAILS_HEADERS})
4243
source_group("Header Files\\SevenBit\\Details\\Impl" FILES ${_7BIT_DI_IMPL_HEADERS})
4344

44-
option(_7BIT_DI_LIBRARY_TYPE "Library build type: Shared;Static;HeaderOnly" "Static")
45+
set(_7BIT_DI_LIBRARY_TYPE "Static" CACHE STRING "Library build type: Shared;Static;HeaderOnly")
46+
set(_7BIT_DI_LIBRARY_TYPE_VALUES "Shared;Static;HeaderOnly" CACHE STRING "List of possible _7BIT_DI_LIBRARY_TYPE values")
4547

46-
option(_7BIT_DI_LIBRARY_TYPE_VALUES "List of possible BUILD_LIBRARY_Type values" "Shared;Static;HeaderOnly")
47-
48-
set_property(CACHE _7BIT_DI_LIBRARY_TYPE PROPERTY STRINGS ${_7BIT_DI_LIBRARY_TYPE_VALUES})
49-
50-
option(_7BIT_DI_BUILD_SHARED "Build shared library" OFF)
48+
set_property(CACHE _7BIT_DI_LIBRARY_TYPE PROPERTY STRINGS Shared Static HeaderOnly)
5149

5250
option(_7BIT_DI_BUILD_PIC "Build position independent code (-fPIC)" OFF)
53-
5451
option(_7BIT_DI_BUILD_EXAMPLES "Build example" OFF)
55-
5652
option(_7BIT_DI_BUILD_TESTS "Build tests" OFF)
57-
5853
option(_7BIT_DI_BUILD_DOCS "Turn on to build documentation (requires sphinx and doxygen installed)" OFF)
59-
6054
option(_7BIT_DI_INSTALL "Installs 7bitDI" OFF)
55+
option(_7BIT_DI_BUILD_SINGLE_HEADER "Builds single header SevenBitDI.hpp" OFF)
6156

6257
if(_7BIT_DI_BUILD_PIC)
6358
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -89,5 +84,7 @@ set(INFOS
8984
"Build tests: ${_7BIT_DI_BUILD_TESTS}"
9085
"Build examples: ${_7BIT_DI_BUILD_EXAMPLES}"
9186
"Build documentation: ${_7BIT_DI_BUILD_DOCS}"
87+
"Build single header: ${_7BIT_DI_BUILD_SINGLE_HEADER}"
88+
"Install project: ${_7BIT_DI_INSTALL}"
9289
)
9390
printInfo("${INFOS}" = 50 7 0)

Docs/advanced-guides/building-library.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ Configure CMake project
1818
Using this command several cache variables can be set:
1919

2020
* <variable cache name>: [possible values] (default value) - Description
21-
* LIBRARY_TYPE: ["Shared", "Static", "HeaderOnly"] ("HeaderOnly") - Library build type
22-
* BUILD_DOCS: [true, false] (false) - Turn on to build documentation (requires Sphinx_, Breathe_ and Doxygen_ installed)
23-
* BUILD_TESTS: [true, false] (false) - Turn on to build tests (requires Gtest_ to be installed, see `Build Library With Conan`_)
24-
* BUILD_EXAMPLES: [true, false] (false) - Turn on to build examples
21+
* _7BIT_DI_LIBRARY_TYPE: ["Shared", "Static", "HeaderOnly"] ("Static") - Library build type
22+
* _7BIT_DI_BUILD_DOCS: ["ON", "OFF"] ("OFF") - Turn on to build documentation (requires Sphinx_, Breathe_ and Doxygen_ to be installed)
23+
* _7BIT_DI_BUILD_TESTS: ["ON", "OFF"] ("OFF") - Turn on to build tests (requires Gtest_ to be installed, see `Build Library With Conan`_)
24+
* _7BIT_DI_BUILD_EXAMPLES: ["ON", "OFF"] ("OFF") - Turn on to build examples
25+
* _7BIT_DI_BUILD_SINGLE_HEADER: ["ON", "OFF"] ("OFF") - Turn on to build single header SevenBitDI.hpp (requires Quom_ to be installed)
26+
* _7BIT_DI_INSTALL: ["ON", "OFF"] ("OFF") - Turn on to install library (output is in build/publish)
2527

2628
to set cache variable pass additional option: -D<variable cache name>=[value]
2729
for example, this command will set the library type to Static and will force examples built
2830

2931
.. code-block:: sh
3032
31-
cmake .. -DCMAKE_BUILD_TYPE=Release -DLIBRARY_TYPE=Static -DBUILD_EXAMPLES=true
33+
cmake .. -DCMAKE_BUILD_TYPE=Release -D_7BIT_DI_INSTALL=ON -D_7BIT_DI_LIBRARY_TYPE=Static -D_7BIT_DI_BUILD_EXAMPLES=true
3234
3335
Build the library using the command:
3436

@@ -38,7 +40,7 @@ Build the library using the command:
3840
3941
4042
Build Library With Conan
41-
^^^^^^^^^^^^^^^
43+
^^^^^^^^^^^^^^^^^^^^^^^^^
4244

4345
Gtest_ library is added to project using Conan_ package manager (`Conan Installation`_),
4446
If Conan was freshly installed run detect command:
@@ -63,7 +65,7 @@ Configure the CMake project, and add also toolchain file as a CMAKE_TOOLCHAIN_FI
6365

6466
.. code-block:: sh
6567
66-
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=true -DCMAKE_TOOLCHAIN_FILE:STRING="conan_toolchain.cmake"
68+
cmake .. -DCMAKE_TOOLCHAIN_FILE:PATH="./conan_toolchain.cmake" -DCMAKE_BUILD_TYPE=Release -D_7BIT_DI_BUILD_TESTS=ON -D_7BIT_DI_INSTALL=ON
6769
6870
Build the library using the command:
6971

@@ -78,4 +80,5 @@ Build the library using the command:
7880
.. _Doxygen: https://www.doxygen.nl/
7981
.. _Gtest: https://google.github.io/googletest/
8082
.. _Conan: https://conan.io/
83+
.. _Quom: https://pypi.org/project/quom/
8184
.. _`Conan Installation`: https://conan.io/downloads.html

Docs/getting-started.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,14 @@ Installation
3939
4040
include_directories(/SevenBitDI/Include)
4141
42-
#. Building library as Static/Shared
43-
Download source code from the most recent release,
44-
build the project using CMake_, set CMake cache var "_7BIT_DI_BUILD_SHARED" to build Shared library,
45-
run install command
46-
47-
.. code-block:: sh
42+
#. Header only - Single file
43+
Download SevenBitDI.hpp header file from the most recent release,
44+
copy this file into your project location and include it.
4845

49-
cmake --build ./build --target install
50-
51-
library files are located in the build/publish folder, include those files in your project,
52-
for more details see the `Building Library`_ guide
46+
#. Building library as Static/Shared
47+
Download source code from the most recent release, build or install the project using CMake_,
48+
library files are located in the build/publish folder,
49+
for more details see the `Building Library`_ guide.
5350

5451
Example Usage
5552
-----------------

Include/SevenBit/DI/CmakeDef.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#pragma once
22

3+
#ifndef _7BIT_DI_SHARED_LIB
34
/* #undef _7BIT_DI_SHARED_LIB */
5+
#endif
6+
7+
#ifndef _7BIT_DI_STATIC_LIB
48
/* #undef _7BIT_DI_STATIC_LIB */
9+
#endif
10+
11+
#ifndef _7BIT_DI_HEADER_ONLY_LIB
512
#define _7BIT_DI_HEADER_ONLY_LIB
13+
#endif
614

715

816
#define _7BIT_DI_VERSION_MAJOR 1

Include/SevenBit/DI/CmakeDef.hpp.input

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#pragma once
22

3+
#ifndef _7BIT_DI_SHARED_LIB
34
#cmakedefine _7BIT_DI_SHARED_LIB
4-
#cmakedefine _7BIT_DI_STATIC_LIB
5+
#endif
6+
7+
#ifndef _7BIT_DI_STATIC_LIB
8+
#cmakedefine _7BIT_DI_STATIC_LIB
9+
#endif
10+
11+
#ifndef _7BIT_DI_HEADER_ONLY_LIB
512
#cmakedefine _7BIT_DI_HEADER_ONLY_LIB
13+
#endif
614

715

816
#cmakedefine _7BIT_DI_VERSION_MAJOR @_7BIT_DI_VERSION_MAJOR@

Include/SevenBit/DI/LibraryConfig.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "SevenBit/DI/CmakeDef.hpp"
4-
#include "SevenBit/DI/Export.hpp"
54

65
#ifndef _7BIT_DI_VERSION
76

@@ -17,11 +16,16 @@
1716

1817
#ifdef _7BIT_DI_HEADER_ONLY_LIB
1918

19+
#undef _7BIT_DI_SHARED_LIB
20+
#undef _7BIT_DI_STATIC_LIB
21+
2022
#define _7BIT_DI_ADD_IMPL
2123
#define INLINE inline
2224

2325
#else
2426

2527
#define INLINE
2628

27-
#endif
29+
#endif
30+
31+
#include "SevenBit/DI/Export.hpp"

SingleHeader/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
find_package(quom REQUIRED)
2+
3+
set(_7BIT_DI_SINGLE_IN ${CMAKE_CURRENT_SOURCE_DIR}/SevenBitDI.hpp.in)
4+
set(_7BIT_DI_SINGLE_OUT ${CMAKE_CURRENT_BINARY_DIR}/SevenBitDI.hpp)
5+
6+
add_custom_command(OUTPUT ${_7BIT_DI_SINGLE_OUT}
7+
COMMAND
8+
${QUOM_EXECUTABLE} ${_7BIT_DI_SINGLE_IN} ${_7BIT_DI_SINGLE_OUT} -I ${_7BIT_DI_HEADERS_DIR}
9+
DEPENDS
10+
${_7BIT_DI_ALL_HEADERS}
11+
COMMENT "Generating single header with Quom")
12+
13+
add_custom_target(GenerateSingleHeader
14+
ALL DEPENDS
15+
${_7BIT_DI_SINGLE_OUT}
16+
${_7BIT_DI_MAIN_HEADER}
17+
)
18+
19+
if(_7BIT_DI_INSTALL)
20+
install(FILES ${_7BIT_DI_SINGLE_OUT}
21+
DESTINATION single-header)
22+
endif()

SingleHeader/SevenBitDI.hpp.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#define _7BIT_DI_HEADER_ONLY_LIB
4+
5+
#include "SevenBit/DI.hpp"

0 commit comments

Comments
 (0)