All new build system

This is based on GavinNL/cpp_library_template, which seems to be a
bit closer to meeting my needs.
This commit is contained in:
James P. Howard, II
2020-09-24 13:14:18 -04:00
parent 870e7b8cfc
commit 7d5482c082
86 changed files with 2124 additions and 871 deletions

55
.ci-files/.travis.yml Normal file
View File

@@ -0,0 +1,55 @@
linux: &linux
os: linux
dist: xenial
language: python
python: "3.7"
services:
- docker
osx: &osx
os: osx
language: generic
matrix:
include:
- <<: *linux
env: CONAN_GCC_VERSIONS=4.9 CONAN_DOCKER_IMAGE=conanio/gcc49
- <<: *linux
env: CONAN_GCC_VERSIONS=5 CONAN_DOCKER_IMAGE=conanio/gcc5
- <<: *linux
env: CONAN_GCC_VERSIONS=6 CONAN_DOCKER_IMAGE=conanio/gcc6
- <<: *linux
env: CONAN_GCC_VERSIONS=7 CONAN_DOCKER_IMAGE=conanio/gcc7
- <<: *linux
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
- <<: *linux
env: CONAN_CLANG_VERSIONS=3.9 CONAN_DOCKER_IMAGE=conanio/clang39
- <<: *linux
env: CONAN_CLANG_VERSIONS=4.0 CONAN_DOCKER_IMAGE=conanio/clang40
- <<: *linux
env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50
- <<: *linux
env: CONAN_CLANG_VERSIONS=6.0 CONAN_DOCKER_IMAGE=conanio/clang60
- <<: *linux
env: CONAN_CLANG_VERSIONS=7.0 CONAN_DOCKER_IMAGE=conanio/clang7
- <<: *osx
osx_image: xcode7.3
env: CONAN_APPLE_CLANG_VERSIONS=7.3
- <<: *osx
osx_image: xcode8.3
env: CONAN_APPLE_CLANG_VERSIONS=8.1
- <<: *osx
osx_image: xcode9
env: CONAN_APPLE_CLANG_VERSIONS=9.0
- <<: *osx
osx_image: xcode9.4
env: CONAN_APPLE_CLANG_VERSIONS=9.1
- <<: *osx
osx_image: xcode10.1
env: CONAN_APPLE_CLANG_VERSIONS=10.0
install:
- chmod +x .ci/install.sh
- ./.ci/install.sh
script:
- chmod +x .ci/run.sh
- ./.ci/run.sh

View File

@@ -0,0 +1,66 @@
[server]
# WARNING! Change default variable of jwt_secret. You should change it periodically
# It only affects to current authentication tokens, you can change safetely anytime
# When it changes user are just forced to log in again
jwt_secret: dSktZiPDNsiBpFQKWIpUgdHp
jwt_expire_minutes: 120
ssl_enabled: False
port: 9300
# Public port where files will be served. If empty will be used "port"
public_port:
host_name: localhost
# Authorize timeout are seconds the client has to upload/download files until authorization expires
authorize_timeout: 1800
# Just for disk storage adapter
# updown_secret is the key used to generate the upload/download authorization token
disk_storage_path: ~/.conan_server/data
disk_authorize_timeout: 1800
updown_secret: EHKKsMYJTeyLITZlwrRVJJIL
# Check docs.conan.io to implement a different authenticator plugin for conan_server
# if custom_authenticator is not specified, [users] section will be used to authenticate
# the users.
#
# custom_authenticator: my_authenticator
# name/version@user/channel: user1, user2, user3
#
# The rules are applied in order.
# If a rule matches your package, then the server wont look further.
# Place your more restrictive rules first.
#
# Example: All versions of opencv package from lasote user in testing channel is only
# writeable by default_user and default_user2. Rest of packages are not writtable by anything
# except the author.
#
# opencv/2.3.4@lasote/testing: default_user, default_user2
#
[write_permissions]
*/*@*/*: *
# name/version@user/channel: user1, user2, user3
# The rules are applied in order. If a rule applies to a conan, system wont look further.
#
# Example:
# All versions of opencv package from lasote user in testing channel are only
# readable by default_user and default_user2.
# All versions of internal package from any user/channel are only readable by
# authenticated users.
# Rest of packages are world readable.
#
# opencv/*@lasote/testing: default_user default_user2
# internal/*@*/*: ?
# */*@*/*: *
#
# By default all users can read all blocks
#
[read_permissions]
*/*@*/*: *
[users]
#default_user: defaultpass
demo: demo

View File

@@ -0,0 +1,27 @@
#!/bin/bash
set -e
set -x
if [[ "$(uname -s)" == 'Darwin' ]]; then
echo "Darwin!"
brew install cmake || true
brew upgrade cmake
else
VERSION=3.13.4
which cmake
wget -q https://github.com/Kitware/CMake/releases/download/v${VERSION}/cmake-${VERSION}-Linux-x86_64.tar.gz -O cmake.tar.gz
tar -xzf cmake.tar.gz
# Remove the original files and copy the new ones over.
#sudo rm -rf /usr/local/cmake-3.12.4/*
sudo cp -r cmake-${VERSION}*/* $(dirname $(dirname $(which cmake)))
which cmake
fi
cmake --version

View File

@@ -0,0 +1,25 @@
#!/bin/bash
set -e
set -x
if [[ "$(uname -s)" == 'Darwin' ]]; then
brew update || brew update
brew outdated pyenv || brew upgrade pyenv
brew install pyenv-virtualenv
brew install cmake || true
if which pyenv > /dev/null; then
eval "$(pyenv init -)"
fi
pyenv install 2.7.10
pyenv virtualenv 2.7.10 conan
pyenv rehash
pyenv activate conan
fi
pip install conan --upgrade
pip install conan_package_tools bincrafters_package_tools
conan user
conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan

14
.ci-files/run.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
set -e
set -x
if [[ "$(uname -s)" == 'Darwin' ]]; then
if which pyenv > /dev/null; then
eval "$(pyenv init -)"
fi
pyenv activate conan
fi
conan create . local/testing
#python build.py

View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -e
set -x
mkdir -p $HOME/.conan_server
cp .ci-files/conan_server/* $HOME/.conan_server
conan_server &
sleep 3

View File

@@ -1,36 +0,0 @@
name: CI
on: [push]
jobs:
build-ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Download Conan package manager.
run: |
pwd
pip3 install wheel setuptools
pip3 install conan
export PATH=$PATH:/home/runner/.local/bin
echo $PATH
conan --version
ls
- name: configure
run: |
export PATH=$PATH:/home/runner/.local/bin
echo $PATH
mkdir build
cd build
conan install ..
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_DOCS=OFF ..
- name: build
run: |
cd build
make
- name: test
run: cd build && ctest

10
.gitignore vendored
View File

@@ -30,7 +30,11 @@
*.exe
*.out
*.app
*.x
# Build directory
build/
# Build directories
*/build/*
*/build-*/*
build/*
# Qtcreator files
*.user

159
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,159 @@
stages:
- analysis
- build
- test
cppcheck:
image: ubuntu:bionic
stage: analysis
before_script:
- apt update
- apt install -y --no-install-recommends cppcheck=1.82-1 python3-pygments python-pygments
- cppcheck --version
script:
- mkdir cppcheck
#- cppcheck . -I include/ --verbose --enable=all --inconclusive --language=c++ --error-exitcode=1
- cppcheck . -I include/ --enable=all --inconclusive --xml-version=2 --force --library=windows,posix,gnu . 2> cppcheck/result.xml
- cppcheck-htmlreport --source-encoding="iso8859-1" --title="my project name" --source-dir . --report-dir=cppcheck --file=cppcheck/result.xml
artifacts:
paths:
- cppcheck/
expire_in: 1 week
.build_template: &job_definition
image: conanio/gcc7
stage: build
before_script:
- env
- sudo apt update
- sudo apt install -y python3-pip
- sudo pip3 install gcovr
- sudo chmod +x ./.ci-files/install_conan.sh
- sudo chmod +x ./.ci-files/install_cmake.sh
- sudo chmod +x ./.ci-files/run_conan_server.sh
- ./.ci-files/install_conan.sh
- ./.ci-files/install_cmake.sh
#
- ./.ci-files/run_conan_server.sh
- conan remote add local http://localhost:9300
- conan remote list
script:
- echo $USER --- $HOME
- echo Working directory $PWD
### Test that we can build the library properly
- mkdir -p build && cd build
- cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/local
- cmake --build .
- ctest
- mkdir -p artifacts/coverage
- gcovr . -r .. --html-details --html -o artifacts/coverage/index.html -e ../test/third_party
- sudo cmake --build . --target install
## Test that we can build the test application
## and the find_package method works correctly.
- rm -rf *
- cmake ../test_cmake_install/cmake -D CMAKE_PREFIX_PATH=$HOME/local
- cmake --build .
- ctest
## Build the Conan package and upload it to the local repo.
- cd ..
- conan user -p demo demo -r=local
- conan create . local/testing
- conan upload foo* -r=local -c --all
- conan search "*" -r=local
artifacts:
paths:
- artifacts/*
expire_in: 1 week
build-gcc5:
<<: *job_definition # Merge the contents of the 'job_definition' alias
image: conanio/gcc5
build-gcc6:
<<: *job_definition # Merge the contents of the 'job_definition' alias
image: conanio/gcc6
build-gcc7:
<<: *job_definition # Merge the contents of the 'job_definition' alias
image: conanio/gcc7
build-gcc8:
<<: *job_definition # Merge the contents of the 'job_definition' alias
image: conanio/gcc8
build-clang60:
<<: *job_definition
image: conanio/clang60
build-clang40:
<<: *job_definition
image: conanio/clang40
build-clang50:
<<: *job_definition
image: conanio/clang50
build-clang7:
<<: *job_definition
image: conanio/clang7
build-clang39:
<<: *job_definition
image: conanio/clang39
###############################################################################
# The test package stage tests whether the different Conan generators work
# correctly with the
###############################################################################
.test_package: &test_package_definition
image: conanio/gcc7
stage: test
dependencies:
- build-gcc5
- build-gcc6
- build-gcc7
- build-gcc8
before_script:
- env
- sudo apt update
- sudo chmod +x ./.ci-files/install_conan.sh
- sudo chmod +x ./.ci-files/install_cmake.sh
- sudo chmod +x ./.ci-files/run_conan_server.sh
- ./.ci-files/install_conan.sh
- ./.ci-files/install_cmake.sh
#
- ./.ci-files/run_conan_server.sh
- conan remote add local http://localhost:9300
- conan remote list
script:
# Create and uplaod the recipe to the repository
- conan user -p demo demo -r=local
- conan create . local/testing
- conan upload foo* -r=local -c --all
# Test the Conan cmake generator
- mkdir build && cd build
- conan install ../test_cmake_install/conan_cmake_generator --build missing
- cmake ../test_cmake_install/conan_cmake_generator
- cmake --build .
- rm -rf *
# Test the Conan cmake_paths generator
- conan install ../test_cmake_install/conan_cmake_paths_generator --build missing
- cmake ../test_cmake_install/conan_cmake_paths_generator
- cmake --build .
- rm -rf *
# Test the Conan find_package generator
- conan install ../test_cmake_install/conan_cmake_find_package_generator --build missing
- cmake ../test_cmake_install/conan_cmake_find_package_generator
- cmake --build .
- rm -rf *
test-package-gcc8:
<<: *test_package_definition # Merge the contents of the 'job_definition' alias
image: conanio/gcc8
test-package-clang60:
<<: *test_package_definition # Merge the contents of the 'job_definition' alias
image: conanio/clang60

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "external/doctest"]
path = external/doctest
url = https://github.com/onqtam/doctest.git

View File

@@ -1,52 +1,56 @@
language: cpp
dist: xenial
notifications:
email: false
# Define builds on mulitple OS/compiler combinations.
# Feel free to add/remove entries from this list.
linux: &linux
os: linux
dist: xenial
language: python
python: "3.7"
services:
- docker
osx: &osx
os: osx
language: generic
matrix:
include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- lcov
- g++-7
env:
- MATRIX_EVAL="CXX_COMPILER=g++-7; sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-7 90"
include:
- <<: *linux
env: CONAN_GCC_VERSIONS=4.9 CONAN_DOCKER_IMAGE=conanio/gcc49
- <<: *linux
env: CONAN_GCC_VERSIONS=5 CONAN_DOCKER_IMAGE=conanio/gcc5
- <<: *linux
env: CONAN_GCC_VERSIONS=6 CONAN_DOCKER_IMAGE=conanio/gcc6
- <<: *linux
env: CONAN_GCC_VERSIONS=7 CONAN_DOCKER_IMAGE=conanio/gcc7
- <<: *linux
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
- <<: *linux
env: CONAN_CLANG_VERSIONS=3.9 CONAN_DOCKER_IMAGE=conanio/clang39
- <<: *linux
env: CONAN_CLANG_VERSIONS=4.0 CONAN_DOCKER_IMAGE=conanio/clang40
- <<: *linux
env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50
- <<: *linux
env: CONAN_CLANG_VERSIONS=6.0 CONAN_DOCKER_IMAGE=conanio/clang60
- <<: *linux
env: CONAN_CLANG_VERSIONS=7.0 CONAN_DOCKER_IMAGE=conanio/clang7
- <<: *osx
osx_image: xcode7.3
env: CONAN_APPLE_CLANG_VERSIONS=7.3
- <<: *osx
osx_image: xcode8.3
env: CONAN_APPLE_CLANG_VERSIONS=8.1
- <<: *osx
osx_image: xcode9
env: CONAN_APPLE_CLANG_VERSIONS=9.0
- <<: *osx
osx_image: xcode9.4
env: CONAN_APPLE_CLANG_VERSIONS=9.1
- <<: *osx
osx_image: xcode10.1
env: CONAN_APPLE_CLANG_VERSIONS=10.0
- os: osx
osx_image: xcode10.1
addons:
homebrew:
packages:
- lcov
update: true
env:
- MATRIX_EVAL="CXX_COMPILER=clang++"
before_install:
- eval "${MATRIX_EVAL}"
- PARENTDIR=$(pwd)
- mkdir $PARENTDIR/build
install:
- cd $PARENTDIR/build
- cmake $PARENTDIR -DCMAKE_BUILD_TYPE=Coverage -DCMAKE_CXX_COMPILER=$CXX_COMPILER
- make
install:
- chmod +x .ci-files/install_conan.sh .ci-files/install_cmake.sh
- ./.ci-files/install_conan.sh
- ./.ci-files/install_cmake.sh
script:
- make coverage
after_success:
- cd $PARENTDIR/build
- lcov --list coverage_out.info.cleaned # Show test report in travis log.
# Install coverals gem for uploading coverage to coveralls.
- gem install coveralls-lcov
- coveralls-lcov coverage_out.info.cleaned # uploads to coveralls
- bash <(curl -s https://codecov.io/bash) -f coverage_out.info.cleaned || echo "Codecov did not collect coverage reports"
- chmod +x .ci-files/run.sh
- ./.ci-files/run.sh

View File

@@ -1,124 +1,193 @@
# This file specifies how the project should be built, using CMake.
# If you are unfamiliar with CMake, don't worry about all the details.
# The sections you might want to edit are marked as such, and
# the comments should hopefully make most of it clear.
#
# For many purposes, you may not need to change anything about this file.
# This is the Top level CMakelists file which creates the namespace and
# organizes all sublibraries under it.
#
# The project name in this file is considered the "Namespace"
# and any libraries under it will be given a target of
#
# Namespace::library_name
#
#
# This Lists file was modified from https://github.com/forexample/package-example
#
# This file creates project 'Foo' with two library targets 'bar' and 'cat'.
# Target 'cat' depends on 'bar'. After installation this project can be found
# by 'find_package(... CONFIG)' command:
#
# find_package(foo CONFIG REQUIRED)
# target_link_libraries(... foo::bar)
#
# Note that requirements propagated automatically, for example:
# * Foo::baz linked automatically
# * <prefix>/include added to header search path
# * FOO_BAZ_DEBUG=1/FOO_BAR_DEBUG=1 added on Debug
# * FOO_BAZ_DEBUG=0/FOO_BAR_DEBUG=0 added on other configurations
cmake_minimum_required(VERSION 3.8.2)
project(KAMI VERSION 0.1.0 LANGUAGES CXX)
####
# Set minimum version of CMake. We need 3.13 at least.
cmake_minimum_required(VERSION 3.13) # GENERATOR_IS_MULTI_CONFIG
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake.modules/")
set(KAMI_VERSION_MAJOR 0)
set(KAMI_VERSION_MINOR 1)
set(KAMI_VERSION_PATCH 0)
set(KAMI_VERSION_STRING ${KAMI_VERSION_MAJOR}.${KAMI_VERSION_MINOR}.${KAMI_VERSION_PATCH})
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
################################################################################
# Set variables for the project. The:
# * PROJECT_NAME
# * PROJECT_VERSION
# * PROJECT_NAMESPACE should be the same as the project.
project(kami VERSION ${KAMI_VERSION_STRING}
LANGUAGES CXX)
# Options: Things you can set via commandline options to cmake (e.g. -DENABLE_LTO=[ON|OFF])
option(ENABLE_WARNINGS_SETTINGS "Allow target_set_warnings to add flags and defines.
Set this to OFF if you want to provide your own warning parameters." ON)
option(ENABLE_LTO "Enable link time optimization" ON)
option(ENABLE_DOCTESTS "Include tests in the library. Setting this to OFF will remove all doctest related code.
Tests in tests/*.cpp will still be enabled." ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(PROJECT_NAMESPACE kami ) # The project namespace. Library targets
# will be referred by
# foo::bar. This value should usually be
# the same as the project.
################################################################################
if(CMAKE_COMPILER_IS_GNUCC)
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE)
endif()
# Include stuff. No change needed.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
include(ConfigSafeGuards)
include(Colors)
include(CTest)
include(Doctest)
#include(Documentation)
include(LTO)
include(Misc)
include(Warnings)
# Check for LTO support.
find_lto(CXX)
################################################################################
# If coverage reporting is turned on. Create a custom target so that
# the libraries can link to it to acquire the appropriate flags.
#
# Also generate a custom target `gcov` so that the coverage reports can be created
################################################################################
if(ENABLE_COVERAGE)
include(cmake/coverage.cmake)
endif()
# --------------------------------------------------------------------------------
# Locate files (change as needed).
# --------------------------------------------------------------------------------
set(SOURCES # All .cpp files in src/
src/agent.cpp
src/grid1d.cpp
src/grid2d.cpp
src/grid3d.cpp
src/kami.cpp
src/multigrid1d.cpp
src/multigrid2d.cpp
src/multigrid3d.cpp
src/random.cpp
src/sequential.cpp
src/sologrid1d.cpp
src/sologrid2d.cpp
src/sologrid3d.cpp
src/staged.cpp
include(cmake/functions.cmake)
include(cmake/warnings.cmake)
include(cmake/cppcheck.cmake)
################################################################################
# Sub libraries.
#
# Each sub library will be built as a static or shared library and a
# target will be created for it.
################################################################################
directory_list(sub_modules "${CMAKE_CURRENT_SOURCE_DIR}/src")
FOREACH(subdir ${sub_modules})
add_subdirectory(src/${subdir})
ENDFOREACH()
################################################################################
################################################################################
# Examples.
#
# Each example will be built as a static or shared library and a
# target will be created for it.
################################################################################
directory_list(example_modules "${CMAKE_CURRENT_SOURCE_DIR}/examples")
FOREACH(subdir ${example_modules})
add_subdirectory(examples/${subdir})
ENDFOREACH()
################################################################################
enable_testing()
add_subdirectory(test)
################################################################################
# Installation of the library and all it's sub components. No need to edit this.
################################################################################
# Get the Default installation folders:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Layout. This works for all platforms:
# * <prefix>/lib*/cmake/<PROJECT-NAME>
# * <prefix>/lib*/
# * <prefix>/include/
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
set(TESTFILES # All .cpp files in tests/
tests/dummy.cpp
# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
set(LIBRARY_NAME kami) # Default name for the library built from src/*.cpp (change if you wish)
#Targets:
# * <prefix>/lib/libbar.a
# * <prefix>/lib/libbaz.a
# * header location after install: <prefix>/include/foo/Bar.hpp
# * headers can be included by C++ code `#include <foo/Bar.hpp>`
install(
TARGETS
${sub_modules} ${example_modules}
${COVERAGE_INSTALL_TARGET}
EXPORT
"${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# --------------------------------------------------------------------------------
# Build! (Change as needed)
# --------------------------------------------------------------------------------
# Compile all sources into a library.
add_library(${LIBRARY_NAME} OBJECT ${SOURCES})
# Lib needs its header files, and users of the library must also see these (PUBLIC). (No change needed)
target_include_directories(${LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
# There's also (probably) doctests within the library, so we need to see this as well.
target_link_libraries(${LIBRARY_NAME} PUBLIC spdlog)
# Set the compile options you want (change as needed).
target_set_warnings(${LIBRARY_NAME} ENABLE ALL AS_ERROR ALL DISABLE Annoying)
# target_compile_options(${LIBRARY_NAME} ... ) # For setting manually.
# If you add more executables, copy these lines accordingly.
add_executable(boltzmann1d examples/boltzmann1d.cpp) # Name of exec. and location of file.
target_link_libraries(boltzmann1d PRIVATE ${LIBRARY_NAME}) # Link the executable to library (if it uses it).
target_set_warnings(boltzmann1d ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed).
target_enable_lto(boltzmann1d optimized) # enable link-time-optimization if available for non-debug configurations
# Set the properties you require, e.g. what C++ standard to use. Here applied to library and main (change as needed).
set_target_properties(
${LIBRARY_NAME} boltzmann1d
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
# Config
# * <prefix>/lib/cmake/Foo/FooConfig.cmake
# * <prefix>/lib/cmake/Foo/FooConfigVersion.cmake
install(
FILES
"${project_config}" "${version_config}"
DESTINATION
"${config_install_dir}"
)
add_executable(boltzmann2d examples/boltzmann2d.cpp) # Name of exec. and location of file.
target_link_libraries(boltzmann2d PRIVATE ${LIBRARY_NAME}) # Link the executable to library (if it uses it).
target_set_warnings(boltzmann2d ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed).
target_enable_lto(boltzmann2d optimized) # enable link-time-optimization if available for non-debug configurations
# Set the properties you require, e.g. what C++ standard to use. Here applied to library and main (change as needed).
set_target_properties(
${LIBRARY_NAME} boltzmann2d
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
# Config
# * <prefix>/lib/cmake/Foo/FooTargets.cmake
install(
EXPORT
"${TARGETS_EXPORT_NAME}"
NAMESPACE
"${namespace}"
DESTINATION
"${config_install_dir}"
)
add_executable(boltzmann3d examples/boltzmann3d.cpp) # Name of exec. and location of file.
target_link_libraries(boltzmann3d PRIVATE ${LIBRARY_NAME}) # Link the executable to library (if it uses it).
target_set_warnings(boltzmann3d ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed).
target_enable_lto(boltzmann3d optimized) # enable link-time-optimization if available for non-debug configurations
# Set the properties you require, e.g. what C++ standard to use. Here applied to library and main (change as needed).
set_target_properties(
${LIBRARY_NAME} boltzmann3d
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
# Set up tests (see tests/CMakeLists.txt).
add_subdirectory(tests)
add_subdirectory(docs)
add_subdirectory(docs)

View File

@@ -1,6 +1,83 @@
# Kami Agent-Based Modeling in C++
# C++ Library Template
This package is largely based on the [Mesa: Agent-based modeling
in Python 3+](https://mesa.readthedocs.io/en/master/)
package. However, allowances are made for "idiomatic" implementation
in C++.
This is a C++ Library Template using modern CMake. It's list file is modified
from https://github.com/forexample/package-example.
| Branch | Gitlab-CI |
|--------|-----------|
| dev | ![https://gitlab.com/GavinNL/cpp_library_template/pipelines/](https://gitlab.com/GavinNL/cpp_library_template/badges/dev/build.svg) |
| master | ![https://gitlab.com/GavinNL/cpp_library_template/pipelines/](https://gitlab.com/GavinNL/cpp_library_template/badges/master/build.svg) |
# Features
* Multimodule library: Three libraries wrapped in a single namespace: `foo::bar`, `foo::cat` and `foo::dog`
* Auto-generated EXPORT headers for Windows DLLs
* Auto-generated CMake config files for installation
* Unit tests
* Conan Package Manager Integration
* Gitlab-CI integration
* Builds the library with gcc/clang verions
* Tests that the find_package() method works
* Builds the Conan Package
* Tests the cmake, cmake_paths, and cmake_find_package generators work
* **[to do]** CPack generation.
# Compiling
```Bash
# Build, test and install the library
git clone https://github.com/GavinNL/cpp_library_template
cd cpp_library_template
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/cpp_library_template -DBUILD_SHARED_LIBS:BOOL=TRUE
cmake --build .
ctest -C Debug
cmake --build . --target install
# Build an application that links to this one using.
# Use the find_package(foo) method to find where the installation
# is.
cd ..
rm -rf build
cd test_cmake_install
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH=/tmp/cpp_library_template
cmake --build .
export LD_LIBRARY_PATH=/tmp/cpp_library_template/lib
./test-bar
./test-cat
```
# Conan Package Manager
This library comes with a `conanfile.py` to build it into a Conan package so that
it may be used by external applications/libraries.
## Create Conan Packages
Creating a Conan package is relatively easy. Simple cd into the source directory
and execute the conan create function.
```bash
git clone https://github.com/GavinNL/cpp_library_template
cd cpp_library_template
conan create . foo/testing
```
## Using the Conan Package
Once you have created the Conan package, you can then link to it from another
application or library. There are three examples you can look at in the
`test_cmake_install` folder.
* Using [cmake generator](test_cmake_install/conan_cmake_generator)
* Using [cake_paths generator](test_cmake_install/conan_cmake_paths_generator)
* Using [cmake_find_package generator](test_cmake_install/conan_cmake_find_package_generator)

View File

@@ -0,0 +1 @@
---

View File

@@ -0,0 +1,3 @@
Start testing: Sep 23 18:26 EDT
----------------------------------------------------------
End testing: Sep 23 18:26 EDT

View File

@@ -1,46 +0,0 @@
#---------------------------------#
# environment configuration #
#---------------------------------#
# Build worker image (VM template)
image: Visual Studio 2017
clone_depth: 3
platform:
- Win32
- x64
configuration:
- Debug
- Release
# environment:
# matrix:
# - TOOLSET: v140
matrix:
fast_finish: false
# scripts that are called at very beginning, before repo cloning
init:
- cmd: cmake --version
- cmd: msbuild /version
install:
- git submodule update --init --recursive
before_build:
- cmake . -Bbuild -A%PLATFORM% -DCMAKE_BUILD_TYPE=%configuration%
build:
project: build/CPP_BOILERPLATE.sln
parallel: true
verbosity: minimal
test_script:
- cd build
- set CTEST_OUTPUT_ON_FAILURE=1
- ctest -C %configuration%
- cd ..

View File

@@ -1,158 +0,0 @@
# 2012-01-31, Lars Bilke
# - Enable Code Coverage
#
# 2013-09-17, Joakim Söderberg
# - Added support for Clang.
# - Some additional usage instructions.
#
# 2018-03-31, Bendik Samseth
# - Relax debug output.
# - Keep a copy of the coverage output for later use.
# - Updated coverage exclude patterns.
#
# 2018-01-03, HenryRLee
# - Allow for *Clang compiler names, not just Clang.
#
# 2018-01-03, Bendik Samseth
# - Only check compiler compatibility if in a coverage build.
#
#
# USAGE:
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
# http://stackoverflow.com/a/22404544/80480
#
# 1. Copy this file into your cmake modules path.
#
# 2. Add the following line to your CMakeLists.txt:
# INCLUDE(CodeCoverage)
#
# 3. Set compiler flags to turn off optimization and enable coverage:
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
#
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
# which runs your test executable and produces a lcov code coverage report:
# Example:
# SETUP_TARGET_FOR_COVERAGE(
# my_coverage_target # Name for custom target.
# test_driver # Name of the test driver executable that runs the tests.
# # NOTE! This should always have a ZERO as exit code
# # otherwise the coverage generation will not complete.
# coverage # Name of output directory.
# )
#
# 4. Build a Debug build:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make
# make my_coverage_target
#
#
# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests.
# MUST return ZERO always, even on errors.
# If not, no coverage report will be created!
# Param _outputname lcov output is generated as _outputname.info
# HTML report is generated in _outputname/index.html
# Optional fourth parameter is passed as arguments to _testrunner
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Run tests
COMMAND ${_testrunner} ${ARGV3}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/tests/*' '/usr/*' '*/external/*' '/Applications/*' --output-file ${_outputname}.info.cleaned
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
COMMAND ${LCOV_PATH} --list ${_outputname}.info.cleaned
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "${BoldMagenta}Open ./${_outputname}/index.html in your browser to view the coverage report.${ColourReset}"
)
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
if (cmake_build_type_tolower STREQUAL "coverage")
# Check prereqs
FIND_PROGRAM( GCOV_PATH gcov )
FIND_PROGRAM( LCOV_PATH lcov )
FIND_PROGRAM( GENHTML_PATH genhtml )
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF() # NOT GCOV_PATH
IF(NOT CMAKE_COMPILER_IS_GNUCXX)
IF(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc or Clang! Aborting...")
ENDIF()
ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
SET(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0 -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE )
SET(CMAKE_C_FLAGS_COVERAGE
"-g -O0 -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE )
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
# If unwanted files are included in the coverage reports, you can
# adjust the exclude patterns on line 83.
SETUP_TARGET_FOR_COVERAGE(
coverage # Name for custom target.
${TEST_MAIN} # Name of the test driver executable that runs the tests.
# NOTE! This should always have a ZERO as exit code
# otherwise the coverage generation will not complete.
coverage_out # Name of output directory.
)
else()
add_custom_target(coverage
COMMAND echo "${Red}Code coverage only available in coverage builds."
COMMAND echo "${Green}Make a new build directory and rerun cmake with -DCMAKE_BUILD_TYPE=Coverage to enable this target.${ColorReset}"
)
endif()

View File

@@ -1,19 +0,0 @@
IF(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
ENDIF()

4
cmake/Config.cmake.in Normal file
View File

@@ -0,0 +1,4 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")

View File

@@ -1,20 +0,0 @@
# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()
# guard against bad build-type strings
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper)
if( NOT cmake_build_type_tolower STREQUAL "debug"
AND NOT cmake_build_type_tolower STREQUAL "release"
AND NOT cmake_build_type_tolower STREQUAL "profile"
AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo"
AND NOT cmake_build_type_tolower STREQUAL "coverage")
message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Coverage, Release, Profile, RelWithDebInfo (case-insensitive).")
endif()

View File

@@ -1,6 +0,0 @@
if(ENABLE_DOCTESTS)
add_definitions(-DENABLE_DOCTEST_IN_LIBRARY)
endif()
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE ${PROJECT_SOURCE_DIR}/external/doctest/doctest)

View File

@@ -1,15 +0,0 @@
# --------------------------------------------------------------------------------
# Documentation (no change needed).
# --------------------------------------------------------------------------------
# Add a make target 'doc' to generate API documentation with Doxygen.
# You should set options to your liking in the file 'Doxyfile.in'.
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile &> doxygen.log
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "${BoldMagenta}Generating API documentation with Doxygen (open ./html/index.html to view).${ColourReset}" VERBATIM
)
endif(DOXYGEN_FOUND)

View File

@@ -1,249 +0,0 @@
# Usage :
#
# Variable : ENABLE_LTO | Enable or disable LTO support for this build
#
# find_lto(lang)
# - lang is C or CXX (the language to test LTO for)
# - call it after project() so that the compiler is already detected
#
# This will check for LTO support and create a target_enable_lto(target [debug,optimized,general]) macro.
# The 2nd parameter has the same meaning as in target_link_libraries, and is used to enable LTO only for those build configurations
# 'debug' is by default the Debug configuration, and 'optimized' all the other configurations
#
# if ENABLE_LTO is set to false, an empty macro will be generated
#
# Then to enable LTO for your target use
#
# target_enable_lto(mytarget general)
#
# It is however recommended to use it only for non debug builds the following way :
#
# target_enable_lto(mytarget optimized)
#
# Note : For CMake versions < 3.9, target_link_library is used in it's non plain version.
# You will need to specify PUBLIC/PRIVATE/INTERFACE to all your other target_link_library calls for the target
#
# WARNING for cmake versions older than 3.9 :
# This module will override CMAKE_AR CMAKE_RANLIB and CMAKE_NM by the gcc versions if found when building with gcc
# License:
#
# Copyright (C) 2016 Lectem <lectem@gmail.com>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the 'Software') deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
macro(find_lto lang)
if(ENABLE_LTO AND NOT LTO_${lang}_CHECKED)
#LTO support was added for clang/gcc in 3.9
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
cmake_policy(SET CMP0054 NEW)
message(STATUS "Checking for LTO Compatibility")
# Since GCC 4.9 we need to use gcc-ar / gcc-ranlib / gcc-nm
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_GCC_AR OR NOT CMAKE_GCC_RANLIB OR NOT CMAKE_GCC_NM)
find_program(CMAKE_GCC_AR NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${_version}"
DOC "gcc provided wrapper for ar which adds the --plugin option"
)
find_program(CMAKE_GCC_RANLIB NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}"
DOC "gcc provided wrapper for ranlib which adds the --plugin option"
)
# Not needed, but at least stay coherent
find_program(CMAKE_GCC_NM NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm-${_version}"
DOC "gcc provided wrapper for nm which adds the --plugin option"
)
mark_as_advanced(CMAKE_GCC_AR CMAKE_GCC_RANLIB CMAKE_GCC_NM)
set(CMAKE_LTO_AR ${CMAKE_GCC_AR})
set(CMAKE_LTO_RANLIB ${CMAKE_GCC_RANLIB})
set(CMAKE_LTO_NM ${CMAKE_GCC_NM})
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_LTO_AR ${CMAKE_AR})
set(CMAKE_LTO_RANLIB ${CMAKE_RANLIB})
set(CMAKE_LTO_NM ${CMAKE_NM})
endif()
if(CMAKE_LTO_AR AND CMAKE_LTO_RANLIB)
set(__lto_flags -flto)
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7)
list(APPEND __lto_flags -fno-fat-lto-objects)
endif()
if(NOT DEFINED CMAKE_${lang}_PASSED_LTO_TEST)
set(__output_dir "${CMAKE_PLATFORM_INFO_DIR}/LtoTest1${lang}")
file(MAKE_DIRECTORY "${__output_dir}")
set(__output_base "${__output_dir}/lto-test-${lang}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "void foo() {}"
COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -c -xc -
-o "${__output_base}.o"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_LTO_AR} cr "${__output_base}.a" "${__output_base}.o"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_LTO_RANLIB} "${__output_base}.a"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "void foo(); int main() {foo();}"
COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -xc -
-x none "${__output_base}.a" -o "${__output_base}"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
set(__lto_found TRUE)
endif()
set(CMAKE_${lang}_PASSED_LTO_TEST
${__lto_found} CACHE INTERNAL
"If the compiler passed a simple LTO test compile")
endif()
if(CMAKE_${lang}_PASSED_LTO_TEST)
message(STATUS "Checking for LTO Compatibility - works")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags")
else()
message(STATUS "Checking for LTO Compatibility - not working")
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Checking for LTO Compatibility - works (assumed for clang)")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "Checking for LTO Compatibility - works")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS /GL CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -LTCG:INCREMENTAL CACHE STRING "Link Time Optimization link flags")
else()
message(STATUS "Checking for LTO Compatibility - compiler not handled by module")
endif()
mark_as_advanced(LTO_${lang}_SUPPORT LTO_COMPILE_FLAGS LTO_LINK_FLAGS)
set(LTO_${lang}_CHECKED TRUE CACHE INTERNAL "" )
if(CMAKE_GCC_AR AND CMAKE_GCC_RANLIB AND CMAKE_GCC_NM)
# THIS IS HACKY BUT THERE IS NO OTHER SOLUTION ATM
set(CMAKE_AR ${CMAKE_GCC_AR} CACHE FILEPATH "Forcing gcc-ar instead of ar" FORCE)
set(CMAKE_NM ${CMAKE_GCC_NM} CACHE FILEPATH "Forcing gcc-nm instead of nm" FORCE)
set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE FILEPATH "Forcing gcc-ranlib instead of ranlib" FORCE)
endif()
endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
endif(ENABLE_LTO AND NOT LTO_${lang}_CHECKED)
if(ENABLE_LTO)
#Special case for cmake older than 3.9, using a library for gcc/clang, but could setup the flags directly.
#Taking advantage of the [debug,optimized] parameter of target_link_libraries
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
if(LTO_${lang}_SUPPORT)
if(NOT TARGET __enable_lto_tgt)
add_library(__enable_lto_tgt INTERFACE)
endif()
target_compile_options(__enable_lto_tgt INTERFACE ${LTO_COMPILE_FLAGS})
#this might not work for all platforms... in which case we'll have to set the link flags on the target directly
target_link_libraries(__enable_lto_tgt INTERFACE ${LTO_LINK_FLAGS} )
macro(target_enable_lto _target _build_configuration)
if(${_build_configuration} STREQUAL "optimized" OR ${_build_configuration} STREQUAL "debug" )
target_link_libraries(${_target} PRIVATE ${_build_configuration} __enable_lto_tgt)
else()
target_link_libraries(${_target} PRIVATE __enable_lto_tgt)
endif()
endmacro()
else()
#In old cmake versions, we can set INTERPROCEDURAL_OPTIMIZATION even if not supported by the compiler
#So if we didn't detect it, let cmake give it a try
set(__IPO_SUPPORTED TRUE)
endif()
else()
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT __IPO_SUPPORTED OUTPUT output)
if(NOT __IPO_SUPPORTED)
message(STATUS "IPO is not supported or broken.")
else()
message(STATUS "IPO is supported")
endif()
endif()
if(__IPO_SUPPORTED)
macro(target_enable_lto _target _build_configuration)
if(NOT ${_build_configuration} STREQUAL "debug" )
#enable for all configurations
set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(${_build_configuration} STREQUAL "optimized" )
#blacklist debug configurations
set(__enable_debug_lto FALSE)
else()
#enable only for debug configurations
set(__enable_debug_lto TRUE)
endif()
get_property(DEBUG_CONFIGURATIONS GLOBAL PROPERTY DEBUG_CONFIGURATIONS)
if(NOT DEBUG_CONFIGURATIONS)
set(DEBUG_CONFIGURATIONS DEBUG) # This is what is done by CMAKE internally... since DEBUG_CONFIGURATIONS is empty by default
endif()
foreach(config IN LISTS DEBUG_CONFIGURATIONS)
set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${config} ${__enable_debug_lto})
endforeach()
endmacro()
endif()
endif()
if(NOT COMMAND target_enable_lto)
macro(target_enable_lto _target _build_configuration)
endmacro()
endif()
endmacro()

View File

@@ -1,16 +0,0 @@
# --------------------------------------------------------------------------------
# Misc (no change needed).
# --------------------------------------------------------------------------------
# Have CMake parse the config file, generating the config header, with
# correct definitions. Here only used to make version number available to
# the source code. Include "exampleConfig.h" (no .in suffix) in the source.
configure_file (
"${PROJECT_SOURCE_DIR}/include/kami/config.hpp.in"
"${PROJECT_BINARY_DIR}/include/kami/config.hpp"
)
# add the binary tree to the search path for include files
# so that we will find exampleConfig.h
include_directories("${PROJECT_BINARY_DIR}")
# Ask CMake to output a compile_commands.json file for use with things like Vim YCM.
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

View File

@@ -1,101 +1,19 @@
# MIT License
#
# This Cmake file creates targets for better warnings
#
# Link to the following targets:
# warning::all - displays all warnings
# warning::error - treats warnings as errors
#
# Copyright (c) 2017 Lectem
add_library(warnings_all_ INTERFACE)
add_library(warning::all ALIAS warnings_all_)
target_compile_options(warnings_all_ INTERFACE -Wall -Wextra -Wpedantic)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
set(WARNING_INSTALL_TARGET warnings_all_)
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
add_library(warnings_error_ INTERFACE)
add_library(warning::error ALIAS warnings_error_)
target_compile_options(warnings_error_ INTERFACE -Werror)
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
function(target_set_warnings)
if(NOT ENABLE_WARNINGS_SETTINGS)
return()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(WMSVC TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(WGCC TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(WCLANG TRUE)
endif()
set(multiValueArgs ENABLE DISABLE AS_ERROR)
cmake_parse_arguments(this "" "" "${multiValueArgs}" ${ARGN})
list(FIND this_ENABLE "ALL" enable_all)
list(FIND this_DISABLE "ALL" disable_all)
list(FIND this_AS_ERROR "ALL" as_error_all)
if(NOT ${enable_all} EQUAL -1)
if(WMSVC)
# Not all the warnings, but WAll is unusable when using libraries
# Unless you'd like to support MSVC in the code with pragmas, this is probably the best option
list(APPEND WarningFlags "/W4")
elseif(WGCC)
list(APPEND WarningFlags "-Wall" "-Wextra" "-Wpedantic")
elseif(WCLANG)
list(APPEND WarningFlags "-Wall" "-Weverything" "-Wpedantic")
endif()
elseif(NOT ${disable_all} EQUAL -1)
set(SystemIncludes TRUE) # Treat includes as if coming from system
if(WMSVC)
list(APPEND WarningFlags "/w" "/W0")
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags "-w")
endif()
endif()
list(FIND this_DISABLE "Annoying" disable_annoying)
if(NOT ${disable_annoying} EQUAL -1)
if(WMSVC)
# bounds-checked functions require to set __STDC_WANT_LIB_EXT1__ which we usually don't need/want
list(APPEND WarningDefinitions -D_CRT_SECURE_NO_WARNINGS)
# disable C4514 C4710 C4711... Those are useless to add most of the time
#list(APPEND WarningFlags "/wd4514" "/wd4710" "/wd4711")
#list(APPEND WarningFlags "/wd4365") #signed/unsigned mismatch
#list(APPEND WarningFlags "/wd4668") # is not defined as a preprocessor macro, replacing with '0' for
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags -Wno-switch-enum)
if(WCLANG)
list(APPEND WarningFlags -Wno-unknown-warning-option -Wno-padded -Wno-undef -Wno-reserved-id-macro -fcomment-block-commands=test,retval)
if(NOT CMAKE_CXX_STANDARD EQUAL 98)
list(APPEND WarningFlags -Wno-c++98-compat -Wno-c++98-compat-pedantic)
endif()
if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") # clang-cl has some VCC flags by default that it will not recognize...
list(APPEND WarningFlags -Wno-unused-command-line-argument)
endif()
endif(WCLANG)
endif()
endif()
if(NOT ${as_error_all} EQUAL -1)
if(WMSVC)
list(APPEND WarningFlags "/WX")
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags "-Werror")
endif()
endif()
foreach(target IN LISTS this_UNPARSED_ARGUMENTS)
if(WarningFlags)
target_compile_options(${target} PRIVATE ${WarningFlags})
endif()
if(WarningDefinitions)
target_compile_definitions(${target} PRIVATE ${WarningDefinitions})
endif()
if(SystemIncludes)
set_target_properties(${target} PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>)
endif()
endforeach()
endfunction(target_set_warnings)
set(WARNING_INSTALL_TARGET ${WARNING_INSTALL_TARGET} warnings_error_)

22
cmake/coverage.cmake Normal file
View File

@@ -0,0 +1,22 @@
if(CMAKE_COMPILER_IS_GNUCC)
add_library(coverage_ INTERFACE)
add_library(coverage::coverage ALIAS coverage_)
target_compile_options(coverage_ INTERFACE --coverage -g -O0 -fprofile-arcs -ftest-coverage)
target_link_libraries(coverage_ INTERFACE --coverage -g -O0 -fprofile-arcs -ftest-coverage)
set(COVERAGE_TARGET coverage::coverage)
set(COVERAGE_INSTALL_TARGET coverage_)
add_custom_target(coverage
COMMAND rm -rf coverage
COMMAND mkdir -p coverage
COMMAND ${CMAKE_MAKE_PROGRAM} test
COMMAND gcovr . -r ${CMAKE_SOURCE_DIR} --html-details --html -o coverage/index.html -e ${CMAKE_SOURCE_DIR}/test/third_party;
COMMAND gcovr . -r ${CMAKE_SOURCE_DIR} --xml -o coverage/report.xml -e ${CMAKE_SOURCE_DIR}/test/third_party;
COMMAND gcovr . -r ${CMAKE_SOURCE_DIR} -o coverage/report.txt -e ${CMAKE_SOURCE_DIR}/test/third_party;
COMMAND cat coverage/report.txt
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # Need separate command for this line
)
endif()

13
cmake/cppcheck.cmake Normal file
View File

@@ -0,0 +1,13 @@
add_custom_target(cppcheck
#COMMAND mkdir -p coverage
#COMMAND ${CMAKE_MAKE_PROGRAM} test
#WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_command(TARGET cppcheck
COMMAND echo "=================== CPPCHECK ===================="
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/cppcheck
COMMAND cppcheck . -I include/ --enable=all --inconclusive --xml-version=2 --force --library=windows,posix,gnu . --output-file=${CMAKE_BINARY_DIR}/cppcheck/result.xml
COMMAND cppcheck-htmlreport --source-encoding="iso8859-1" --title="mmp2top" --source-dir . --report-dir=${CMAKE_BINARY_DIR}/cppcheck --file=${CMAKE_BINARY_DIR}/cppcheck/result.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} # Need separate command for this line
)

663
cmake/functions.cmake Normal file
View File

@@ -0,0 +1,663 @@
include(GenerateExportHeader)
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
MACRO(directory_list result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child} )
LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
MACRO(print_list result)
foreach(arg IN LISTS ${result})
message(" - ${arg}")
endforeach()
ENDMACRO()
MACRO(print_list_label Label ListVar)
message("${Label}:")
print_list(${ListVar})
ENDMACRO()
# create_library( NAME myLibrary
# NAMESPACE myNamespace
# SOURCES
# myLib.cpp
# myLib_functions.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# EXPORT_FILE_PATH
# ${CMAKE_BINARY_DIR}/MYLIBRARY_EXPORT.h
################################################################################
# Create a Library.
#
# Example usage:
#
# create_library( NAME myLibrary
# NAMESPACE myNamespace
# SOURCES
# myLib.cpp
# myLib_functions.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# EXPORT_FILE_PATH
# ${CMAKE_BINARY_DIR}/MYLIBRARY_EXPORT.h
# )
#
# The above example creates an alias target, myNamespace::myLibrary which can be
# linked to by other tar gets.
# PUBLIC_DEFINITIONS - preprocessor defines which are inherated by targets which
# link to this library
#
# PRIVATE_DEFINITIONS - preprocessor defines which are private and only seen by
# myLibrary
#
# PUBLIC_INCLUDE_PATHS - include paths which are public, therefore inherted by
# targest which link to this library.
#
# PRIVATE_INCLUDE_PATHS - private include paths which are only visible by MyLibrary
#
# LINKED_TARGETS - targets to link to.
#
# EXPORT_FILE_PATH - the export file to generate for dll files.
################################################################################
function(create_library)
set(options)
set(args NAME
NAMESPACE
EXPORT_FILE_PATH
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
PUBLIC_COMPILE_OPTIONS
PRIVATE_COMPILE_OPTIONS
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("--------------------------")
message("Creating Library")
if("${lib_NAME}" STREQUAL "")
get_filename_component(lib_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" lib_NAME ${lib_NAME})
message(" Library, NAME argument not provided. Using folder name: ${lib_NAME}")
endif()
if("${lib_NAMESPACE}" STREQUAL "")
set(lib_NAMESPACE ${lib_NAME})
message(" Library, NAMESPACE argument not provided. Using target alias: ${lib_NAME}::${lib_NAME}")
endif()
message("-----------------------------------")
message("Building Library: ${lib_NAME}")
message("-----------------------------------")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
add_library( ${lib_NAME} ${lib_SOURCES} )
add_library( ${lib_NAMESPACE}::${lib_NAME} ALIAS ${lib_NAME} )
target_compile_features(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_FEATURES} )
target_compile_options(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_OPTIONS} )
target_compile_options(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_OPTIONS} )
target_link_libraries( ${lib_NAME} PUBLIC ${lib_PUBLIC_LINKED_TARGETS})
target_link_libraries( ${lib_NAME} PRIVATE ${lib_PRIVATE_LINKED_TARGETS})
target_include_directories( ${lib_NAME}
PUBLIC
${lib_INCLUDE_PATHS}
${lib_PUBLIC_INCLUDE_PATHS}
PRIVATE
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
PUBLIC
${lib_PUBLIC_DEFINITIONS}
PRIVATE
${lib_PRIVATE_DEFINITIONS}
)
if( NOT "${lib_EXPORT_FILE_PATH}" STREQUAL "" )
generate_export_header( ${lib_NAME}
EXPORT_FILE_NAME
${lib_EXPORT_FILE_PATH}
)
endif()
################################################################################
# Debug Information Format:
# * https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format
#
# Notes:
#
# * /Z7 still produce PDB file for DLL and without the PDB file installed
# you can't debug DLL
#
# * /Z7 for static library doesn't produce PDB. It's the best option if you
# want debug library without changing internal CMake code.
# Toolchain example: https://github.com/ruslo/polly/blob/master/vs-15-2017-win64-z7.cmake
#
# * /Zi option is default (produce separate PDB files)
#
# * TARGET_PDB_FILE generator expression doesn't support static libraries.
# See https://gitlab.kitware.com/cmake/cmake/issues/16932
# (that's why it's not used here)
#
# * This code can be implemented as a 'PDB DESTINATION' feature.
# See https://gitlab.kitware.com/cmake/cmake/issues/16935#note_275180
#
# * By default only Debug/RelWithDebInfo produce debug information,
# Release/MinSizeRel do not.
#
# * Generated PDB for static libraries doesn't respect CMAKE_<CONFIG>_POSTFIX
# variable. It means if you specify Debug and RelWithDebInfo then generated
# PDB files for both will be "md5.pdb". When PDB files installed one will
# overwrite another making it unusable. Release + Debug configurations will
# work fine because Release doesn't produce PDB files.
#
# * All PDB files will be installed, including PDB for targets that will not
# be installed themselves.
################################################################################
if(MSVC)
set(pdb_output_dir "${CMAKE_CURRENT_BINARY_DIR}/pdb-files")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${pdb_output_dir}")
set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${pdb_output_dir}")
get_cmake_property(is_multi GENERATOR_IS_MULTI_CONFIG)
if(is_multi)
set(config_suffix "$<CONFIG>")
else()
set(config_suffix "")
endif()
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
include(GNUInstallDirs)
if(BUILD_SHARED_LIBS)
set(pdb_dst ${CMAKE_INSTALL_BINDIR})
else()
set(pdb_dst ${CMAKE_INSTALL_LIBDIR})
endif()
install(
DIRECTORY "${pdb_output_dir}/${config_suffix}/"
DESTINATION ${pdb_dst}
)
endif()
################################################################################
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction()
################################################################################
# Create an executable.
#
# Example usage:
#
# create_executable( NAME myExe
# SOURCES
# main.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# myNamespace::myLib
# )
#
# The above example creates an alias target, myNamespace::myLibrary which can be
# linked to by other tar gets.
# PUBLIC_DEFINITIONS - preprocessor defines which are inherated by targets which
# link to this library
#
# PRIVATE_DEFINITIONS - preprocessor defines which are private and only seen by
# myLibrary
#
# PUBLIC_INCLUDE_PATHS - include paths which are public, therefore inherted by
# targest which link to this library.
#
# PRIVATE_INCLUDE_PATHS - private include paths which are only visible by MyExe
#
# LINKED_TARGETS - targets to link to.
################################################################################
function(create_executable)
set(options)
set(args NAME
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
PUBLIC_COMPILE_OPTIONS
PRIVATE_COMPILE_OPTIONS
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("-----------------------------------")
message("Building Executable: ${Green}${lib_NAME}${ColourReset}")
message("-----------------------------------")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
add_executable( ${lib_NAME} ${lib_SOURCES} )
target_link_libraries( ${lib_NAME} PUBLIC ${lib_PUBLIC_LINKED_TARGETS} )
target_include_directories( ${lib_NAME}
PUBLIC
${lib_PUBLIC_INCLUDE_PATHS}
PRIVATE
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
PUBLIC
${lib_PUBLIC_DEFINITIONS}
PRIVATE
${lib_PRIVATE_DEFINITIONS}
)
target_compile_features(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_FEATURES} )
target_compile_options(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_OPTIONS} )
target_compile_options(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_OPTIONS} )
################################################################################
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction(create_executable)
function(create_module)
set(options)
set(args NAME
)
set(list_args
LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
INCLUDE_PATHS)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("Building Module: ${lib_NAME}")
add_library( ${lib_NAME} MODULE ${lib_SOURCES} )
target_link_libraries( ${lib_NAME} PUBLIC ${lib_LINKED_TARGETS} )
set_target_properties( ${lib_NAME} PROPERTIES SUFFIX ".so")
set_target_properties( ${lib_NAME} PROPERTIES PREFIX "")
target_include_directories( ${lib_NAME}
PUBLIC
${lib_INCLUDE_PATHS}
${lib_PUBLIC_INCLUDE_PATHS}
PRIVATE
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
PUBLIC
${lib_PUBLIC_DEFINITIONS}
PRIVATE
${lib_PRIVATE_DEFINITIONS}
)
################################################################################
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction()
################################################################################
# Create a Header Only Library.
#
# Example usage:
#
# create_library( NAME myLibrary
# NAMESPACE myNamespace
# SOURCES
# myLib.cpp
# myLib_functions.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# EXPORT_FILE_PATH
# ${CMAKE_BINARY_DIR}/MYLIBRARY_EXPORT.h
# )
#
# The above example creates an alias target, myNamespace::myLibrary which can be
# linked to by other tar gets.
# PUBLIC_DEFINITIONS - preprocessor defines which are inherated by targets which
# link to this library
#
# PRIVATE_DEFINITIONS - preprocessor defines which are private and only seen by
# myLibrary
#
# PUBLIC_INCLUDE_PATHS - include paths which are public, therefore inherted by
# targest which link to this library.
#
# PRIVATE_INCLUDE_PATHS - private include paths which are only visible by MyLibrary
#
# LINKED_TARGETS - targets to link to.
#
# EXPORT_FILE_PATH - the export file to generate for dll files.
################################################################################
function(create_header_only_library)
set(options)
set(args NAME
NAMESPACE
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
PUBLIC_COMPILE_OPTIONS
PRIVATE_COMPILE_OPTIONS
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("--------------------------")
message("Creating Header-Only Library")
if("${lib_NAME}" STREQUAL "")
get_filename_component(lib_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" lib_NAME ${lib_NAME})
message(" Library, NAME argument not provided. Using folder name: ${lib_NAME}")
endif()
if("${lib_NAMESPACE}" STREQUAL "")
set(lib_NAMESPACE ${lib_NAME})
message(" Library, NAMESPACE argument not provided. Using target alias: ${lib_NAME}::${lib_NAME}")
endif()
message("-----------------------------------")
message("Building Library: ${lib_NAME} Alias: ${lib_NAMESPACE}::${lib_NAME}")
message("-----------------------------------")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
add_library( ${lib_NAME} INTERFACE ${lib_SOURCES} )
add_library( ${lib_NAMESPACE}::${lib_NAME} ALIAS ${lib_NAME} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PUBLIC_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PRIVATE_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PUBLIC_COMPILE_OPTIONS} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PRIVATE_COMPILE_OPTIONS} )
target_link_libraries( ${lib_NAME} PUBLIC ${PUBLIC_LINKED_TARGETS})
target_link_libraries( ${lib_NAME} PRIVATE ${PRIVATE_LINKED_TARGETS})
target_include_directories( ${lib_NAME}
INTERFACE
${lib_PUBLIC_INCLUDE_PATHS}
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
INTERFACE
${lib_PUBLIC_DEFINITIONS}
${lib_PRIVATE_DEFINITIONS}
)
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction()
function(create_test)
set(options)
set(args NAME
WORKING_DIRECTORY
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
COMMAND
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("-----------------------------------")
message("Building Test: ${lib_NAME} ")
message("-----------------------------------")
message("Command to Execute: ${lib_COMMAND}")
message("Working Directory : ${lib_WORKING_DIRECTORY}")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
set(testcase ${lib_NAME} )
add_executable(${testcase} ${lib_SOURCES})
target_compile_definitions(${testcase} PRIVATE
#CATCH_CONFIG_FAST_COMPILE
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
${lib_PRIVATE_DEFINITIONS}
${lib_PUBLIC_DEFINITIONS}
)
target_compile_options(${testcase} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
# $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
${lib_PUBLIC_COMPILE_FEATURES}
${lib_PRIVATE_COMPILE_FEATURES}
)
target_include_directories(${testcase} PRIVATE
${lib_PUBLIC_INCLUDE_PATHS}
${lib_PRIVATE_INCLUDE_PATHS}
)
target_link_libraries(${testcase} ${lib_PUBLIC_LINKED_TARGETS} ${lib_PRIVATE_LINKED_TARGETS} )
#target_link_libraries(${testcase} --coverage -g -O0 -fprofile-arcs -ftest-coverage)
#target_compile_options(${testcase} PRIVATE --coverage -g -O0 -fprofile-arcs -ftest-coverage)
#MESSAGE(" Adding link libraries for ${testcase}: ${GNL_LIBS} ${GNL_COVERAGE_FLAGS} ")
add_test( NAME ${testcase}
COMMAND ${lib_COMMAND}
WORKING_DIRECTORY ${lib_WORKING_DIRECTORY})
endfunction()

48
conanfile.py Normal file
View File

@@ -0,0 +1,48 @@
from conans import ConanFile, CMake
class CppLibraryTemplateConan(ConanFile):
name = "kami"
version = "0.1.0"
license = "Unlicense"
author = "James P. Howard, II <james.howard@jhu.edu>"
url = "http://github.com/GavinNL/cpp_library_template"
description = "A simple C++ Library Template."
topics = ("<Put some tag here>", "<here>", "<and here>")
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
exports_sources = "*"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
cmake.configure()
return cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
'''
Create a package using "cmake --build . --target install"
All installation files are defined in the CMakeLists.txt file rather
than in the conan package.
'''
cmake = self._configure_cmake()
cmake.install()
def package_info(self):
# These libraries are required when using the
# following generators:
# cmake, cmake_paths, cmake_
self.cpp_info.libs = ["dog", "cat", "bar", "kami", "kamidata"]

View File

@@ -1,6 +0,0 @@
[requires]
catch2/2.2.2@bincrafters/stable
spdlog/1.7.0
[generators]
cmake

View File

@@ -55,5 +55,4 @@ add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})
# Add an install target to install the docs
include(GNUInstallDirs)
install(DIRECTORY ${SPHINX_BUILD}
DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(DIRECTORY ${SPHINX_BUILD}/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/html)

View File

@@ -0,0 +1,7 @@
# Creating a New Example
Each folder in here is automatically traversed by the root level cmake list file.
1. Copy one of the existing folders to a new name.
2. The name of the folder will be the name of the library
3. Change the source file list.

View File

@@ -0,0 +1,24 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
set(EXAMPLE_NAME "boltzmann1d")
project(${EXAMPLE_NAME}
LANGUAGES CXX)
create_executable( NAME ${EXAMPLE_NAME}
SOURCES
boltzmann1d.cpp
PUBLIC_DEFINITIONS
USE_DOUBLE_PRECISION=1
PRIVATE_DEFINITIONS
DEBUG_VERBOSE
PRIVATE_INCLUDE_PATHS
${CMAKE_SOURCE_DIR}/include
PUBLIC_LINKED_TARGETS
kami
)
set_target_properties(${EXAMPLE_NAME} PROPERTIES VERSION ${KAMI_VERSION_STRING})

View File

@@ -0,0 +1,24 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
set(EXAMPLE_NAME "boltzmann2d")
project(${EXAMPLE_NAME}
LANGUAGES CXX)
create_executable( NAME ${EXAMPLE_NAME}
SOURCES
boltzmann2d.cpp
PUBLIC_DEFINITIONS
USE_DOUBLE_PRECISION=1
PRIVATE_DEFINITIONS
DEBUG_VERBOSE
PRIVATE_INCLUDE_PATHS
${CMAKE_SOURCE_DIR}/include
PUBLIC_LINKED_TARGETS
kami
)
set_target_properties(${EXAMPLE_NAME} PROPERTIES VERSION ${KAMI_VERSION_STRING})

View File

@@ -0,0 +1,24 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
set(EXAMPLE_NAME "boltzmann3d")
project(${EXAMPLE_NAME}
LANGUAGES CXX)
create_executable( NAME ${EXAMPLE_NAME}
SOURCES
boltzmann3d.cpp
PUBLIC_DEFINITIONS
USE_DOUBLE_PRECISION=1
PRIVATE_DEFINITIONS
DEBUG_VERBOSE
PRIVATE_INCLUDE_PATHS
${CMAKE_SOURCE_DIR}/include
PUBLIC_LINKED_TARGETS
kami
)
set_target_properties(${EXAMPLE_NAME} PROPERTIES VERSION ${KAMI_VERSION_STRING})

20
include/foo/bar/bar.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef FOO_BAR_HPP_
#define FOO_BAR_HPP_
#include <iostream> // std::cout
// this is a generated header. It is needed
// to build dll libraries that work on windows.
// add the BAR_EXPORT definition to each
// function/class you want to export to the dll.
#include <foo/bar/BAR_EXPORT.h>
namespace foo {
BAR_EXPORT void bar();
} // namespace foo
#endif // FOO_BAZ_HPP_

29
include/foo/cat/cat.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef FOO_CAT_HPP_
#define FOO_CAT_HPP_
#include <iostream> // std::cout
// this is a generated header. It is needed
// to build dll libraries that work on windows.
// add the BAR_EXPORT definition to each
// function/class you want to export to the dll.
#include <foo/cat/CAT_EXPORT.h>
namespace foo {
class CAT_EXPORT cat
{
public:
cat();
~cat();
void call_bar();
};
} // namespace foo
#endif // FOO_BAZ_HPP_

25
include/foo/dog/dog.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef FOO_DOG_HPP_
#define FOO_DOG_HPP_
#include <iostream> // std::cout
// this is a generated header. It is needed
// to build dll libraries that work on windows.
// add the BAR_EXPORT definition to each
// function/class you want to export to the dll.
#include <foo/dog/DOG_EXPORT.h>
namespace foo {
class DOG_EXPORT dog
{
public:
dog();
~dog();
};
} // namespace foo
#endif // FOO_BAZ_HPP_

20
include/kami/data/baz.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef KAMI_DATA_BAZ_HPP
#define KAMI_DATA_BAZ_HPP
#include <iostream> // std::cout
// this is a generated header. It is needed
// to build dll libraries that work on windows.
// add the BAR_EXPORT definition to each
// function/class you want to export to the dll.
#include <kami/data/BAZ_EXPORT.h>
namespace foo {
KAMIDATA_EXPORT void baz();
} // namespace foo
#endif // KAMI_DATA_BAZ_HPP

View File

@@ -0,0 +1,7 @@
# Creating a New Sub Library
Each folder in here is automatically traversed by the root level cmake list file.
1. Copy one of the existing folders to a new name.
2. The name of the folder will be the name of the library (eg: dog -> libdog.so)
3. Change the source file list.

46
src/bar/CMakeLists.txt Normal file
View File

@@ -0,0 +1,46 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
project(bar VERSION 1.2.3)
create_library(NAME bar
NAMESPACE foo
SOURCES
bar.cpp
PUBLIC_INCLUDE_PATHS
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated_headers>"
PRIVATE_LINKED_TARGETS
${COVERAGE_TARGET}
EXPORT_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/foo/bar/BAR_EXPORT.h"
)
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Headers:
# * include/foo/bar/bar.h -> <prefix>/include/NAMESPACE/LIBRARY_NAME/*.h
# * include/foo/bar/bar.h -> <prefix>/include/foo/bar/bar.h
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/include/foo/bar"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/foo/"
FILES_MATCHING PATTERN "*"
)
# Export headers:
# The export header will be stored in:
# <prefix>/include/${NAMESPACE}/LIBRARY_NAME/LIBRARY_NAME_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/foo/bar/BAR_EXPORT.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/foo/bar"
)
################################################################################
# }

10
src/bar/bar.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include <foo/bar/bar.h>
namespace foo {
void bar()
{
std::cout << "--- Bar called ---" << std::endl;
}
} // namespace foo

48
src/cat/CMakeLists.txt Normal file
View File

@@ -0,0 +1,48 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
project(cat VERSION 1.2.3)
create_library(NAME cat
NAMESPACE foo
SOURCES
cat.cpp
PUBLIC_LINKED_TARGETS
foo::bar
PRIVATE_LINKED_TARGETS
${COVERAGE_LIBS}
PUBLIC_INCLUDE_PATHS
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated_headers>"
EXPORT_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/foo/cat/CAT_EXPORT.h"
)
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Headers:
# * include/foo/bar/bar.h -> <prefix>/include/NAMESPACE/LIBRARY_NAME/*.h
# * include/foo/bar/bar.h -> <prefix>/include/foo/bar/bar.h
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/include/foo/cat"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/foo/"
FILES_MATCHING PATTERN "*"
)
# Export headers:
# The export header will be stored in:
# <prefix>/include/${NAMESPACE}/LIBRARY_NAME/LIBRARY_NAME_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/foo/cat/CAT_EXPORT.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/foo/cat"
)
################################################################################
# }

22
src/cat/cat.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <foo/cat/cat.h>
#include <foo/bar/bar.h>
namespace foo {
cat::cat()
{
std::cout << "Cat constructed" << std::endl;
}
cat::~cat()
{
std::cout << "Cat destroyed" << std::endl;
}
void cat::call_bar()
{
std::cout << "Cat calling bar()" << std::endl;
bar();
}
} // namespace foo

49
src/dog/CMakeLists.txt Normal file
View File

@@ -0,0 +1,49 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
project(dog VERSION 1.2.3)
create_library(NAME dog
NAMESPACE foo
SOURCES
dog.cpp
PUBLIC_LINKED_TARGETS
foo::cat foo::bar
PRIVATE_LINKED_TARGETS
${COVERAGE_TARGET}
PUBLIC_INCLUDE_PATHS
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated_headers>"
EXPORT_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/foo/dog/DOG_EXPORT.h"
)
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Headers:
# * include/foo/bar/bar.h -> <prefix>/include/NAMESPACE/LIBRARY_NAME/*.h
# * include/foo/bar/bar.h -> <prefix>/include/foo/bar/bar.h
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/include/foo/dog"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/foo/"
FILES_MATCHING PATTERN "*"
)
# Export headers:
# The export header will be stored in:
# <prefix>/include/${NAMESPACE}/LIBRARY_NAME/LIBRARY_NAME_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/foo/dog/DOG_EXPORT.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/foo/dog"
)
################################################################################
# }

23
src/dog/dog.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <foo/dog/dog.h>
#include <foo/bar/bar.h>
#include <foo/cat/cat.h>
namespace foo {
dog::dog()
{
std::cout << "dog constructed" << std::endl;
}
dog::~dog()
{
#if defined FOO_DOG_DEBUG
#error DEBUG MODE
#endif
std::cout << "dog destroyed" << std::endl;
bar();
foo::cat C;
}
} // namespace foo

63
src/kami/CMakeLists.txt Normal file
View File

@@ -0,0 +1,63 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
project(libkami VERSION ${KAMI_VERSION_STRING}
LANGUAGES CXX)
create_library(NAME kami
NAMESPACE kami
SOURCES
agent.cpp
grid1d.cpp
grid2d.cpp
grid3d.cpp
kami.cpp
multigrid1d.cpp
multigrid2d.cpp
multigrid3d.cpp
random.cpp
sequential.cpp
sologrid1d.cpp
sologrid2d.cpp
sologrid3d.cpp
staged.cpp
PUBLIC_INCLUDE_PATHS
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated_headers>"
PRIVATE_LINKED_TARGETS
${COVERAGE_TARGET}
EXPORT_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/kami/KAMI_EXPORT.h"
)
set_target_properties(kami PROPERTIES VERSION ${KAMI_VERSION_STRING}
SOVERSION ${KAMI_VERSION_MAJOR})
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Headers:
# * include/foo/bar/bar.h -> <prefix>/include/NAMESPACE/LIBRARY_NAME/*.h
# * include/foo/bar/bar.h -> <prefix>/include/foo/bar/bar.h
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/include/kami"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*"
)
# Export headers:
# The export header will be stored in:
# <prefix>/include/${NAMESPACE}/LIBRARY_NAME/LIBRARY_NAME_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/kami/KAMI_EXPORT.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kami"
)
################################################################################
# }

View File

@@ -0,0 +1,49 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
project(libkamidata VERSION ${KAMI_VERSION_STRING})
create_library(NAME kamidata
NAMESPACE kami
SOURCES
baz.cpp
PUBLIC_INCLUDE_PATHS
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated_headers>"
PRIVATE_LINKED_TARGETS
${COVERAGE_TARGET}
EXPORT_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/kami/data/BAZ_EXPORT.h"
)
set_target_properties(kamidata PROPERTIES VERSION ${KAMI_VERSION_STRING}
SOVERSION ${KAMI_VERSION_MAJOR})
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Headers:
# * include/foo/bar/bar.h -> <prefix>/include/NAMESPACE/LIBRARY_NAME/*.h
# * include/foo/bar/bar.h -> <prefix>/include/foo/bar/bar.h
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/include/kami/data"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/data"
FILES_MATCHING PATTERN "*"
)
# Export headers:
# The export header will be stored in:
# <prefix>/include/${NAMESPACE}/LIBRARY_NAME/LIBRARY_NAME_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/generated_headers/kami/data/BAZ_EXPORT.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kami/data"
)
################################################################################
# }

10
src/kamidata/baz.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include <kami/data/baz.h>
namespace foo {
void baz()
{
std::cout << "--- Baz called ---" << std::endl;
}
} // namespace foo

29
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,29 @@
################################################################################
# This CMakeLists.txt contains the build descriptions for unit tests
################################################################################
cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)
create_test( NAME test-foo.cat # Name for the unit test
SOURCES # The sources that will be compiled [optional]
unit-foo.cat.cpp
PUBLIC_LINKED_TARGETS # The targest that need to be linked to this unit test [optional]
foo::cat
${COVERAGE_LIBS}
COMMAND # The command to be called.
test-foo.cat
PUBLIC_COMPILE_FEATURES
${COVERAGE_FLAGS}
)
create_test( NAME test-foo.bar # Name for the unit test
SOURCES # The sources that will be compiled [optional]
unit-foo.bar.cpp
PUBLIC_LINKED_TARGETS # The targest that need to be linked to this unit test [optional]
foo::bar
${COVERAGE_LIBS}
COMMAND # The command to be called.
test-foo.bar
PUBLIC_COMPILE_FEATURES
${COVERAGE_FLAGS}
)

7
test/unit-foo.bar.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include <foo/bar/bar.h>
int main()
{
foo::bar();
return 0;
}

8
test/unit-foo.cat.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <foo/cat/cat.h>
int main()
{
foo::cat C;
C.call_bar();
return 0;
}

View File

@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13) # GENERATOR_IS_MULTI_CONFIG
find_package(foo REQUIRED)
add_executable( test-cat test-cat.cpp)
target_link_libraries( test-cat foo::cat)

View File

@@ -0,0 +1,41 @@
# Test CMake Install
This tests whether the find_package(foo) works properly after the library has
been installed.
To do this, we first have to build the main library and install it into a
temporary location.
```Bash
# Build the main library and install it into /tmp/cpp_library_template
cd cpp_library_template
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/cpp_library_template -DBUILD_SHARED_LIBS:BOOL=TRUE
cmake --build .
cmake --build . --target install
# Delete the build directory to make sure we don't accidentally link to the build
# folder instead.
cd ..
rm -rf build
# Build the test library and point the CMAKE_PREFIX_PATH to the location we
# installed the library to.
cd test_cmake_install/cmake
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH=/tmp/cpp_library_template
cmake --build .
```
Because we installed the libary to a non-standard location, we will need to
set the LD_LIBRARY_PATH env variable before we are able to run the two executables
we created
```Bash
export LD_LIBRARY_PATH=/tmp/cpp_library_template/lib
./test-bar
./test-cat
```

View File

@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.13) # GENERATOR_IS_MULTI_CONFIG
# This Lists file requires that the library be installed to a folder somewhere
find_package(foo)
add_executable( test-cat ../test-cat.cpp)
target_link_libraries( test-cat foo::cat)
add_executable( test-bar ../test-bar.cpp)
target_link_libraries( test-bar foo::bar)

View File

@@ -0,0 +1,5 @@
[requires]
foo/0.1@gavin/testing
[generators]
cmake_paths

View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.13) # GENERATOR_IS_MULTI_CONFIG
list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
#set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR}" CACHE STRING "Modules for CMake" FORCE)
find_package(foo)
add_executable( test-cat ../test-cat.cpp)
add_executable( test-bar ../test-bar.cpp)
# Here foo::foo is defined by the libraries
# listed in the conan file. foo::foo is not defined by
# the normal cmake installation.
target_link_libraries( test-cat foo::foo)
target_link_libraries( test-bar foo::foo)

View File

@@ -0,0 +1,5 @@
[requires]
foo/0.1@local/testing
[generators]
cmake_find_package

View File

@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.13) # GENERATOR_IS_MULTI_CONFIG
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable( test-cat ../test-cat.cpp)
add_executable( test-bar ../test-bar.cpp)
# The values of CONAN_PKG::foo are set by
# the conanfile.py file
target_link_libraries( test-cat CONAN_PKG::foo)
target_link_libraries( test-bar CONAN_PKG::foo)

View File

@@ -0,0 +1,5 @@
[requires]
foo/0.1@local/testing
[generators]
cmake

View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.13) # GENERATOR_IS_MULTI_CONFIG
# This requires that the original library provides a Findfoo.cmake file
#
# If you do not want to use the include. you add this via the command line
# cmake $SRC_FOLDER -DCMAKE_TOOLCHAIN_FILE=$BINARY_FOLDER/conan_paths.cmake
include("${CMAKE_BINARY_DIR}/conan_paths.cmake")
find_package(foo)
add_executable( test-cat ../test-cat.cpp)
add_executable( test-bar ../test-bar.cpp)
# The target foo::cat is provided by the original CMake installation of
# the library.
target_link_libraries( test-cat foo::cat)
target_link_libraries( test-bar foo::bar)

View File

@@ -0,0 +1,5 @@
[requires]
foo/0.1@local/testing
[generators]
cmake_paths

View File

@@ -0,0 +1,8 @@
#include<foo/bar/bar.h>
int main()
{
foo::bar();
return 0;
}

View File

@@ -0,0 +1,11 @@
#include<foo/cat/cat.h>
int main()
{
foo::cat C;
C.call_bar();
return 0;
}

View File

@@ -1,32 +0,0 @@
cmake_minimum_required(VERSION 3.8.2)
# List all files containing tests. (Change as needed)
set(TESTFILES # All .cpp files in tests/
dummy.cpp
)
set(TEST_MAIN unit_tests) # Default name for test executable (change if you wish).
set(TEST_RUNNER_PARAMS "") # Any arguemnts to feed the test runner (change as needed).
# --------------------------------------------------------------------------------
# Make Tests (no change needed).
# --------------------------------------------------------------------------------
add_executable(${TEST_MAIN} ${TESTFILES})
target_link_libraries(${TEST_MAIN} PRIVATE ${LIBRARY_NAME} doctest)
set_target_properties(${TEST_MAIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
target_set_warnings(${TEST_MAIN} ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed).
set_target_properties(${TEST_MAIN} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
add_test(
# Use some per-module/project prefix so that it is easier to run only tests for this module
NAME ${LIBRARY_NAME}.${TEST_MAIN}
COMMAND ${TEST_MAIN} ${TEST_RUNNER_PARAMS})
# Adds a 'coverage' target.
include(CodeCoverage)

View File

@@ -1,5 +0,0 @@
#include <iostream>
int main(void) {
std::cout << "foo";
}