Skip to content

Commit 544ac87

Browse files
authored
Merge pull request #1 from DanShort12/find_openmc_in_cmake
Update OpenMC paths
2 parents ea4e522 + 4fd6115 commit 544ac87

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

CMakeLists.txt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ set(CMAKE_CXX_FLAGS "-Wall")
1313
set(CMAKE_CXX_FLAGS_DEBUG "-g")
1414
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
1515

16-
# Use output paths from OpenMC install - change if needed
17-
set(OPENMC_DIR /opt/openmc)
18-
set(OPENMC_INC_DIR ${OPENMC_DIR}/include)
19-
set(OPENMC_LIB_DIR ${OPENMC_DIR}/lib)
20-
2116
# Ensure submodules are available and up to date
2217
find_package(Git QUIET)
2318
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
@@ -44,16 +39,29 @@ list(APPEND source_sampling_SOURCES
4439
${SRC_DIR}/plasma_source.cpp
4540
)
4641

47-
add_library(source_sampling SHARED ${source_sampling_SOURCES})
42+
# Use output paths from OpenMC install
43+
# If OpenMC isn't available then we won't be able to build the plugin
44+
# However, the package can still be run by using the sampling methods directly
45+
# So don't terminate the build
46+
find_package(OpenMC QUIET)
47+
48+
if(OpenMC_FOUND)
49+
# Build the source_sampling OpenMC plugin if OpenMC is available
50+
set(OPENMC_INC_DIR ${OpenMC_DIR}/../../../include/openmc)
51+
set(OPENMC_LIB_DIR ${OpenMC_DIR}/../../../lib)
4852

49-
find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR} OPTIONAL)
53+
add_library(source_sampling SHARED ${source_sampling_SOURCES})
5054

51-
if (OPENMC_LIB)
52-
set_target_properties(source_sampling PROPERTIES PREFIX "")
53-
set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON)
54-
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR})
55-
target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml)
56-
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran)
55+
find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR} OPTIONAL)
56+
57+
if (OPENMC_LIB)
58+
set_target_properties(source_sampling PROPERTIES PREFIX "")
59+
set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON)
60+
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR})
61+
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran)
62+
endif()
63+
else()
64+
message(WARNING "Unable to find OpenMC installation - the source_sampling plugin will not be built.")
5765
endif()
5866

5967
# Build plasma_source Python bindings

0 commit comments

Comments
 (0)