From f6f03ed4cc4271384ec934fd5867ccbce4e798f2 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Fri, 13 Nov 2015 12:59:18 +0100 Subject: [PATCH] Add test for OSX/iOS Framework directory structure (#15833) --- Tests/RunCMake/CMakeLists.txt | 6 ++++ Tests/RunCMake/Framework/CMakeLists.txt | 3 ++ .../RunCMake/Framework/FrameworkLayout.cmake | 5 +++ .../OSXFrameworkLayout-build-check.cmake | 20 +++++++++++ Tests/RunCMake/Framework/RunCMakeTest.cmake | 33 +++++++++++++++++++ Tests/RunCMake/Framework/foo.c | 1 + .../iOSFrameworkLayout-build-check.cmake | 20 +++++++++++ Tests/RunCMake/Framework/ios.cmake | 25 ++++++++++++++ Tests/RunCMake/Framework/osx.cmake | 18 ++++++++++ 9 files changed, 131 insertions(+) create mode 100644 Tests/RunCMake/Framework/CMakeLists.txt create mode 100644 Tests/RunCMake/Framework/FrameworkLayout.cmake create mode 100644 Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake create mode 100644 Tests/RunCMake/Framework/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/Framework/foo.c create mode 100644 Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake create mode 100644 Tests/RunCMake/Framework/ios.cmake create mode 100644 Tests/RunCMake/Framework/osx.cmake diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 1a0019f5e..a6cbf8660 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -239,6 +239,12 @@ if(XCODE_VERSION AND NOT "${XCODE_VERSION}" VERSION_LESS 3) add_RunCMake_test(XcodeProject -DXCODE_VERSION=${XCODE_VERSION}) endif() +if(NOT XCODE + AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang" + AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0) + add_RunCMake_test(Framework) +endif() + add_RunCMake_test(File_Generate) add_RunCMake_test(ExportWithoutLanguage) add_RunCMake_test(target_link_libraries) diff --git a/Tests/RunCMake/Framework/CMakeLists.txt b/Tests/RunCMake/Framework/CMakeLists.txt new file mode 100644 index 000000000..6dd8cdf55 --- /dev/null +++ b/Tests/RunCMake/Framework/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.4) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/Framework/FrameworkLayout.cmake b/Tests/RunCMake/Framework/FrameworkLayout.cmake new file mode 100644 index 000000000..107afdfe9 --- /dev/null +++ b/Tests/RunCMake/Framework/FrameworkLayout.cmake @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.4) +enable_language(C) + +add_library(Framework SHARED foo.c) +set_target_properties(Framework PROPERTIES FRAMEWORK TRUE) diff --git a/Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake b/Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake new file mode 100644 index 000000000..27d10d8cb --- /dev/null +++ b/Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake @@ -0,0 +1,20 @@ +set(framework-dir "${RunCMake_TEST_BINARY_DIR}/Framework.framework") +set(plist-file "${framework-dir}/Resources/Info.plist") +set(framework-library "${framework-dir}/Framework") +set(framework-versions "${framework-dir}/Versions") + +if(NOT IS_DIRECTORY ${framework-dir}) + message(SEND_ERROR "Framework not found at ${framework-dir}") +endif() + +if(NOT EXISTS ${plist-file}) + message(SEND_ERROR "plist file not found at ${plist-file}") +endif() + +if(NOT EXISTS ${framework-library}) + message(SEND_ERROR "Framework library not found at ${framework-library}") +endif() + +if(NOT EXISTS ${framework-versions}) + message(SEND_ERROR "Framework versions not found at ${framework-versions}") +endif() diff --git a/Tests/RunCMake/Framework/RunCMakeTest.cmake b/Tests/RunCMake/Framework/RunCMakeTest.cmake new file mode 100644 index 000000000..d8102837b --- /dev/null +++ b/Tests/RunCMake/Framework/RunCMakeTest.cmake @@ -0,0 +1,33 @@ +include(RunCMake) + +# iOS + +set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/iOSFrameworkLayout-build) +set(RunCMake_TEST_NO_CLEAN 1) +set(RunCMake_TEST_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/ios.cmake") + +file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") +file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + +run_cmake(FrameworkLayout) +run_cmake_command(iOSFrameworkLayout-build ${CMAKE_COMMAND} --build .) + +unset(RunCMake_TEST_BINARY_DIR) +unset(RunCMake_TEST_NO_CLEAN) +unset(RunCMake_TEST_OPTIONS) + +# OSX + +set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/OSXFrameworkLayout-build) +set(RunCMake_TEST_NO_CLEAN 1) +set(RunCMake_TEST_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/OSX.cmake") + +file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") +file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + +run_cmake(FrameworkLayout) +run_cmake_command(OSXFrameworkLayout-build ${CMAKE_COMMAND} --build .) + +unset(RunCMake_TEST_BINARY_DIR) +unset(RunCMake_TEST_NO_CLEAN) +unset(RunCMake_TEST_OPTIONS) diff --git a/Tests/RunCMake/Framework/foo.c b/Tests/RunCMake/Framework/foo.c new file mode 100644 index 000000000..bf7759e11 --- /dev/null +++ b/Tests/RunCMake/Framework/foo.c @@ -0,0 +1 @@ +int foo() { return 42; } diff --git a/Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake b/Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake new file mode 100644 index 000000000..373baad7a --- /dev/null +++ b/Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake @@ -0,0 +1,20 @@ +set(framework-dir "${RunCMake_TEST_BINARY_DIR}/Framework.framework") +set(plist-file "${framework-dir}/Info.plist") +set(framework-library "${framework-dir}/Framework") +set(framework-versions "${framework-dir}/Versions") + +if(NOT IS_DIRECTORY ${framework-dir}) + message(SEND_ERROR "Framework not found at ${framework-dir}") +endif() + +if(NOT EXISTS ${plist-file}) + message(SEND_ERROR "plist file not found at ${plist-file}") +endif() + +if(NOT EXISTS ${framework-library}) + message(SEND_ERROR "Framework library not found at ${framework-library}") +endif() + +if(EXISTS ${framework-versions}) + message(SEND_ERROR "Framework versions found at ${framework-versions}") +endif() diff --git a/Tests/RunCMake/Framework/ios.cmake b/Tests/RunCMake/Framework/ios.cmake new file mode 100644 index 000000000..209a50d39 --- /dev/null +++ b/Tests/RunCMake/Framework/ios.cmake @@ -0,0 +1,25 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_VERSION 1) +set(UNIX True) +set(APPLE True) + +set(CMAKE_MACOSX_BUNDLE TRUE) +set(CMAKE_CXX_COMPILER_WORKS TRUE) +set(CMAKE_C_COMPILER_WORKS TRUE) +set(CMAKE_CROSSCOMPILING TRUE) +set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") +set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") + +find_program(XCRUN_EXECUTABLE xcrun) +if(NOT XCRUN_EXECUTABLE) + message(FATAL_ERROR "xcrun not found") +endif() + +execute_process( + COMMAND ${XCRUN_EXECUTABLE} --sdk iphoneos --show-sdk-path + OUTPUT_VARIABLE IOS_SDK_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(CMAKE_OSX_SYSROOT ${IOS_SDK_PATH} CACHE PATH "Sysroot used for iOS support") +set(CMAKE_OSX_ARCHITECTURES "armv7" CACHE STRING "Architectures to build for") +set(CMAKE_FIND_ROOT_PATH ${IOS_SDK_PATH} CACHE PATH "Find search path root") diff --git a/Tests/RunCMake/Framework/osx.cmake b/Tests/RunCMake/Framework/osx.cmake new file mode 100644 index 000000000..e021fcd45 --- /dev/null +++ b/Tests/RunCMake/Framework/osx.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_VERSION 1) +set(UNIX True) +set(APPLE True) + +find_program(XCRUN_EXECUTABLE xcrun) +if(NOT XCRUN_EXECUTABLE) + message(FATAL_ERROR "xcrun not found") +endif() + +execute_process( + COMMAND ${XCRUN_EXECUTABLE} --sdk macosx --show-sdk-path + OUTPUT_VARIABLE OSX_SDK_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(CMAKE_OSX_SYSROOT ${OSX_SDK_PATH} CACHE PATH "Sysroot used for OSX support") + +set(CMAKE_FIND_ROOT_PATH ${OSX_SDK_PATH} CACHE PATH "Find search path root")