diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index a5a91ae30..3212fb488 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -3,16 +3,30 @@ file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # A semi-colon separated list of test sources that should not be automatically built with doctest set(SPECIAL_TESTS "portability_test.cpp") -# Build the portability test only if we are on a 64-bit machine (void* is 8 bytes) -if((${CMAKE_SIZEOF_VOID_P} EQUAL 8) AND (NOT SKIP_PORTABILITY_TEST)) - add_executable(portability_test32 portability_test.cpp) - set_target_properties(portability_test32 PROPERTIES COMPILE_FLAGS "-m32") - set_target_properties(portability_test32 PROPERTIES LINK_FLAGS "-m32") +if(CMAKE_VERSION VERSION_LESS 2.8) + # Portability test uses the `TARGET_FILE_DIR` generator expression which is available from CMake 2.8. + set(SKIP_PORTABILITY_TEST ON) +endif() + +if(NOT SKIP_PORTABILITY_TEST) + # Build the portability test only if we are on a 64-bit machine (void* is 8 bytes) + if((${CMAKE_SIZEOF_VOID_P} EQUAL 8)) + if(NOT MSVC) + add_executable(portability_test32 portability_test.cpp) + set_target_properties(portability_test32 PROPERTIES COMPILE_FLAGS "-m32") + set_target_properties(portability_test32 PROPERTIES LINK_FLAGS "-m32") + endif() - add_executable(portability_test64 portability_test.cpp) + add_executable(portability_test64 portability_test.cpp) - add_test(NAME portability_test COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/run_portability_test.sh") + add_test(NAME portability_test + COMMAND ${CMAKE_COMMAND} + -DPORTABILITY_TEST_DIR=$ + -P "${CMAKE_CURRENT_SOURCE_DIR}/run_portability_test.cmake") + elseif(MSVC) + add_executable(portability_test32 portability_test.cpp) + endif() endif() # Build all of the non-special tests diff --git a/unittests/run_portability_test.cmake b/unittests/run_portability_test.cmake new file mode 100644 index 000000000..2841e6c35 --- /dev/null +++ b/unittests/run_portability_test.cmake @@ -0,0 +1,16 @@ +macro(EXEC_CMD_CHECK) + message("running ${ARGN}") + execute_process(COMMAND ${ARGN} RESULT_VARIABLE CMD_RESULT) + if(CMD_RESULT) + message(FATAL_ERROR "Error running ${ARGN}") + endif() +endmacro() + +set(PORTABILITY_TEST_32 "${PORTABILITY_TEST_DIR}/portability_test32") +set(PORTABILITY_TEST_64 "${PORTABILITY_TEST_DIR}/portability_test64") + +exec_cmd_check(${PORTABILITY_TEST_64} save 64) +exec_cmd_check(${PORTABILITY_TEST_32} load 32) +exec_cmd_check(${PORTABILITY_TEST_32} save 32) +exec_cmd_check(${PORTABILITY_TEST_64} load 64) +exec_cmd_check(${PORTABILITY_TEST_64} remove 64) diff --git a/unittests/run_portability_test.sh b/unittests/run_portability_test.sh deleted file mode 100755 index 718440284..000000000 --- a/unittests/run_portability_test.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -set -e - -./portability_test64 save 64 -./portability_test32 load 32 -./portability_test32 save 32 -./portability_test64 load 64 -./portability_test64 remove 64