diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5148ca33c15932abaa2d9824763cef26499ff17d..6d4d52be1d2c82151c5e2f08c614de2ef74fdb6e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,9 @@ variables: stages: - config - quality - - build_test + - build + - test + - example - optional # job/stage to just prepare cmake @@ -23,7 +25,6 @@ config-u-18_04: variables: CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" script: - - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git - mkdir build - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON @@ -31,7 +32,6 @@ config-u-18_04: expire_in: 1 day paths: - build - - corsika-data # job/stage to just prepare cmake config-clang-8: @@ -42,7 +42,6 @@ config-clang-8: variables: CORSIKA_DATA: "${CI_BUILDS_DIR}/AirShowerPhysics/corsika/corsika-data/" script: - - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git - mkdir build - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON @@ -50,7 +49,6 @@ config-clang-8: expire_in: 1 day paths: - build - - corsika-data check-copyrights: image: corsika/devel:u-18.04 @@ -71,11 +69,11 @@ check-clang-format: - ./do-clang-format.py --all # normal pipeline for each commit -build-test-u-18_04: +build-u-18_04: image: corsika/devel:u-18.04 dependencies: - config-u-18_04 - stage: build_test + stage: build tags: - corsika variables: @@ -83,6 +81,43 @@ build-test-u-18_04: script: - cd build - cmake --build . -- -j4 + artifacts: + expire_in: 1 hour + paths: + - build + +# normal pipeline for each commit +build-clang-8: + image: corsika/devel:clang-8 + dependencies: + - config-clang-8 + stage: build + tags: + - corsika + variables: + CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" + script: + - cd build + - cmake --build . -- -j4 + artifacts: + expire_in: 1 hour + reports: + paths: + - build + +# normal pipeline for each commit +test-u-18_04: + image: corsika/devel:u-18.04 + dependencies: + - build-u-18_04 + stage: test + tags: + - corsika + variables: + CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" + script: + - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git + - cd build - set -o pipefail - ctest -VV | gzip -v -9 > test.log.gz artifacts: @@ -95,18 +130,18 @@ build-test-u-18_04: - build/test.log.gz # normal pipeline for each commit -build-test-clang-8: +test-clang-8: image: corsika/devel:clang-8 dependencies: - - config-clang-8 - stage: build_test + - build-clang-8 + stage: test tags: - corsika variables: CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" script: + - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git - cd build - - cmake --build . -- -j4 - set -o pipefail - ctest -VV | gzip -v -9 > test.log.gz artifacts: @@ -117,9 +152,51 @@ build-test-clang-8: - build/test_outputs/junit*.xml paths: - build/test.log.gz - + +# normal pipeline for each commit +example-u-18_04: + image: corsika/devel:u-18.04 + dependencies: + - build-u-18_04 + stage: example + tags: + - corsika + variables: + CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" + script: + - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git + - cd build + - set -o pipefail + - make run_examples | gzip -v -9 > examples.log.gz + artifacts: + when: always + expire_in: 1 week + paths: + - build/examples.log.gz + +# normal pipeline for each commit +example-clang-8: + image: corsika/devel:clang-8 + dependencies: + - build-clang-8 + stage: example + tags: + - corsika + variables: + CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" + script: + - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git + - cd build + - set -o pipefail + - make run_examples | gzip -v -9 > examples.log.gz + artifacts: + when: always + expire_in: 1 week + paths: + - build/examples.log.gz + # optional release pipeline for each commit -release-u-18_04: +release-full-u-18_04: image: corsika/devel:u-18.04 dependencies: - config-u-18_04 @@ -129,11 +206,13 @@ release-u-18_04: variables: CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" script: + - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git - cd build - cmake .. -DCMAKE_BUILD_TYPE=Release - cmake --build . -- -j4 - set -o pipefail - ctest -VV | gzip -v -9 > test.log.gz + - make run_examples artifacts: when: always expire_in: 1 week @@ -145,7 +224,7 @@ release-u-18_04: when: manual # optional release pipeline for each commit -release-clang-8: +release-full-clang-8: image: corsika/devel:clang-8 dependencies: - config-clang-8 @@ -155,11 +234,13 @@ release-clang-8: variables: CORSIKA_DATA: "${CI_PROJECT_DIR}/corsika-data/" script: + - git clone https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika-data.git - cd build - cmake .. -DCMAKE_BUILD_TYPE=Release - cmake --build . -- -j4 - set -o pipefail - - ctest -VV | gzip -v -9 > test.log.gz + - ctest -VV | gzip -v -9 > test.log.gz + - make run_examples artifacts: when: always expire_in: 1 week diff --git a/CMakeModules/CorsikaUtilities.cmake b/CMakeModules/CorsikaUtilities.cmake index 090e26065dc987d602d28b246412574566e18ea2..d80269b3a24e549a7655b769099bd6579a79a112 100644 --- a/CMakeModules/CorsikaUtilities.cmake +++ b/CMakeModules/CorsikaUtilities.cmake @@ -31,7 +31,8 @@ endfunction (CORSIKA_PREPEND_PATH) # # if needed, create symbolic links from the source files to this build-directory location # -# any path information from input filenames is stripped, IF path was specified it is used for the link destination, if NOT the link is relative to the CMAKE_CURRENT_SOURCE_DIR +# any path information from input filenames is stripped, IF path was specified it is used for the link destination, +# if NOT the link is relative to the CMAKE_CURRENT_SOURCE_DIR # function (CORSIKA_COPY_HEADERS_TO_NAMESPACE for_library in_namespace) set (HEADERS_BUILD "") @@ -126,20 +127,19 @@ endmacro(CORSIKA_ADD_FILES_ABSOLUTE) # TEMPORARY: All sanitizers are currently globally disabled by default, to enable them, # set CORSIKA_SANITIZERS_ENABLED to TRUE. function (CORSIKA_ADD_TEST) - cmake_parse_arguments (PARSE_ARGV 1 _ "" "SANITIZE" "SOURCES") - + cmake_parse_arguments (PARSE_ARGV 1 C8_ADD_TEST "" "SANITIZE" "SOURCES") set (name ${ARGV0}) - if (NOT __SOURCES) + if (NOT C8_ADD_TEST_SOURCES) set (sources ${name}.cc) else () - set (sources ${__SOURCES}) + set (sources ${C8_ADD_TEST_SOURCES}) endif () - if (NOT __SANITIZE) + if (NOT C8_ADD_TEST_SANITIZE) set(sanitize "address,undefined") else () - set(sanitize ${__SANITIZE}) + set(sanitize ${C8_ADD_TEST_SANITIZE}) endif () add_executable (${name} ${sources}) @@ -153,3 +153,63 @@ 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 exmaple in cmake +# +# Examples can be globally executed by 'make run_examples' +# +# 1) Simple use: +# Pass the name of the test.cc file as the first +# argument, without the ".cc" extention. +# +# Example: CORSIKA_ADD_EXAMPLE (testSomething) +# +# This generates target testSomething from file testSomething.cc. +# +# 2) Customize sources: +# If 1) doesn't work, use the SOURCES keyword to explicitly +# specify the sources. +# +# Example: CORSIKA_ADD_EXAMPLE (testSomething +# SOURCES source1.cc source2.cc someheader.h) +# +# In all cases, you can further customize the target with +# target_link_libraries(testSomething ...) and so on. +# +function (CORSIKA_ADD_EXAMPLE) + cmake_parse_arguments (PARSE_ARGV 1 C8_ADD_EXAMPLE "" "" "SOURCES;RUN_OPTIONS") + set (name ${ARGV0}) + + if (NOT C8_ADD_EXAMPLE_SOURCES) + set (sources ${name}.cc) + else () + set (sources ${C8_ADD_EXAMPLE_SOURCES}) + endif () + + if (NOT C8_ADD_EXAMPLE_RUN_OPTIONS) + set (run_options "") + else () + set (run_options ${C8_ADD_EXAMPLE_RUN_OPTIONS}) + endif () + + add_executable (${name} ${sources}) + target_compile_options (${name} PRIVATE -g) # do not skip asserts + target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/example_outputs/) + if (TARGET run_examples) + else () + add_custom_target (run_examples) + endif () + add_dependencies (run_examples ${name}) + 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 ${CMAKE_CURRENT_BINARY_DIR}/${name} ${run_options} VERBATIM + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/example_outputs) + install (TARGETS ${name} DESTINATION share/examples) +endfunction (CORSIKA_ADD_EXAMPLE) diff --git a/Documentation/Examples/CMakeLists.txt b/Documentation/Examples/CMakeLists.txt index 474bbe4224b075a3b7e8f759414322e5f481d812..ee95e2e89956ec8ca79ce7b90f890a166aa7bb69 100644 --- a/Documentation/Examples/CMakeLists.txt +++ b/Documentation/Examples/CMakeLists.txt @@ -1,67 +1,64 @@ -CORSIKA_ADD_TEST (helix_example) + +CORSIKA_ADD_EXAMPLE (helix_example) target_link_libraries (helix_example CORSIKAgeometry CORSIKAunits) -install (TARGETS helix_example DESTINATION share/examples) -CORSIKA_ADD_TEST (particle_list_example) +CORSIKA_ADD_EXAMPLE (particle_list_example) target_link_libraries (particle_list_example CORSIKAparticles CORSIKAunits CORSIKAprocesses ProcessSibyll ProcessQGSJetII) -install (TARGETS particle_list_example DESTINATION share/examples) -CORSIKA_ADD_TEST (geometry_example) +CORSIKA_ADD_EXAMPLE (geometry_example) target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits) -install (TARGETS geometry_example DESTINATION share/examples) -CORSIKA_ADD_TEST (logger_example) +CORSIKA_ADD_EXAMPLE (logger_example) target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) -install (TARGETS logger_example DESTINATION share/examples) -CORSIKA_ADD_TEST (stack_example) +CORSIKA_ADD_EXAMPLE (stack_example) target_link_libraries (stack_example SuperStupidStack CORSIKAunits CORSIKAlogging) # address sanitizer is making this example too slow, so we only do "undefined" -CORSIKA_ADD_TEST (cascade_example SANITIZE "undefined") -target_link_libraries (cascade_example +CORSIKA_ADD_EXAMPLE (boundary_example) +target_link_libraries (boundary_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom ProcessSibyll CORSIKAcascade - ProcessEnergyLoss - ProcessStackInspector - ProcessParticleCut ProcessTrackWriter + ProcessParticleCut ProcessTrackingLine CORSIKAprocesses - CORSIKAcascade CORSIKAparticles CORSIKAgeometry CORSIKAenvironment CORSIKAprocesssequence ) -install (TARGETS cascade_example DESTINATION share/examples) -CORSIKA_ADD_TEST (boundary_example) -target_link_libraries (boundary_example +CORSIKA_ADD_EXAMPLE (cascade_example) +target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom ProcessSibyll CORSIKAcascade + ProcessEnergyLoss ProcessTrackWriter - ProcessParticleCut + ProcessStackInspector ProcessTrackingLine + ProcessParticleCut + ProcessHadronicElasticModel + ProcessStackInspector CORSIKAprocesses + CORSIKAcascade CORSIKAparticles CORSIKAgeometry CORSIKAenvironment CORSIKAprocesssequence ) -install (TARGETS boundary_example DESTINATION share/examples) if (Pythia8_FOUND) - CORSIKA_ADD_TEST (cascade_proton_example) + CORSIKA_ADD_EXAMPLE (cascade_proton_example) target_link_libraries (cascade_proton_example SuperStupidStack CORSIKAunits @@ -84,9 +81,8 @@ if (Pythia8_FOUND) CORSIKAenvironment CORSIKAprocesssequence ) - install (TARGETS cascade_proton_example DESTINATION share/examples) - add_executable(vertical_EAS vertical_EAS.cc) + CORSIKA_ADD_EXAMPLE (vertical_EAS RUN_OPTIONS 4 2 10000.) target_link_libraries (vertical_EAS SuperStupidStack CORSIKAunits @@ -99,10 +95,11 @@ if (Pythia8_FOUND) CORSIKAcascade ProcessEnergyLoss ProcessObservationPlane + ProcessInteractionCounter + ProcessTrackWriter ProcessTrackingLine ProcessParticleCut ProcessStackInspector - ProcessInteractionCounter CORSIKAprocesses CORSIKAcascade CORSIKAparticles @@ -110,11 +107,9 @@ if (Pythia8_FOUND) CORSIKAenvironment CORSIKAprocesssequence ) - install (TARGETS vertical_EAS DESTINATION share/examples) - endif() -CORSIKA_ADD_TEST(stopping_power) +CORSIKA_ADD_EXAMPLE (stopping_power stopping_power) target_link_libraries (stopping_power SuperStupidStack CORSIKAunits @@ -124,10 +119,9 @@ target_link_libraries (stopping_power CORSIKAenvironment ) -CORSIKA_ADD_TEST (staticsequence_example) +CORSIKA_ADD_EXAMPLE (staticsequence_example) target_link_libraries (staticsequence_example CORSIKAprocesssequence CORSIKAunits CORSIKAgeometry CORSIKAlogging) -install (TARGETS staticsequence_example DESTINATION share/examples)