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 `check_code_compiles` macro to allow for checking if a feature is available in a third-party library.
mcfadden8 marked this conversation as resolved.
Show resolved Hide resolved

### Fixed
- Guard HIP compiler flag ``--rocm-path=/path/to/rocm`` against Crayftn compiler earlier than 15.0.0.
Expand Down
16 changes: 14 additions & 2 deletions cmake/BLTMacros.cmake
Expand Up @@ -1554,6 +1554,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 @@ -1567,13 +1568,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 @@ -1600,11 +1603,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