Skip to content

Commit

Permalink
Support for shared Fortran library (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck authored and havogt committed Jan 29, 2019
1 parent aef839c commit d03231b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ find_package(Threads REQUIRED)
# Set script directory
set(SCRIPT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)

# If we build the C Interface we require shared libraries
if(SERIALBOX_ENABLE_C AND NOT(SERIALBOX_BUILD_SHARED))
message(STATUS "SERIALBOX_ENABLE_C requires shared libraries, setting SERIALBOX_BUILD_SHARED=ON")
set(SERIALBOX_BUILD_SHARED ON)
endif()

# If we build the Fortran Interface, we need a Fortran compiler
if(SERIALBOX_ENABLE_FORTRAN)
enable_language(Fortran)
Expand Down Expand Up @@ -260,7 +254,7 @@ if(SERIALBOX_ENABLE_EXPERIMENTAL_FILESYSTEM)
if( STD_FILESYSTEM_LIB_CHECK )
message(STATUS "Using std::experimental::filesystem (no dependency on compiled boost libs)")
add_library(SerialboxFilesytemTarget INTERFACE)
target_link_libraries(SerialboxFilesytemTarget INTERFACE stdc++fs)
target_link_libraries(SerialboxFilesytemTarget INTERFACE ${STD_FILESYSTEM_LIB_CHECK})
set(SERIALBOX_FILESYSTEM_LIBRARY_STRING "SERIALBOX_USE_STD_EXPERIMENTAL_FILESYSTEM")
set(_use_boost_filesystem OFF)
else()
Expand Down
11 changes: 9 additions & 2 deletions cmake/SerialboxConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,23 @@ endif(SERIALBOX_HAS_C)
if(SERIALBOX_HAS_FORTRAN)
get_property(_static_lib TARGET Serialbox::SerialboxFortranStatic PROPERTY LOCATION)
message(STATUS " Static serialbox FORTRAN: ${_static_lib}")

if(SERIALBOX_HAS_SHARED_LIBRARY)
get_property(_shared_lib TARGET Serialbox::SerialboxFortranShared PROPERTY LOCATION)
message(STATUS " Shared serialbox FORTRAN: ${_shared_lib}")
endif()

endif(SERIALBOX_HAS_FORTRAN)

#===---------------------------------------------------------------------------------------------===
# Find external libraries
#====--------------------------------------------------------------------------------------------===
if(NOT(DEFINED SERIALBOX_NO_EXTERNAL_LIBS))

include(CMakeFindDependencyMacro)
#
# Pthreads
#
message( STATUS "Serialbox: find_depencency( Threads )" )
find_dependency(Threads)

#
Expand All @@ -111,7 +117,8 @@ if(NOT(DEFINED SERIALBOX_NO_EXTERNAL_LIBS))
set(BOOST_INCLUDEDIR "${SERIALBOX_BOOST_INCLUDE_DIRS}")
set(Boost_NO_SYSTEM_PATHS "ON") # Force boost to search locations specified above

find_package(Boost
message( STATUS "Serialbox: find_depencency( Boost ${SERIALBOX_BOOST_VERSION} EXACT COMPONENTS ${SERIALBOX_REQUIRED_BOOST_COMPONENTS}}")
find_dependency(Boost
${SERIALBOX_BOOST_VERSION} EXACT COMPONENTS ${SERIALBOX_REQUIRED_BOOST_COMPONENTS})
if(Boost_FOUND)
list(APPEND SERIALBOX_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
Expand Down
16 changes: 16 additions & 0 deletions src/serialbox-fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ if(SERIALBOX_ENABLE_FORTRAN)
ARCHIVE DESTINATION lib
)

if(BUILD_SHARED_LIBS)
set_target_properties( SerialboxFortranSerializeObjects PROPERTIES POSITION_INDEPENDENT_CODE ON )
set_target_properties( SerialboxFortranObjects PROPERTIES POSITION_INDEPENDENT_CODE ON )
add_library(SerialboxFortranShared SHARED $<TARGET_OBJECTS:SerialboxFortranSerializeObjects> $<TARGET_OBJECTS:SerialboxFortranObjects>)
target_link_libraries(SerialboxFortranShared PUBLIC SerialboxFortranObjects)
target_link_libraries(SerialboxFortranShared PUBLIC SerialboxFortranSerializeObjects)
target_link_libraries(SerialboxFortranShared PUBLIC SerialboxCShared)
set_target_properties(SerialboxFortranShared PROPERTIES VERSION ${Serialbox_VERSION_STRING})

install(TARGETS SerialboxFortranShared
EXPORT SerialboxTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()

# Install mod files
foreach(source ${SOURCES_FORTRAN} ${SOURCES_FORTRAN_SERIALIZE})
get_filename_component(module_name ${source} NAME_WE)
Expand Down

0 comments on commit d03231b

Please sign in to comment.