Set libopenmc as static library in CMake for MSVC: Built openmc.exe

successfully with visual studio
This commit is contained in:
jingang 2019-06-06 10:46:01 -04:00
parent e5b108be7a
commit 950c684e6c

View file

@ -159,7 +159,7 @@ target_compile_options(faddeeva PRIVATE ${cxxflags})
# libopenmc
#===============================================================================
add_library(libopenmc SHARED
list(APPEND libopenmc_SOURCES
src/bank.cpp
src/bremsstrahlung.cpp
src/dagmc.cpp
@ -246,6 +246,18 @@ add_library(libopenmc SHARED
src/xml_interface.cpp
src/xsdata.cpp)
# For Visual Studio compilers
if(MSVC)
# Use static library (otherwise explicit symbol portings are needed)
add_library(libopenmc STATIC ${libopenmc_SOURCES})
# To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB
# compile definition must be specified.
target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB)
else()
add_library(libopenmc SHARED ${libopenmc_SOURCES})
endif()
set_target_properties(libopenmc PROPERTIES
OUTPUT_NAME openmc)
@ -272,12 +284,6 @@ if(GIT_SHA1_SUCCESS EQUAL 0)
target_compile_definitions(libopenmc PRIVATE -DGIT_SHA1="${GIT_SHA1}")
endif()
# To use the shared HDF5 libraries on Windows with Visual Studio,
# the H5_BUILT_AS_DYNAMIC_LIB compile definition must be specified.
if(MSVC)
target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB)
endif()
# target_link_libraries treats any arguments starting with - but not -l as
# linker flags. Thus, we can pass both linker flags and libraries together.
target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}