Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend blt_check_code_compiles macro to handle dependencies #639

1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Expand Up @@ -17,6 +17,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/

### Added
- Added `blt_print_variables` macro to print variables in current scope, with regex filtering on variable names and values
- Added `LINK_LIBRARIES` optional parameter to `blt_check_code_compiles` macro to allow for checking if a feature is available in a third-party library.
- Added `CONFIGURATIONS` and `OMP_NUM_THREADS` options to `blt_add_benchmark`

### Fixed
Expand Down
16 changes: 14 additions & 2 deletions cmake/BLTMacros.cmake
Expand Up @@ -1557,6 +1557,7 @@ endmacro()
##------------------------------------------------------------------------------
## blt_check_code_compiles(CODE_COMPILES <variable>
## VERBOSE_OUTPUT <ON|OFF (default OFF)>
## LINK_LIBRARIES <libs>
white238 marked this conversation as resolved.
Show resolved Hide resolved
## SOURCE_STRING <quoted C++ program>)
##
## This macro checks if a snippet of C++ code compiles.
Expand All @@ -1570,13 +1571,15 @@ endmacro()
## CODE_COMPILES A boolean variable the contains the compilation result.
##
## VERBOSE_OUTPUT Optional parameter to output debug information (Default: off)
##
## LINK_LIBRARIES Optional parameter for a list of additional dependencies
##------------------------------------------------------------------------------
macro(blt_check_code_compiles)

set(options)
set(singleValueArgs CODE_COMPILES VERBOSE_OUTPUT )
# NOTE: SOURCE_STRING must be a multiValueArg otherwise CMake removes all semi-colons
set(multiValueArgs SOURCE_STRING)
set(multiValueArgs LINK_LIBRARIES SOURCE_STRING)

# Parse the arguments to the macro
cmake_parse_arguments(arg
Expand All @@ -1603,11 +1606,20 @@ macro(blt_check_code_compiles)
string(RANDOM LENGTH 5 _rand)
set(_fname ${CMAKE_CURRENT_BINARY_DIR}/_bltCheckCompiles${_rand}.cpp)
file(WRITE ${_fname} "${arg_SOURCE_STRING}")
try_compile(${arg_CODE_COMPILES}
if(NOT DEFINED arg_LINK_LIBRARIES)
try_compile(${arg_CODE_COMPILES}
${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp
SOURCES ${_fname}
CXX_STANDARD ${CMAKE_CXX_STANDARD}
OUTPUT_VARIABLE _res)
else()
try_compile(${arg_CODE_COMPILES}
${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp
SOURCES ${_fname}
CXX_STANDARD ${CMAKE_CXX_STANDARD}
LINK_LIBRARIES ${arg_LINK_LIBRARIES}
OUTPUT_VARIABLE _res)
endif()
file(REMOVE ${_fname})

if(${arg_VERBOSE_OUTPUT})
Expand Down
43 changes: 0 additions & 43 deletions host-configs/llnl/toss_4_x86_64_ib_cray/rocm@4.5.2_hip.cmake

This file was deleted.

26 changes: 26 additions & 0 deletions tests/internal/unit/CMakeLists.txt
Expand Up @@ -173,3 +173,29 @@ if(_hello_world_compiled)
else()
message(FATAL_ERROR "... failed to compile.")
endif()

if(ENABLE_HIP)
message(STATUS "Checking blt::hip_runtime in blt_check_code_compiles")
blt_check_code_compiles(CODE_COMPILES _hello_world_with_libs_compiled
VERBOSE_OUTPUT ON
LINK_LIRBRARIES blt::hip_runtime
SOURCE_STRING
[=[
#include <iostream>
#include "hip/hip_runtime.h"

int main(int, char**)
{

std::cout << "Hello World!" << std::endl;

return 0;
}
]=])

if(_hello_world_with_libs_compiled)
message(STATUS "... passed")
else()
message(FATAL_ERROR "... failed to compile.")
endif()
endif()