Enable cmake formatting (#53)

* enable cmake formatting

* update style check workflow

* update readme

* update wording
This commit is contained in:
Lars Melchior 2020-08-11 11:10:01 +02:00 committed by GitHub
parent 4e87a9410a
commit 866ae707e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 85 deletions

View file

@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# ---- Project ----
# Note: update this to your new project's name and version
project(Greeter
project(
Greeter
VERSION 1.0
LANGUAGES CXX
)
@ -11,7 +12,10 @@ project(Greeter
# ---- Include guards ----
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
# ---- Add dependencies via CPM ----
@ -28,16 +32,16 @@ CPMAddPackage(
# ---- Add source files ----
# Note: globbing sources is considered bad practice as CMake's generators may not detect new files automatically.
# Keep that in mind when changing files, or explicitly mention them here.
FILE(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
FILE(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
# Note: globbing sources is considered bad practice as CMake's generators may not detect new files
# automatically. Keep that in mind when changing files, or explicitly mention them here.
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
# ---- Create library ----
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface target:
# add_library(Greeter INTERFACE)
# set_target_properties(Greeter PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17)
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target: add_library(Greeter INTERFACE) set_target_properties(Greeter PROPERTIES
# INTERFACE_COMPILE_FEATURES cxx_std_17)
add_library(Greeter ${headers} ${sources})
@ -46,20 +50,18 @@ set_target_properties(Greeter PROPERTIES CXX_STANDARD 17)
# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(Greeter PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")
# Link dependencies (if required)
# target_link_libraries(Greeter PUBLIC cxxopts)
# Link dependencies (if required) target_link_libraries(Greeter PUBLIC cxxopts)
target_include_directories(Greeter
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
target_include_directories(
Greeter PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)
# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.
# the location where the project's version header will be placed
# should match the project's regular header paths
# the location where the project's version header will be placed should match the project's regular
# header paths
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)
packageProject(