Skip to content

Commit

Permalink
Enable cross-platform portability test
Browse files Browse the repository at this point in the history
CMake fix 32-bit executable with generator Win64
  • Loading branch information
tusharpm committed Jan 26, 2017
1 parent 0a908bc commit df44243
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
28 changes: 21 additions & 7 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=$<TARGET_FILE_DIR:portability_test64>
-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
Expand Down
16 changes: 16 additions & 0 deletions unittests/run_portability_test.cmake
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 0 additions & 9 deletions unittests/run_portability_test.sh

This file was deleted.

0 comments on commit df44243

Please sign in to comment.