Skip to content

Commit

Permalink
make ginkgo be the major library
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed May 29, 2024
1 parent 7f726ff commit 50abb16
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
3 changes: 0 additions & 3 deletions cmake/create_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ function(ginkgo_set_test_target_properties test_target_name test_library_suffix)
set_target_properties(${test_target_name} PROPERTIES CUDA_STANDARD 14)
target_include_directories(${test_target_name} PRIVATE ${Ginkgo_BINARY_DIR} ${set_properties_ADDITIONAL_INCLUDES})
target_link_libraries(${test_target_name} PRIVATE ginkgo GTest::GTest ${set_properties_ADDITIONAL_LIBRARIES})
if(MSVC AND BUILD_SHARED_LIBS)
target_link_libraries(${test_target_name} PRIVATE ginkgo_config)
endif()
endfunction()

function(ginkgo_add_resource_requirement test_name)
Expand Down
59 changes: 34 additions & 25 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
add_subdirectory(device_hooks) # placeholders for disabled modules

add_library(ginkgo "")
set(config_source
config/factorization_config.cpp
config/multigrid_config.cpp
config/preconditioner_config.cpp
config/registry.cpp
config/solver_config.cpp
)
target_sources(ginkgo
# MSVC: To solve LNK1189, we separate the library as a workaround
# To make ginkgo still be the major library, we make the original to ginkgo_core in MSVC/shared
# TODO: should think another way to solve it like dllexport or def file
set(ginkgo_core "ginkgo")
if(MSVC AND BUILD_SHARED_LIBS)
set(ginkgo_core "ginkgo_core")
endif()

add_library(${ginkgo_core} "")
target_sources(${ginkgo_core}
PRIVATE
base/array.cpp
base/batch_multi_vector.cpp
Expand Down Expand Up @@ -110,15 +118,15 @@ target_sources(ginkgo
)

if(GINKGO_HAVE_PAPI_SDE)
target_sources(ginkgo PRIVATE log/papi.cpp)
target_sources(${ginkgo_core} PRIVATE log/papi.cpp)
endif()

if(GINKGO_HAVE_METIS)
target_sources(ginkgo PRIVATE reorder/nested_dissection.cpp)
target_sources(${ginkgo_core} PRIVATE reorder/nested_dissection.cpp)
endif()

if(GINKGO_BUILD_MPI)
target_sources(ginkgo
target_sources(${ginkgo_core}
PRIVATE
mpi/exception.cpp
distributed/matrix.cpp
Expand All @@ -127,54 +135,55 @@ if(GINKGO_BUILD_MPI)
distributed/preconditioner/schwarz.cpp)
endif()

# MSVC/shared: make ginkgo be the major library
if(MSVC AND BUILD_SHARED_LIBS)
add_library(ginkgo_config "")
target_sources(ginkgo_config PRIVATE ${config_source})
ginkgo_compile_features(ginkgo_config)
ginkgo_default_includes(ginkgo_config)
ginkgo_install_library(ginkgo_config)
add_library(ginkgo "")
target_sources(ginkgo PRIVATE ${config_source})
ginkgo_compile_features(ginkgo)
ginkgo_default_includes(ginkgo)
ginkgo_install_library(ginkgo)
if(GINKGO_CHECK_CIRCULAR_DEPS)
ginkgo_check_headers(ginkgo_config "")
ginkgo_check_headers(ginkgo "")
endif()
else()
target_sources(ginkgo PRIVATE ${config_source})
target_sources(${ginkgo_core} PRIVATE ${config_source})
endif()

ginkgo_compile_features(ginkgo)
ginkgo_compile_features(${ginkgo_core})

# add a namespace alias so Ginkgo can always be included as Ginkgo::ginkgo
# regardless of whether it is installed or added as a subdirectory
add_library(Ginkgo::ginkgo ALIAS ginkgo)
target_link_libraries(ginkgo
PUBLIC ginkgo_device ginkgo_omp ginkgo_cuda ginkgo_reference ginkgo_hip ginkgo_dpcpp)
if(MSVC AND BUILD_SHARED_LIBS)
target_link_libraries(ginkgo_config PUBLIC ginkgo)
target_link_libraries(ginkgo PUBLIC ${ginkgo_core})
endif()
target_link_libraries(ginkgo
PUBLIC ginkgo_device ginkgo_omp ginkgo_cuda ginkgo_reference ginkgo_hip ginkgo_dpcpp)
if(GINKGO_HAVE_PAPI_SDE)
target_link_libraries(ginkgo PUBLIC PAPI::PAPI_SDE)
target_link_libraries(${ginkgo_core} PUBLIC PAPI::PAPI_SDE)
endif()

if(GINKGO_HAVE_TAU)
target_link_libraries(ginkgo PRIVATE perfstubs)
target_link_libraries(${ginkgo_core} PRIVATE perfstubs)
endif()

if(GINKGO_HAVE_VTUNE)
target_link_libraries(ginkgo PRIVATE VTune::ITT)
target_link_libraries(${ginkgo_core} PRIVATE VTune::ITT)
endif()

if(GINKGO_HAVE_METIS)
target_link_libraries(ginkgo PRIVATE METIS::METIS)
target_link_libraries(${ginkgo_core} PRIVATE METIS::METIS)
endif()

if(GINKGO_BUILD_MPI)
target_link_libraries(ginkgo PUBLIC MPI::MPI_CXX)
target_link_libraries(${ginkgo_core} PUBLIC MPI::MPI_CXX)
endif()

ginkgo_default_includes(ginkgo)
ginkgo_install_library(ginkgo)
ginkgo_default_includes(${ginkgo_core})
ginkgo_install_library(${ginkgo_core})

if(GINKGO_CHECK_CIRCULAR_DEPS)
ginkgo_check_headers(ginkgo "")
ginkgo_check_headers(${ginkgo_core} "")
endif()

if(GINKGO_BUILD_TESTS)
Expand All @@ -183,7 +192,7 @@ endif()

if(GINKGO_DEVEL_TOOLS AND CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BUILD_SHARED_LIBS)
# Copy pretty-printer next to library
add_custom_command(TARGET ginkgo POST_BUILD
add_custom_command(TARGET ${ginkgo_core} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"${Ginkgo_SOURCE_DIR}/dev_tools/scripts/gdb-ginkgo.py"
"$<TARGET_FILE:ginkgo>-gdb.py"
Expand Down

0 comments on commit 50abb16

Please sign in to comment.