From 2eab819c98cdf2869d737e289a80e0040740c38a Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:08:25 +0100 Subject: [PATCH 1/2] Update OpenMC paths OpenMC installs into /usr/local but we were looking in /opt/openmc, so change the OpenMC paths to be under /usr/local. Also removes unused pugixml include. --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 412d405..64b45fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,8 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") # Use output paths from OpenMC install - change if needed -set(OPENMC_DIR /opt/openmc) -set(OPENMC_INC_DIR ${OPENMC_DIR}/include) -set(OPENMC_LIB_DIR ${OPENMC_DIR}/lib) +set(OPENMC_INC_DIR /usr/local/include/openmc) +set(OPENMC_LIB_DIR /usr/local/lib) # Ensure submodules are available and up to date find_package(Git QUIET) @@ -52,7 +51,6 @@ if (OPENMC_LIB) set_target_properties(source_sampling PROPERTIES PREFIX "") set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR}) - target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml) target_link_libraries(source_sampling ${OPENMC_LIB} gfortran) endif() From 4fd6115793f84cf8fb9c07501ab8d109e7d84b4a Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 11:41:46 +0000 Subject: [PATCH 2/2] Use find_package for OpenMC Use find_package to populate OpenMC_DIR and then get relative paths to include and lib from there. Raises a warning if OpenMC is not present, as the source can still function but the OpenMC plugin won't be available. --- CMakeLists.txt | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64b45fb..b7edc73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,10 +13,6 @@ set(CMAKE_CXX_FLAGS "-Wall") set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") -# Use output paths from OpenMC install - change if needed -set(OPENMC_INC_DIR /usr/local/include/openmc) -set(OPENMC_LIB_DIR /usr/local/lib) - # Ensure submodules are available and up to date find_package(Git QUIET) if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") @@ -43,15 +39,29 @@ list(APPEND source_sampling_SOURCES ${SRC_DIR}/plasma_source.cpp ) -add_library(source_sampling SHARED ${source_sampling_SOURCES}) +# Use output paths from OpenMC install +# If OpenMC isn't available then we won't be able to build the plugin +# However, the package can still be run by using the sampling methods directly +# So don't terminate the build +find_package(OpenMC QUIET) + +if(OpenMC_FOUND) + # Build the source_sampling OpenMC plugin if OpenMC is available + set(OPENMC_INC_DIR ${OpenMC_DIR}/../../../include/openmc) + set(OPENMC_LIB_DIR ${OpenMC_DIR}/../../../lib) -find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR} OPTIONAL) + add_library(source_sampling SHARED ${source_sampling_SOURCES}) -if (OPENMC_LIB) - set_target_properties(source_sampling PROPERTIES PREFIX "") - set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON) - target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR}) - target_link_libraries(source_sampling ${OPENMC_LIB} gfortran) + find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR} OPTIONAL) + + if (OPENMC_LIB) + set_target_properties(source_sampling PROPERTIES PREFIX "") + set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON) + target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR}) + target_link_libraries(source_sampling ${OPENMC_LIB} gfortran) + endif() +else() + message(WARNING "Unable to find OpenMC installation - the source_sampling plugin will not be built.") endif() # Build plasma_source Python bindings