Skip to content

Commit

Permalink
Merge pull request #537 from wdeconinck/production_DE_fixup
Browse files Browse the repository at this point in the history
Make async_threads_module and fesom_C an OBJECT library
  • Loading branch information
suvarchal authored Dec 4, 2023
2 parents fad6269 + d9767cf commit fc90da7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ add_subdirectory(../lib/parms ${PROJECT_BINARY_DIR}/parms)

add_subdirectory(async_threads_cpp)

add_library(${PROJECT_NAME}_C ${sources_C})
add_library(${PROJECT_NAME}_C OBJECT ${sources_C})
target_compile_definitions(${PROJECT_NAME}_C PRIVATE PARMS USE_MPI REAL=double DBL HAS_BLAS FORTRAN_UNDERSCORE VOID_POINTER_SIZE_8 SGI LINUX UNDER_ MPI2)

target_link_libraries(${PROJECT_NAME}_C PRIVATE parms) #metis
target_link_libraries(${PROJECT_NAME}_C PRIVATE MPI::MPI_C)


# fesom library
add_library(${PROJECT_NAME} ${sources_Fortran})
add_library(${PROJECT_NAME} ${sources_Fortran} $<TARGET_OBJECTS:fesom_C> $<TARGET_OBJECTS:async_threads_cpp>)
add_dependencies(${PROJECT_NAME} fesom_version_info-generated.F90)
target_compile_definitions(${PROJECT_NAME} PRIVATE PARMS -DMETIS_VERSION=5 -DPART_WEIGHTED -DMETISRANDOMSEED=35243)

Expand All @@ -179,7 +179,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE parms) #metis
target_link_libraries(${PROJECT_NAME} PRIVATE MPI::MPI_Fortran)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_C ${NETCDF_Fortran_LIBRARIES} ${NETCDF_C_LIBRARIES} ${OASIS_Fortran_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${MCT_Fortran_LIBRARIES} ${MPEU_Fortran_LIBRARIES} ${SCRIP_Fortran_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE async_threads_cpp)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE Fortran)
if(ENABLE_OPENMP AND NOT ${CMAKE_Fortran_COMPILER_ID} STREQUAL Cray)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenMP::OpenMP_Fortran)
Expand Down Expand Up @@ -269,4 +268,4 @@ target_link_libraries(${PROJECT_NAME}.x PUBLIC ${PROJECT_NAME})

### Export and installation

fesom_export(TARGETS ${PROJECT_NAME}_C ${PROJECT_NAME} parms async_threads_cpp fesom.x)
fesom_export(TARGETS ${PROJECT_NAME} parms fesom.x)
20 changes: 5 additions & 15 deletions src/async_threads_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
cmake_minimum_required(VERSION 3.4)
cmake_minimum_required(VERSION 3.16)

project(async_threads_cpp CXX C Fortran) # the FortranCInterface requires the C language to be enabled

set (CMAKE_CXX_STANDARD 11)

# get our source files
file(GLOB sources_CXX ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
file(GLOB sources ${CMAKE_CURRENT_LIST_DIR}/*.cpp)

include(FortranCInterface)
FortranCInterface_HEADER(ThreadsManagerFCMacros.h MACRO_NAMESPACE "ThreadsManagerFCMacros_" SYMBOLS init_ccall begin_ccall end_ccall)

add_library(${PROJECT_NAME} ${sources_CXX})

add_library(${PROJECT_NAME} OBJECT ${sources})
target_include_directories(${PROJECT_NAME}
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
PUBLIC $<BUILD_INTERFACE:${CMAKE_Fortran_MODULE_DIRECTORY}>
)

if(${CMAKE_CXX_COMPILER_ID} STREQUAL Cray )
target_compile_options(${PROJECT_NAME} PRIVATE -hstd=c++11)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++11)
endif()
if(${BUILD_FESOM_AS_LIBRARY})
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
install(TARGETS ${PROJECT_NAME} DESTINATION "${FESOM_INSTALL_PREFIX}/lib")
endif()
3 changes: 2 additions & 1 deletion src/async_threads_module.F90
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define __FILENAME__ "async_threads_module.F90"
module async_threads_module
implicit none
public thread_type
Expand Down Expand Up @@ -110,7 +111,7 @@ subroutine assert(val, line)
integer, intent(in) :: line
! EO args
if(.NOT. val) then
print *, "error in line ",line, __FILE__
print *, "error in line ",line, __FILENAME__
stop 1
end if
end subroutine
Expand Down
9 changes: 9 additions & 0 deletions src/fesom-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ if(NOT @PROJECT_NAME@_BINARY_DIR)
endif()

include(CMakeFindDependencyMacro)

if( NOT (TARGET MPI::MPI_C AND TARGET MPI::MPI_Fortran) )
enable_language(C)
enable_language(Fortran)
find_dependency(MPI COMPONENTS C Fortran)
endif()

if( @ENABLE_OPENMP@ )
if( NOT TARGET OpenMP::OpenMP_Fortran )
enable_language(Fortran)
Expand All @@ -34,3 +36,10 @@ if( @ENABLE_IFS_INTERFACE@ )
else()
set( fesom_HAVE_IFS_INTERFACE 0 )
endif()

if( @ENABLE_MULTIO@ )
find_dependency( multio HINTS ${CMAKE_CURRENT_LIST_DIR}/../multio @multio_DIR@ )
set( fesom_HAVE_MULTIO 1 )
else()
set( fesom_HAVE_MULTIO 0 )
endif()
1 change: 1 addition & 0 deletions test_downstream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ message("fesom found: ${fesom_DIR}")
message("fesom_VERSION: ${fesom_VERSION}")
message("fesom_HAVE_OPENMP: ${fesom_HAVE_OPENMP}")
message("fesom_HAVE_IFS_INTERFACE: ${fesom_HAVE_IFS_INTERFACE}")
message("fesom_HAVE_MULTIO: ${fesom_HAVE_MULTIO}")

if(NOT TARGET fesom)
message(FATAL_ERROR "fesom was installed wrongly: fesom target not found")
Expand Down

0 comments on commit fc90da7

Please sign in to comment.