Commit 90293603 by Victor Costan Committed by Dominic Hamon

CMake: Fallback from try_run to try_compile when cross-compiling. (#436)

parent 3347a20e
...@@ -26,11 +26,28 @@ function(cxx_feature_check FILE) ...@@ -26,11 +26,28 @@ function(cxx_feature_check FILE)
add_definitions(-DHAVE_${VAR}) add_definitions(-DHAVE_${VAR})
return() return()
endif() endif()
message("-- Performing Test ${FEATURE}") message("-- Performing Test ${FEATURE}")
try_run(RUN_${FEATURE} COMPILE_${FEATURE} if(CMAKE_CROSSCOMPILING)
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp try_compile(COMPILE_${FEATURE}
CMAKE_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp
LINK_LIBRARIES ${BENCHMARK_CXX_LIBRARIES}) CMAKE_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS}
LINK_LIBRARIES ${BENCHMARK_CXX_LIBRARIES})
if(COMPILE_${FEATURE})
message(WARNING
"If you see build failures due to cross compilation, try setting HAVE_${VAR} to 0")
set(RUN_${FEATURE} 0)
else()
set(RUN_${FEATURE} 1)
endif()
else()
message("-- Performing Test ${FEATURE}")
try_run(RUN_${FEATURE} COMPILE_${FEATURE}
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp
CMAKE_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS}
LINK_LIBRARIES ${BENCHMARK_CXX_LIBRARIES})
endif()
if(RUN_${FEATURE} EQUAL 0) if(RUN_${FEATURE} EQUAL 0)
message("-- Performing Test ${FEATURE} -- success") message("-- Performing Test ${FEATURE} -- success")
set(HAVE_${VAR} 1 CACHE INTERNAL "Feature test for ${FILE}" PARENT_SCOPE) set(HAVE_${VAR} 1 CACHE INTERNAL "Feature test for ${FILE}" PARENT_SCOPE)
...@@ -43,4 +60,3 @@ function(cxx_feature_check FILE) ...@@ -43,4 +60,3 @@ function(cxx_feature_check FILE)
endif() endif()
endif() endif()
endfunction() endfunction()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment