diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1765db34..451fafe2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,7 @@ jobs: run: | mkdir build cd build - cmake .. + cmake -DRMG_BUILD_EXAMPLES=1 .. make make install - name: Run full test suite diff --git a/CMakeLists.txt b/CMakeLists.txt index bda82abc..3dc8841f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,11 @@ if(RMG_BUILD_DOCS) add_subdirectory(docs) endif() +option(RMG_BUILD_EXAMPLES "Build all remage examples" OFF) +if(RMG_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() + include(CTest) add_subdirectory(tests) diff --git a/examples/01-gdml/CMakeLists.txt b/examples/01-gdml/CMakeLists.txt index 33657b3a..5c04772d 100644 --- a/examples/01-gdml/CMakeLists.txt +++ b/examples/01-gdml/CMakeLists.txt @@ -3,7 +3,10 @@ project(01-gdml) set(CMAKE_BUILD_TYPE RelWithDebInfo) -find_package(remage REQUIRED COMPONENTS GDML) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # stand-alone build. + find_package(remage REQUIRED COMPONENTS GDML) +endif() add_executable(01-gdml main.cc) target_link_libraries(01-gdml PUBLIC RMG::remage) diff --git a/examples/02-hpge/CMakeLists.txt b/examples/02-hpge/CMakeLists.txt index 653c34c1..111c0314 100644 --- a/examples/02-hpge/CMakeLists.txt +++ b/examples/02-hpge/CMakeLists.txt @@ -3,7 +3,10 @@ project(02-hpge) set(CMAKE_BUILD_TYPE RelWithDebInfo) -find_package(remage) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # stand-alone build. + find_package(remage REQUIRED) +endif() add_executable(02-hpge main.cc HPGeTestStand.hh HPGeTestStand.cc) target_link_libraries(02-hpge PUBLIC RMG::remage) diff --git a/examples/03-optics/CMakeLists.txt b/examples/03-optics/CMakeLists.txt index 24ba9f1b..14934f46 100644 --- a/examples/03-optics/CMakeLists.txt +++ b/examples/03-optics/CMakeLists.txt @@ -3,7 +3,10 @@ project(03-optics) set(CMAKE_BUILD_TYPE RelWithDebInfo) -find_package(remage REQUIRED COMPONENTS GDML) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # stand-alone build. + find_package(remage REQUIRED COMPONENTS GDML) +endif() add_executable(03-optics main.cc) target_link_libraries(03-optics PUBLIC RMG::remage) diff --git a/examples/04-cosmogenics/CMakeLists.txt b/examples/04-cosmogenics/CMakeLists.txt index 9286cfdf..f1a9ed82 100644 --- a/examples/04-cosmogenics/CMakeLists.txt +++ b/examples/04-cosmogenics/CMakeLists.txt @@ -3,7 +3,10 @@ project(04-surface-cosmogenic) set(CMAKE_BUILD_TYPE RelWithDebInfo) -find_package(remage) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # stand-alone build. + find_package(remage REQUIRED) +endif() add_executable(04-surface-cosmogenic main.cc HPGeTestStand.hh HPGeTestStand.cc) target_link_libraries(04-surface-cosmogenic PUBLIC RMG::remage) diff --git a/examples/05-MUSUN/CMakeLists.txt b/examples/05-MUSUN/CMakeLists.txt index 32c75290..48eef282 100644 --- a/examples/05-MUSUN/CMakeLists.txt +++ b/examples/05-MUSUN/CMakeLists.txt @@ -3,7 +3,10 @@ project(05-MUSUN) set(CMAKE_BUILD_TYPE RelWithDebInfo) -find_package(remage) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # stand-alone build. + find_package(remage REQUIRED) +endif() add_executable(05-MUSUN main.cc HPGeTestStand.hh HPGeTestStand.cc) target_link_libraries(05-MUSUN PUBLIC RMG::remage) diff --git a/examples/06-NeutronCapture/CMakeLists.txt b/examples/06-NeutronCapture/CMakeLists.txt index f0e87bac..ac84971a 100644 --- a/examples/06-NeutronCapture/CMakeLists.txt +++ b/examples/06-NeutronCapture/CMakeLists.txt @@ -3,7 +3,10 @@ project(06-NeutronCapture) set(CMAKE_BUILD_TYPE RelWithDebInfo) -find_package(remage) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # stand-alone build. + find_package(remage REQUIRED) +endif() add_executable(06-NeutronCapture main.cc HPGeTestStand.hh HPGeTestStand.cc IsotopeOutputScheme.cc IsotopeOutputScheme.hh) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4bb0cf0e..a358fbc5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,2 +1,6 @@ add_subdirectory(01-gdml) add_subdirectory(02-hpge) +add_subdirectory(03-optics) +add_subdirectory(04-cosmogenics) +add_subdirectory(05-MUSUN) +add_subdirectory(06-NeutronCapture) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d7c717f9..fd807b38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,6 +94,11 @@ endif() add_library(remage SHARED ${PROJECT_PUBLIC_HEADERS} ${PROJECT_SOURCES}) +if(RMG_BUILD_EXAMPLES) + # add an alias to support building examples both stand-alone as well as a part of the main project. + add_library(RMG::remage ALIAS remage) +endif() + # Ensure clients are aware of the minimum C++ standard we were compiled with target_compile_features(remage PUBLIC cxx_std_${CMAKE_CXX_STANDARD})