bench6/cmake/FindNodes.cmake

67 lines
2.0 KiB
CMake
Raw Permalink Normal View History

2023-09-12 16:12:01 +02:00
# Copyright (c) 2022-2023 Barcelona Supercomputing Center (BSC)
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Searchs for libnodes and checks if the -fompss-2=libnodes flag is supported in
# the compiler.
#
# Sets the variable NODES_FOUND when libnodes is found and NODES_FLAG_SUPPORTED
# when the -fompss-2=libnodes flag is supported.
#
# The target Nodes::nodes is defined when both checks are passed, and includes a
# rule to add the compile and link time flags.
2023-05-19 10:00:54 +02:00
include(GNUInstallDirs)
2024-04-15 15:26:56 +02:00
include(FeatureSummary)
2023-05-19 10:00:54 +02:00
2024-04-15 15:26:56 +02:00
set(NODES_FLAG "-fompss-2=libnodes")
set(can_search_nodes TRUE)
if(NOT DEFINED ENV{NODES_HOME})
message(STATUS "NODES_HOME not set, refusing to search Nodes")
set(can_search_nodes FALSE)
endif()
2024-04-15 15:26:56 +02:00
if(NOT DEFINED ENV{NOSV_HOME})
message(STATUS "NOSV_HOME not set, refusing to search Nodes")
set(can_search_nodes FALSE)
endif()
2023-05-19 10:00:54 +02:00
2024-04-15 15:26:56 +02:00
if(can_search_nodes)
set(NODES_HOME "$ENV{NODES_HOME}")
2023-05-19 10:00:54 +02:00
2024-04-15 15:26:56 +02:00
# Ensure the compiler supports libnodes
include(CheckCCompilerFlag)
2023-05-19 10:00:54 +02:00
2024-04-15 15:26:56 +02:00
# Also set the linker flags, as otherwise the check will fail due to undefined
# symbols in the final program.
set(CMAKE_REQUIRED_LINK_OPTIONS "${NODES_FLAG}")
check_c_compiler_flag("${NODES_FLAG}" NODES_FLAG_SUPPORTED)
if(NOT NODES_FLAG_SUPPORTED)
message(STATUS "Compiler doesn't support ${NODES_FLAG} flag")
endif()
find_library(NODES_LIBRARY NAMES nodes PATHS "${NODES_HOME}/lib" NO_DEFAULT_PATH)
find_path(NODES_INCLUDE_DIR nodes.h PATHS "${NODES_HOME}/include" NO_DEFAULT_PATH)
2023-09-12 16:12:01 +02:00
endif()
2024-04-15 15:26:56 +02:00
include(FindPackageHandleStandardArgs)
2023-09-12 16:12:01 +02:00
2024-04-15 15:26:56 +02:00
find_package_handle_standard_args(Nodes DEFAULT_MSG
NODES_HOME NODES_LIBRARY NODES_INCLUDE_DIR NODES_FLAG_SUPPORTED)
2023-09-12 16:12:01 +02:00
2024-04-15 15:26:56 +02:00
if(NOT NODES_FOUND)
message(STATUS "Cannot find NODES library")
2023-05-19 10:00:54 +02:00
return()
endif()
if(NOT TARGET Nodes::nodes)
add_library(Nodes::nodes SHARED IMPORTED)
set_target_properties(Nodes::nodes PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${NODES_INCLUDE_DIR}"
IMPORTED_LOCATION ${NODES_LIBRARY})
2023-09-12 16:12:01 +02:00
target_compile_options(Nodes::nodes INTERFACE "${NODES_FLAG}")
target_link_options(Nodes::nodes INTERFACE "${NODES_FLAG}")
2023-05-19 10:00:54 +02:00
endif()