Skip to content
Snippets Groups Projects
Commit 46976e4f authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add example useage to README

parent 0e7728ef
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,78 @@ A collection of CMake helper functions and tools that are common to all IHTA C++
- `ihta_add_test`: Adds a unit test executable target including downloading the dependencies, CTest registration and optional code coverage.
- `build_doc`: Builds doxygen documentation with nice styling.
## Usage
Here is an example of the usage:
```cmake
cmake_minimum_required(VERSION 3.20)
# optionally disable code coverage
set(IHTA_COMMON_ENABLE_CODE_COVERAGE ON)
include (FetchContent)
FetchContent_Declare (
IHTACMakeCommon
GIT_REPOSITORY https://git.rwth-aachen.de/ihta/cmake/ihtacmakecommon.git
GIT_TAG main
)
FetchContent_MakeAvailable (IHTACMakeCommon)
init_project ()
project (AwesomeProjectName
LANGUAGES CXX C
VERSION 1.0.0
)
CPMAddPackage("gh:gabime/spdlog@1.8.2")
# Add the library target with unit test
ihta_add_library (
NAME ${PROJECT_NAME}
SOURCES include/project.h src/project.cpp
NAMESPACE IHTA
IDE_FOLDER ${PROJECT_NAME}
LIBRARY_TYPE STATIC
TEST_INTERNALS
OUT_LIB LIB_TARGET
OUT_TEST TEST_TARGET
TEST_SOURCES test/test.cpp
)
# Add external library link to library
target_link_libraries(${LIB_TARGET} PRIVATE spdlog)
# Add external library link to unit test
target_link_libraries(${TEST_TARGET} PRIVATE OtherExternalLibrary)
# Install & export
packageProject (
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
DEPENDENCIES "ExternalLibrary"
COMPATIBILITY ExactVersion
NAMESPACE IHTA
DISABLE_VERSION_SUFFIX YES
VERSION_HEADER "AwesomeProjectName_version.h"
EXPORT_HEADER "AwesomeProjectName_export.h"
)
# Needed so the object library knows the location of the generated headers from packageProject.
target_include_directories (${LIB_TARGET} PUBLIC "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/PackageProjectInclude>")
target_include_directories (${TEST_TARGET} PUBLIC "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/PackageProjectInclude>")
build_doc (
ADD_DEV_SECTION OFF
README_MAINPAGE ${CMAKE_CURRENT_SOURCE_DIR}/README.md
SOURCES "include" "src" "docs"
)
```
## References
- [cpp_coverage](https://github.com/ekcoh/cpp-coverage/blob/master/cmake/cpp_coverage.cmake)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment