From e4897a78b9a325537117a57243c65d82774694fc Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 21 Oct 2009 13:01:17 -0400 Subject: Test OSX_ARCHITECTURES target property We test the property with a project that fails to link due to an architecture mismatch between an executable and a static library. See issue #8725. --- Tests/Architecture/CMakeLists.txt | 21 +++++++++++++++++++++ Tests/Architecture/bar.c | 2 ++ Tests/Architecture/foo.c | 1 + Tests/CMakeLists.txt | 12 ++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Tests/Architecture/CMakeLists.txt create mode 100644 Tests/Architecture/bar.c create mode 100644 Tests/Architecture/foo.c diff --git a/Tests/Architecture/CMakeLists.txt b/Tests/Architecture/CMakeLists.txt new file mode 100644 index 0000000..bc767fe --- /dev/null +++ b/Tests/Architecture/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.8) +project(Architecture C) + +add_library(foo foo.c) +if(CMAKE_OSX_ARCHITECTURES) + get_property(archs TARGET foo PROPERTY OSX_ARCHITECTURES) + if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "${archs}") + message(FATAL_ERROR + "OSX_ARCHITECTURES property not initialized by CMAKE_OSX_ARCHITECTURES.\n" + "Expected [${CMAKE_OSX_ARCHITECTURES}], got [${archs}]." + ) + endif() +endif() +set_property(TARGET foo PROPERTY OSX_ARCHITECTURES i386) +set_property(TARGET foo PROPERTY OSX_ARCHITECTURES_DEBUG ppc) + +add_executable(bar bar.c) +target_link_libraries(bar foo) +set_property(TARGET bar PROPERTY OUTPUT_NAME Architecture) +set_property(TARGET bar PROPERTY OSX_ARCHITECTURES ppc) +set_property(TARGET bar PROPERTY OSX_ARCHITECTURES_DEBUG i386) diff --git a/Tests/Architecture/bar.c b/Tests/Architecture/bar.c new file mode 100644 index 0000000..923c89c --- /dev/null +++ b/Tests/Architecture/bar.c @@ -0,0 +1,2 @@ +extern int foo(void); +int main() { return foo(); } diff --git a/Tests/Architecture/foo.c b/Tests/Architecture/foo.c new file mode 100644 index 0000000..e35694b --- /dev/null +++ b/Tests/Architecture/foo.c @@ -0,0 +1 @@ +int foo(void) { return 0; } diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 6389325..ea28029 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -77,7 +77,8 @@ IF(BUILD_TESTING) "Should the tests that use '--build-target package' be run?" ON) MARK_AS_ADVANCED(CTEST_TEST_CPACK) - IF(APPLE AND CTEST_TEST_CPACK) + SET(CTEST_TEST_OSX_ARCH 0) + IF(APPLE) EXECUTE_PROCESS( COMMAND sw_vers -productVersion OUTPUT_VARIABLE OSX_VERSION @@ -87,8 +88,10 @@ IF(BUILD_TESTING) MESSAGE(STATUS "Forcing CTEST_TEST_CPACK=OFF on OSX < 10.4") MESSAGE(STATUS "OSX_VERSION='${OSX_VERSION}'") SET(CTEST_TEST_CPACK OFF) + ELSE(OSX_VERSION MATCHES "^10\\.[0123]" OR OSX_VERSION MATCHES "ProductVersion:\t10\\.[0123]") + SET(CTEST_TEST_OSX_ARCH 1) ENDIF(OSX_VERSION MATCHES "^10\\.[0123]" OR OSX_VERSION MATCHES "ProductVersion:\t10\\.[0123]") - ENDIF(APPLE AND CTEST_TEST_CPACK) + ENDIF(APPLE) # Use 1500 or CTEST_TEST_TIMEOUT for long test timeout value, # whichever is greater. @@ -133,6 +136,11 @@ IF(BUILD_TESTING) IF("${CMAKE_TEST_GENERATOR}" MATCHES "Make") ADD_TEST_MACRO(Policy0002 Policy0002) ENDIF("${CMAKE_TEST_GENERATOR}" MATCHES "Make") + IF(CTEST_TEST_OSX_ARCH) + ADD_TEST_MACRO(Architecture Architecture) + SET_TESTS_PROPERTIES(Architecture PROPERTIES + PASS_REGULAR_EXPRESSION "(file is not of required architecture|does not match cputype)") + ENDIF(CTEST_TEST_OSX_ARCH) SET(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/COnly") SET(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/CMakeBuildCOnly") -- cgit v0.12