IAP GITLAB

Commit e845cfd7 authored by Ralf Ulrich's avatar Ralf Ulrich

Merge branch '360-export-cmake-targets-for-corsika8-as-framework' into 'master'

Resolve "Export cmake targets for CORSIKA8 as framework"

Closes #360

See merge request !306
parents 5c9ea67a ca319868
Pipeline #3486 passed with stages
in 25 minutes and 45 seconds
......@@ -12,6 +12,7 @@ variables:
ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1"
# location of AirShowerPhysics/corsika-data
CORSIKA_DATA: "${CI_PROJECT_DIR}/modules/data" # the git submodule
corsika_DIR: "${CI_PROJECT_DIR}/build/install" # for cmake to find corsikaConfig.cmake
# _alternatively_ corsika-data can be downloaded as submodule:
GIT_SUBMODULE_STRATEGY: normal # none: we get the submodules in before_script,
# normal: get submodules automatically
......@@ -92,7 +93,7 @@ check-clang-format:
script:
- mkdir -p build
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHIA8_C8=C8
- cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_BUILD_TYPE=Debug -DUSE_Pythia8_C8=C8
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_TAG
......@@ -279,56 +280,6 @@ build_test-clang-8:
####### EXAMPLE (only manual) ##############
##########################################################
# generic example template job
# normal pipeline for each commit
.example:
stage: example
tags:
- corsika
script:
- cd build
- set -o pipefail
- make -j4 run_examples | gzip -v -9 > examples.log.gz
rules:
- if: $CI_MERGE_REQUEST_ID
when: manual
- if: $CI_COMMIT_TAG
when: manual
- if: $CI_COMMIT_BRANCH
when: manual
allow_failure: true
artifacts:
when: always
expire_in: 3 days
paths:
- ${CI_PROJECT_DIR}/build/examples.log.gz
cache:
paths:
- ${CI_PROJECT_DIR}/build/
untracked: true
policy: pull
# example for gcc
example-u-18_04:
extends: .example
image: corsika/devel:u-18.04
dependencies:
- build-u-18_04
cache:
key: "${CI_COMMIT_REF_SLUG}-gcc"
# example for clang
example-clang-8:
extends: .example
image: corsika/devel:clang-8
dependencies:
- build-clang-8
cache:
key: "${CI_COMMIT_REF_SLUG}-clang"
####### BUILD-TEST-EXAMPLE (only non-Draft) ##############
......@@ -345,6 +296,11 @@ example-clang-8:
- cmake --build . -- -j4
- set -o pipefail
- ctest -j4
- make install
- mkdir -p build_examples
- cd build_examples
- cmake ../install/share/corsika/examples
- make -j4
- make -j4 run_examples | gzip -v -9 > examples.log.gz
rules:
- if: '$CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_TITLE =~ /^Draft:/'
......@@ -362,7 +318,7 @@ example-clang-8:
junit:
- ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
paths:
- ${CI_PROJECT_DIR}/build/examples.log.gz
- ${CI_PROJECT_DIR}/build/build_examples/examples.log.gz
cache:
paths:
- ${CI_PROJECT_DIR}/build/
......@@ -450,10 +406,15 @@ install-clang-8:
- corsika
script:
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_PYTHIA8_C8=C8
- cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_Pythia8_C8=C8
- cmake --build . -- -j4
- set -o pipefail
- ctest -j4
- make install
- mkdir -p build_examples
- cd build_examples
- cmake ../install/share/corsika/examples
- make -j4
- make -j4 run_examples | gzip -v -9 > examples.log.gz
rules:
- if: '$CI_MERGE_REQUEST_LABELS =~ /Ready for code review/' # run on merge requests, if label 'Ready for code review' is set
......@@ -478,7 +439,7 @@ install-clang-8:
junit:
- ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
paths:
- ${CI_PROJECT_DIR}/build/examples.log.gz
- ${CI_PROJECT_DIR}/build/build_examples/examples.log.gz
# release for gcc
release-full-u-18_04:
......@@ -513,7 +474,7 @@ coverage:
- corsika
script:
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=Coverage -DUSE_PYTHIA8_C8=C8
- cmake .. -DCMAKE_BUILD_TYPE=Coverage -DUSE_Pythia8_C8=C8
- cmake --build . -- -j4
- ctest -j4
- cmake --build . --target coverage
......@@ -575,5 +536,3 @@ sanity:
untracked: true
policy: pull
key: "${CI_COMMIT_REF_SLUG}-gcc"
cmake_minimum_required (VERSION 3.9)
#+++++++++++++++++++++++++++++
# project name
#
set (c8_version 8.0.0)
project (
corsika
VERSION ${c8_version}
DESCRIPTION "CORSIKA C++ project (alpha status)"
LANGUAGES CXX
)
#+++++++++++++++++++++++++++++
# prevent in-source builds and give warning message
#
......@@ -10,15 +21,16 @@ if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
You must delete them, or cmake will refuse to work.")
endif ()
#+++++++++++++++++++++++++++++
# project name
#++++++++++++++++++++++++++++
# cmake version-specific settings
#
project (
corsika
VERSION 8.0.0
DESCRIPTION "CORSIKA C++ project (alpha status)"
LANGUAGES CXX
)
# https://cmake.org/cmake/help/latest/policy/CMP0079.html
if (${CMAKE_VERSION} VERSION_GREATER "3.13.0")
cmake_policy (SET CMP0079 NEW)
endif ()
if (POLICY CMP0079)
cmake_policy (SET CMP0079 NEW)
endif ()
#+++++++++++++++++++++++++++++
# as long as there still are modules using it:
......@@ -46,7 +58,7 @@ set (CMAKE_INSTALL_MESSAGE LAZY)
#+++++++++++++++++++++++++++++
# Setup hardware and infrastructure dependent defines
#
include(CorsikaDefines)
include (CorsikaDefines)
#+++++++++++++++++++++++++++++
# check if compiler is C++17 compliant
......@@ -68,7 +80,6 @@ set (CMAKE_CXX_EXTENSIONS OFF)
# FYI: optimizer flags: -O2 would not trade speed for size, neither O2/3 use fast-math
# debug: O0, relwithdebinfo: 02, release: O3, minsizerel: Os (all defaults)
set (CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -Wno-ignored-qualifiers")
set (CMAKE_Fortran_FLAGS "-std=legacy -Wfunction-elimination")
set (DEFAULT_BUILD_TYPE "Release")
# clang produces a lot of unecessary warnings without this:
......@@ -149,7 +160,7 @@ if (CMAKE_BUILD_TYPE STREQUAL Coverage)
add_custom_command (
OUTPUT coverage.info
COMMAND ${LCOV_BIN_DIR}/lcov -q --remove raw-coverage.info "*/usr/*" "/usr/*" --output-file coverage2.info
COMMAND ${LCOV_BIN_DIR}/lcov --remove coverage2.info "*/externals/*" "*/tests/*" "*/sibyll2.3d.cpp" "*/.conan/*" "*/include/Pythia8/*" "${CMAKE_CURRENT_SOURCE_DIR}/modules/*" "${CMAKE_CURRENT_BINARY_DIR}/modules/*" --output-file coverage.info
COMMAND ${LCOV_BIN_DIR}/lcov --remove coverage2.info "*/externals/*" "*/tests/*" "*/sibyll2.3d.cpp" "*/.conan/*" "*/include/Pythia8/*" "${CMAKE_SOURCE_DIR}/modules/*" "${CMAKE_BINARY_DIR}/modules/*" --output-file coverage.info
COMMAND ${CMAKE_COMMAND} -E remove coverage2.info
DEPENDS raw-coverage.info
)
......@@ -175,7 +186,7 @@ set (CTEST_CUSTOM_COVERAGE_EXCLUDE "./tests/" "./examples/" "./modules/" "test*.
# include this test only if NOT run on gitlab-ci; On CI this is a dedicated job:
if (NOT DEFINED ENV{CI})
# add call to ./do-copyright.py to run as unit-test-case
add_test (NAME copyright_notices COMMAND ./do-copyright.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME copyright_notices COMMAND ./do-copyright.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif (NOT DEFINED ENV{CI})
#+++++++++++++++++++++++++++++
......@@ -190,17 +201,33 @@ option (WITH_HISTORY "Flag to switch on/off HISTORY" ON)
set (Python_ADDITIONAL_VERSIONS 3)
find_package (PythonInterp 3 REQUIRED)
#+++++++++++++++++++++++++++++++
# exporting of CMake targets
#
include (CMakePackageConfigHelpers)
# list of targets that will be INSTALLed and EXPORTed
# Important: all those targets must be individually INSTALLed with "EXPORT CORSIKA8PublicTargets"
set (public_CORSIKA8_targets CORSIKA8)
#+++++++++++++++++++++++++++++
# CORSIKA8
#
add_library (CORSIKA8 INTERFACE)
set_target_properties (
CORSIKA8
PROPERTIES
INTERFACE_CORSIKA8_MAJOR_VERSION 0
COMPATIBLE_INTERFACE_STRING CORSIKA8_MAJOR_VERSION
)
#
target_include_directories (
CORSIKA8
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
# since CORSIKA8 is a header only library we must specify all link dependencies here:
target_link_libraries (
......@@ -217,22 +244,21 @@ add_subdirectory (src)
add_subdirectory (documentation)
#+++++++++++++++++++++++++++++
# =~~~~~~~~~~~~~~~~~~~~~~~~~=
# = Add of subdirectories =
# =~~~~~~~~~~~~~~~~~~~~~~~~~=
#
#+++++++++++++++++++++++++++++
# modules
#
set (CORSIKA_DATA_WITH_TEST ON) # we want to run the corsika-data unit test
add_subdirectory (modules/data) # this is corsika-data (submodule)
add_subdirectory (modules/pythia)
add_subdirectory (modules/pythia8)
add_subdirectory (modules/sibyll)
add_subdirectory (modules/qgsjetII)
add_subdirectory (modules/urqmd)
add_subdirectory (modules/conex)
#
# we really need a better proposal CMakeList.txt files:
# we really need a better proposal CMakeList.txt file:
set (ADD_PYTHON OFF)
file (READ modules/CMakeLists_PROPOSAL.txt overwrite_CMakeLists_PROPOSAL_txt)
file (WRITE modules/proposal/CMakeLists.txt ${overwrite_CMakeLists_PROPOSAL_txt})
......@@ -245,9 +271,79 @@ target_link_libraries (CORSIKA8 INTERFACE PROPOSAL)
add_subdirectory (tests)
#+++++++++++++++++++++++++++++++
# installation
#
install (
TARGETS CORSIKA8
EXPORT CORSIKA8PublicTargets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}
)
#
# header only part
#
install (DIRECTORY corsika DESTINATION include)
write_basic_package_version_file (
${PROJECT_BINARY_DIR}/corsikaConfigVersion.cmake
VERSION ${c8_version}
COMPATIBILITY SameMajorVersion
)
# export targets in build tree
export (
EXPORT CORSIKA8PublicTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/corsikaTargets.cmake"
NAMESPACE CORSIKA8::
)
# export targets in install tree
install (
EXPORT CORSIKA8PublicTargets
FILE corsikaTargets.cmake
NAMESPACE CORSIKA8::
DESTINATION lib/cmake/corsika
)
# config for build tree
configure_package_config_file (
cmake/corsikaConfig.cmake.in
${PROJECT_BINARY_DIR}/corsikaConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}
)
# config for install tree
# overwrite with install location (if it was build as part of corsika)
set (Pythia8_INCDIR ${Pythia8_INCDIR_INSTALL})
set (Pythia8_LIBDIR ${Pythia8_LIBDIR_INSTALL})
configure_package_config_file (
cmake/corsikaConfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/corsikaConfig.cmake
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}/do_not_need_this
)
install (
FILES
${CMAKE_BINARY_DIR}/conanbuildinfo.cmake
${CMAKE_BINARY_DIR}/conaninfo.txt
${CMAKE_BINARY_DIR}/corsikaConfig.cmake
${CMAKE_BINARY_DIR}/corsikaConfigVersion.cmake
DESTINATION lib/cmake/corsika
)
#
# examples
#
add_subdirectory (examples)
install (DIRECTORY examples DESTINATION share/corsika)
#
# tools
#
install (DIRECTORY tools DESTINATION share/corsika)
#+++++++++++++++++++++++++++++++
#
......
#
# Floating point exception support - select implementation to use
#
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX("fenv.h" HAS_FEENABLEEXCEPT)
include (CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX ("fenv.h" HAS_FEENABLEEXCEPT)
if (HAS_FEENABLEEXCEPT) # FLOATING_POINT_ENVIRONMENT
set (CORSIKA_HAS_FEENABLEEXCEPT 1)
set_property(DIRECTORY ${CMAKE_HOME_DIRECTORY} APPEND PROPERTY COMPILE_DEFINITIONS "HAS_FEENABLEEXCEPT")
set_property (DIRECTORY ${CMAKE_HOME_DIRECTORY} APPEND PROPERTY COMPILE_DEFINITIONS "HAS_FEENABLEEXCEPT")
endif ()
......@@ -13,12 +13,12 @@ endif ()
# General OS Detection
#
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CORSIKA_OS_WINDOWS TRUE)
set (CORSIKA_OS_WINDOWS TRUE)
set (CORSIKA_OS "Windows")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CORSIKA_OS_LINUX TRUE)
set (CORSIKA_OS_LINUX TRUE)
set (CORSIKA_OS "Linux")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CORSIKA_OS_MAC TRUE)
set (CORSIKA_OS_MAC TRUE)
set (CORSIKA_OS "Mac")
endif()
\ No newline at end of file
endif ()
......@@ -68,55 +68,3 @@ function (CORSIKA_ADD_TEST)
endif ()
add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -s -r junit)
endfunction (CORSIKA_ADD_TEST)
#################################################
#
# central macro to register an examples in cmake
#
# Examples can be globally executed by 'make run_examples'
#
# 1) Simple use:
# Pass the name of the source.cc file as the first
# argument, without the ".cc" extention.
#
# Example: CORSIKA_REGISTER_EXAMPLE (doSomething)
#
# The TARGET doSomething must already exists,
# i.e. typically via add_executable (doSomething src.cc).
#
# Example: CORSIKA_ADD_EXAMPLE (example_one
# RUN_OPTION "extra command line options"
# )
#
# In all cases, you can further customize the target with
# target_link_libraries(example_one ...) and so on.
#
function (CORSIKA_REGISTER_EXAMPLE)
cmake_parse_arguments (PARSE_ARGV 1 C8_EXAMPLE "" "" "RUN_OPTIONS")
set (name ${ARGV0})
if (NOT C8_EXAMPLE_RUN_OPTIONS)
set (run_options "")
else ()
set (run_options ${C8_EXAMPLE_RUN_OPTIONS})
endif ()
target_compile_options (${name} PRIVATE -g) # do not skip asserts
file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/example_outputs/)
if (TARGET run_examples)
else ()
add_custom_target (run_examples)
endif ()
add_dependencies (run_examples ${name})
# just run the command as-is
set (CMD ${CMAKE_BINARY_DIR}/bin/${name} ${run_options})
add_custom_command (TARGET run_examples
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "**************************************"
COMMAND ${CMAKE_COMMAND} -E echo "***** running example: ${name} " ${run_options} VERBATIM
COMMAND ${CMD} VERBATIM
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/example_outputs)
install (TARGETS ${name} DESTINATION share/examples)
endfunction (CORSIKA_REGISTER_EXAMPLE)
......@@ -68,6 +68,11 @@ find_file (Pythia8_Pythia_h_LOC
PATH_SUFFIXES include/Pythia8
DOC "The location of the Pythia8/Pythia.h script"
REQUIRED)
if ("${Pythia8_Pythia_h_LOC}" STREQUAL "Pythia8_Pythia_h_LOC-NOTFOUND")
message (FATAL_ERROR "Did not find SYSTEM-level Pythia8 in: \"${_SEARCH_Pythia8_}\"")
endif ()
string (REPLACE "/include/Pythia8/Pythia.h" "" Pythia8_DIR ${Pythia8_Pythia_h_LOC})
set (Pythia8_CONFIG ${Pythia8_DIR}/bin/pythia-config)
......
set (CORSIKA8_VERSION @c8_version@)
@PACKAGE_INIT@
#++++++++++++++++++++++++++++
# General config and flags
#
set (CMAKE_CXX_STANDARD @CMAKE_CXX_STANDARD@)
set (CMAKE_CXX_EXTENSIONS @CMAKE_CXX_EXTENSIONS@)
set (COMPILE_OPTIONS @COMPILE_OPTIONS@)
set (CMAKE_VERBOSE_MAKEFILE @CMAKE_VERBOSE_MAKEFILE@)
#+++++++++++++++++++++++++++++
# Setup external dependencies via conan
#
include (${CMAKE_CURRENT_LIST_DIR}/conanbuildinfo.cmake)
conan_basic_setup (TARGETS)
#+++++++++++++++++++++++++++++
# Import Pythia8
# since we always import pythia (ExternalProject_Add) we have to
# import here, too.
#
add_library (C8::ext::pythia8 STATIC IMPORTED GLOBAL)
set_target_properties (
C8::ext::pythia8 PROPERTIES
IMPORTED_LOCATION @Pythia8_LIBDIR@/libpythia8.a
IMPORTED_LINK_INTERFACE_LIBRARIES dl
INTERFACE_INCLUDE_DIRECTORIES @Pythia8_INCDIR@
)
set (Pythia8_FOUND @Pythia8_FOUND@)
message (STATUS "Pythia8 at: @Pythia8_PREFIX@")
#++++++++++++++++++++++++++++++
# import CORSIKA8
#
include ("${CMAKE_CURRENT_LIST_DIR}/corsikaTargets.cmake")
check_required_components (corsika)
......@@ -52,7 +52,7 @@ namespace corsika {
inline QuantityVector<length_d>& getCoordinates(CoordinateSystemPtr const& pCS);
/**
* \defgroup access coordinate components
* \name access coordinate components
* \{
*
* Note, if you access components in a different CoordinateSystem
......
......@@ -9,7 +9,7 @@
#pragma once
// the location of the "xmldoc" pythia directory (data files, config)
#include <Pythia8ConfigurationDirectory.hpp>
#include <corsika/modules/pythia8/Pythia8ConfigurationDirectory.hpp>
// the main pythia include
#include <Pythia8/Pythia.h>
set (
HISTORY_HEADERS
EventType.hpp
Event.hpp
HistorySecondaryProducer.hpp
HistoryObservationPlane.hpp
HistoryStackExtension.hpp
SecondaryParticle.hpp
)
set (
HISTORY_NAMESPACE
corsika/stack/history
)
if (WITH_HISTORY)
set (
HISTORY_SOURCES
HistoryObservationPlane.cpp
)
add_library (CORSIKAhistory STATIC ${HISTORY_SOURCES})
set (IS_INTERFACE "")
else (WITH_HISTORY)
add_library (CORSIKAhistory INTERFACE)
set (IS_INTERFACE "INTERFACE")
endif (WITH_HISTORY)
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAhistory ${HISTORY_NAMESPACE} ${HISTORY_HEADERS})
target_link_libraries (
CORSIKAhistory
${IS_INTERFACE}
CORSIKAparticles
CORSIKAgeometry
CORSIKAprocesssequence # for HistoryObservationPlane
CORSIKAsetup # for HistoryObservationPlane
CORSIKAlogging
SuperStupidStack
NuclearStackExtension # for testHistoryView.cc
C8::ext::boost # for HistoryObservationPlane
)
target_include_directories (
CORSIKAhistory
INTERFACE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/include>
)
install (
FILES ${HISTORY_HEADERS}
DESTINATION include/${HISTORY_NAMESPACE}
)
# ----------------
# code unit testing
CORSIKA_ADD_TEST(testHistoryStack)
target_link_libraries (
testHistoryStack
CORSIKAhistory
CORSIKAtesting
DummyStack
)
CORSIKA_ADD_TEST(testHistoryView)
target_link_libraries (
testHistoryView
CORSIKAhistory
CORSIKAtesting
)
......@@ -3,7 +3,7 @@ find_package (Doxygen OPTIONAL_COMPONENTS dot mscgen dia)
if (DOXYGEN_FOUND)
if (NOT DOXYGEN_DOT_EXECUTABLE)
message (FATAL_ERROR "Found doxygen but not 'dot' command, please install graphviz or set DOXYGEN_DOT_EXECUTABLE")
endif()
endif (NOT DOXYGEN_DOT_EXECUTABLE)
set (DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set (DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
......@@ -17,14 +17,15 @@ if (DOXYGEN_FOUND)
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
VERBATIM
)
add_custom_command(TARGET doxygen POST_BUILD
add_custom_command (TARGET doxygen POST_BUILD
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/latex; pdflatex refman.tex
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc OPTIONAL)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latex/refman.pdf DESTINATION share/doc OPTIONAL)
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc OPTIONAL)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/latex/refman.pdf DESTINATION share/doc OPTIONAL)
else (DOXYGEN_FOUND)
......
#################################################
#
# central macro to register an examples in cmake
#
# Examples can be globally executed by 'make run_examples'
#
# 1) Simple use:
# Pass the name of the source.cc file as the first
# argument, without the ".cc" extention.
#
# Example: CORSIKA_REGISTER_EXAMPLE (doSomething)
#
# The TARGET doSomething must already exists,
# i.e. typically via add_executable (doSomething src.cc).
#
# Example: CORSIKA_ADD_EXAMPLE (example_one
# RUN_OPTION "extra command line options"
# )
#
# In all cases, you can further customize the target with
# target_link_libraries (example_one ...) and so on.
#
function (CORSIKA_REGISTER_EXAMPLE)
cmake_parse_arguments (PARSE_ARGV 1 C8_EXAMPLE "" "" "RUN_OPTIONS")
set (name ${ARGV0})
if (NOT C8_EXAMPLE_RUN_OPTIONS)
set (run_options "")
else ()
set (run_options ${C8_EXAMPLE_RUN_OPTIONS})
endif ()
target_compile_options (${name} PRIVATE -g) # do not skip asserts
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example_outputs/)
if (TARGET run_examples)
else ()
add_custom_target (run_examples)
endif ()
add_dependencies (run_examples ${name})
# just run the command as-is
set (CMD ${CMAKE_CURRENT_BINARY_DIR}/bin/${name} ${run_options})
add_custom_command (TARGET run_examples
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "**************************************"
COMMAND ${CMAKE_COMMAND} -E echo "***** running example: ${name} " ${run_options} VERBATIM
COMMAND ${CMD} VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example_outputs)
install (TARGETS ${name} DESTINATION share/examples)