-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👋🏽 Add example on how to import and use cib in a project. (#39)
* clarifications to the build in the README * create hello_world example by extracting it from the README
- Loading branch information
1 parent
ea1d603
commit 1018429
Showing
15 changed files
with
385 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,3 +155,4 @@ jobs: | |
with: | ||
name: cib.hpp | ||
path: ${{github.workspace}}/build/include/cib/cib.hpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/Testing/ | ||
/cmake-build* | ||
/venv/ | ||
/examples/hello_world/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,79 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(compile_time_init_build) | ||
|
||
|
||
if (DEFINED ENV{CXX_STANDARD} AND NOT $ENV{CXX_STANDARD} EQUAL "") | ||
set(CMAKE_CXX_STANDARD $ENV{CXX_STANDARD}) | ||
if(NOT DEFINED PROJECT_NAME) | ||
set(NOT_SUBPROJECT ON) | ||
else() | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(NOT_SUBPROJECT OFF) | ||
endif() | ||
message("CMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}") | ||
|
||
enable_testing() | ||
|
||
add_subdirectory(lib/Catch2) | ||
add_subdirectory(test) | ||
add_subdirectory(benchmark) | ||
|
||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/cib/) | ||
|
||
add_custom_command( | ||
DEPENDS | ||
${CMAKE_SOURCE_DIR}/tools/gen_release_header.py | ||
${CMAKE_SOURCE_DIR}/include/cib/* | ||
${CMAKE_SOURCE_DIR}/include/cib/detail/* | ||
COMMAND | ||
python3 ${CMAKE_SOURCE_DIR}/tools/gen_release_header.py ${CMAKE_SOURCE_DIR}/include/cib/cib.hpp > ${CMAKE_BINARY_DIR}/include/cib/cib.hpp | ||
OUTPUT | ||
${CMAKE_BINARY_DIR}/include/cib/cib.hpp | ||
) | ||
|
||
add_custom_target(release_header | ||
DEPENDS | ||
${CMAKE_BINARY_DIR}/include/cib/cib.hpp) | ||
|
||
|
||
|
||
add_library(Cib INTERFACE) | ||
project( | ||
cib | ||
VERSION 0.1.0 | ||
LANGUAGES CXX | ||
DESCRIPTION "A header-only C++ library for composing modular firmware at compile-time." | ||
HOMEPAGE_URL "https://github.com/intel/compile-time-init-build") | ||
|
||
add_library(cib INTERFACE) | ||
target_compile_features(cib INTERFACE cxx_std_17) | ||
|
||
|
||
|
||
if(NOT_SUBPROJECT) | ||
if (DEFINED ENV{CXX_STANDARD} AND NOT $ENV{CXX_STANDARD} EQUAL "") | ||
set(CMAKE_CXX_STANDARD $ENV{CXX_STANDARD}) | ||
else() | ||
set(CMAKE_CXX_STANDARD 17) | ||
endif() | ||
|
||
find_package(Git QUIET) | ||
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") | ||
message("Updating git submodules...") | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
RESULT_VARIABLE GIT_RETVAL) | ||
if(NOT GIT_RETVAL EQUAL "0") | ||
message(FATAL_ERROR "git submodule update failed!") | ||
endif() | ||
endif() | ||
|
||
# Enable functional and performance test suites. | ||
enable_testing() | ||
add_subdirectory(lib/Catch2) | ||
add_subdirectory(test) | ||
add_subdirectory(benchmark) | ||
|
||
# Build single-header release. | ||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/cib/) | ||
|
||
find_package(PythonInterp 3 REQUIRED) | ||
|
||
add_custom_command( | ||
DEPENDS | ||
${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_release_header.py | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/cib/* | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/cib/detail/* | ||
COMMAND | ||
python3 ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_release_header.py ${CMAKE_CURRENT_SOURCE_DIR}/include/cib/cib.hpp > ${CMAKE_CURRENT_BINARY_DIR}/include/cib/cib.hpp | ||
OUTPUT | ||
${CMAKE_CURRENT_BINARY_DIR}/include/cib/cib.hpp | ||
) | ||
|
||
add_custom_target(release_header | ||
DEPENDS | ||
${CMAKE_CURRENT_BINARY_DIR}/include/cib/cib.hpp) | ||
endif() | ||
|
||
if ($ENV{SINGLE_HEADER}) | ||
message("Using single-header version of cib.hpp.") | ||
|
||
add_dependencies(Cib release_header) | ||
|
||
target_include_directories(Cib | ||
INTERFACE | ||
${CMAKE_BINARY_DIR}/include/) | ||
add_dependencies(cib release_header) | ||
|
||
target_include_directories(cib INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/> | ||
) | ||
else() | ||
message("Using multi-header version of cib.hpp.") | ||
|
||
target_include_directories(Cib | ||
INTERFACE | ||
${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
target_sources(Cib | ||
INTERFACE | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/cib/cib.hpp) | ||
endif() | ||
target_include_directories(cib INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/> | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(hello_world LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
add_executable(hello_world main.cpp dont_panic.cpp) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
cib | ||
GIT_REPOSITORY https://github.com/intel/compile-time-init-build.git | ||
|
||
# update this to a more recent commit ID for your project | ||
GIT_TAG 8b35ed8f6fb358234a916768c81a924a373c80ff | ||
) | ||
FetchContent_MakeAvailable(cib) | ||
|
||
target_link_libraries(hello_world cib) |
Oops, something went wrong.