Skip to content

Commit

Permalink
print MPI::MPI_Fortran target props
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Dec 20, 2023
1 parent 24fb5c1 commit 25624bc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ LANGUAGES C Fortran

enable_testing()

message(STATUS "CMake ${CMAKE_VERSION} Generator ${CMAKE_GENERATOR}")
message(STATUS "CMake ${CMAKE_VERSION} Generator ${CMAKE_GENERATOR} Build type ${CMAKE_BUILD_TYPE}")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)

# this has checks that can be reused in other projects as well
include(cmake/mpi.cmake)

include(cmake/print_target_props.cmake)
print_target_props(MPI::MPI_Fortran)

include(cmake/compilers.cmake)

add_subdirectory(test)
Expand Down
2 changes: 2 additions & 0 deletions cmake/mpi.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
include(CheckSourceCompiles)

set(MPI_DETERMINE_LIBRARY_VERSION true)

find_package(MPI REQUIRED COMPONENTS C Fortran)

message(STATUS "MPI Library Version: ${MPI_C_LIBRARY_VERSION_STRING}")

# Cray FindMPI.cmake has a bug where the plain CMake variables aren't defined, only imported target is
Expand Down
28 changes: 28 additions & 0 deletions cmake/print_target_props.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
execute_process(COMMAND ${CMAKE_COMMAND} --help-property-list
OUTPUT_VARIABLE _props OUTPUT_STRIP_TRAILING_WHITESPACE
)

STRING(REGEX REPLACE "\n" ";" _props "${_props}")

list(REMOVE_DUPLICATES _props)

function(print_target_props tgt)
if(NOT TARGET ${tgt})
message(WARNING "Target ${tgt} not found")
return()
endif()

message(STATUS "Target: ${tgt} properties")
foreach(p IN LISTS _props)
if(p MATCHES "<CONFIG>" AND NOT CMAKE_BUILD_TYPE)
continue()
endif()

string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" p "${p}")

get_property(v TARGET ${tgt} PROPERTY "${p}")
if(v)
message(STATUS "${tgt} ${p} = ${v}")
endif()
endforeach()
endfunction()

0 comments on commit 25624bc

Please sign in to comment.