diff options
author | Brad King <brad.king@kitware.com> | 2020-12-11 18:05:12 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-12-11 18:05:34 (GMT) |
commit | 794aa36b1fe945c25822108dbf3bcaa4c89f26d7 (patch) | |
tree | 97d0622c5cd7ac0be8e137b7cd0ab52c494e0f79 /Tests/RunCMake | |
parent | 0d9c43281fa4e39b18f63af3619fb89280bde722 (diff) | |
parent | b7f0327dcd4032c6a118825adcfdc8dab6295e7f (diff) | |
download | CMake-794aa36b1fe945c25822108dbf3bcaa4c89f26d7.zip CMake-794aa36b1fe945c25822108dbf3bcaa4c89f26d7.tar.gz CMake-794aa36b1fe945c25822108dbf3bcaa4c89f26d7.tar.bz2 |
Merge topic 'apple-silicon-host-arch'
b7f0327dcd Tests: Cover macOS host architecture selection on Apple Silicon hosts
5f882f6ce5 macOS: Offer control over host architecture on Apple Silicon hosts
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5589
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/AppleSilicon/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/RunCMakeTest.cmake | 27 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/arm64-common.cmake | 10 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/arm64-env.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/arm64-var.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/arm64.c | 9 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/default.c | 14 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/default.cmake | 15 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/x86_64-common.cmake | 10 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/x86_64-env.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/x86_64-var.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/AppleSilicon/x86_64.c | 9 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 3 |
13 files changed, 104 insertions, 0 deletions
diff --git a/Tests/RunCMake/AppleSilicon/CMakeLists.txt b/Tests/RunCMake/AppleSilicon/CMakeLists.txt new file mode 100644 index 0000000..ab1a20c --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.19) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/AppleSilicon/RunCMakeTest.cmake b/Tests/RunCMake/AppleSilicon/RunCMakeTest.cmake new file mode 100644 index 0000000..39e462e --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/RunCMakeTest.cmake @@ -0,0 +1,27 @@ +include(RunCMake) + +# Isolate from caller's environment. +set(ENV{CMAKE_APPLE_SILICON_PROCESSOR} "") +set(ENV{CMAKE_OSX_ARCHITECTURES} "") + +function(run_arch case) + set(RunCMake_TEST_OPTIONS ${ARGN}) + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${case}-build") + run_cmake(${case}) + unset(RunCMake_TEST_OPTIONS) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug) +endfunction() + +run_arch(default) + +run_arch(arm64-var -DCMAKE_APPLE_SILICON_PROCESSOR=arm64) +run_arch(x86_64-var -DCMAKE_APPLE_SILICON_PROCESSOR=x86_64) + +set(ENV{CMAKE_APPLE_SILICON_PROCESSOR} "arm64") +run_arch(arm64-env) + +set(ENV{CMAKE_APPLE_SILICON_PROCESSOR} "x86_64") +run_arch(x86_64-env) + +set(ENV{CMAKE_APPLE_SILICON_PROCESSOR} "") diff --git a/Tests/RunCMake/AppleSilicon/arm64-common.cmake b/Tests/RunCMake/AppleSilicon/arm64-common.cmake new file mode 100644 index 0000000..5a13728 --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/arm64-common.cmake @@ -0,0 +1,10 @@ +enable_language(C) + +if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") + message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR is '${CMAKE_HOST_SYSTEM_PROCESSOR}', not 'arm64'") +endif() +if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "") + message(FATAL_ERROR "CMAKE_OSX_ARCHITECTURES is '${CMAKE_OSX_ARCHITECTURES}', not empty ''") +endif() + +add_library(arm64 arm64.c) diff --git a/Tests/RunCMake/AppleSilicon/arm64-env.cmake b/Tests/RunCMake/AppleSilicon/arm64-env.cmake new file mode 100644 index 0000000..8cb9dbc --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/arm64-env.cmake @@ -0,0 +1 @@ +include(arm64-common.cmake) diff --git a/Tests/RunCMake/AppleSilicon/arm64-var.cmake b/Tests/RunCMake/AppleSilicon/arm64-var.cmake new file mode 100644 index 0000000..8cb9dbc --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/arm64-var.cmake @@ -0,0 +1 @@ +include(arm64-common.cmake) diff --git a/Tests/RunCMake/AppleSilicon/arm64.c b/Tests/RunCMake/AppleSilicon/arm64.c new file mode 100644 index 0000000..d5f65fe --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/arm64.c @@ -0,0 +1,9 @@ +#ifndef __aarch64__ +# error "Not compiling as arm64" +#endif +#ifdef __x86_64__ +# error "Incorrectly compiling as x86_64" +#endif +void arm64_arch(void) +{ +} diff --git a/Tests/RunCMake/AppleSilicon/default.c b/Tests/RunCMake/AppleSilicon/default.c new file mode 100644 index 0000000..7b0535b --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/default.c @@ -0,0 +1,14 @@ +#if defined(HOST_ARM64) +# if !defined(__aarch64__) +# error "Not compiling as host arm64" +# endif +#elif defined(HOST_X86_64) +# if !defined(__x86_64__) +# error "Not compiling as host x86_64" +# endif +#else +# error "One of HOST_ARM64 or HOST_X86_64 must be defined." +#endif +void default_arch(void) +{ +} diff --git a/Tests/RunCMake/AppleSilicon/default.cmake b/Tests/RunCMake/AppleSilicon/default.cmake new file mode 100644 index 0000000..f160e25 --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/default.cmake @@ -0,0 +1,15 @@ +enable_language(C) + +if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") + set(host_def HOST_ARM64) +elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(host_def HOST_X86_64) +else() + message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR is '${CMAKE_HOST_SYSTEM_PROCESSOR}', not 'arm64' or 'x86_64'") +endif() +if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "") + message(FATAL_ERROR "CMAKE_OSX_ARCHITECTURES is '${CMAKE_OSX_ARCHITECTURES}', not empty ''") +endif() + +add_library(default default.c) +target_compile_definitions(default PRIVATE ${host_def}) diff --git a/Tests/RunCMake/AppleSilicon/x86_64-common.cmake b/Tests/RunCMake/AppleSilicon/x86_64-common.cmake new file mode 100644 index 0000000..602bf92 --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/x86_64-common.cmake @@ -0,0 +1,10 @@ +enable_language(C) + +if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR is '${CMAKE_HOST_SYSTEM_PROCESSOR}', not 'x86_64'") +endif() +if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "") + message(FATAL_ERROR "CMAKE_OSX_ARCHITECTURES is '${CMAKE_OSX_ARCHITECTURES}', not empty ''") +endif() + +add_library(x86_64 x86_64.c) diff --git a/Tests/RunCMake/AppleSilicon/x86_64-env.cmake b/Tests/RunCMake/AppleSilicon/x86_64-env.cmake new file mode 100644 index 0000000..a44eaa4 --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/x86_64-env.cmake @@ -0,0 +1 @@ +include(x86_64-common.cmake) diff --git a/Tests/RunCMake/AppleSilicon/x86_64-var.cmake b/Tests/RunCMake/AppleSilicon/x86_64-var.cmake new file mode 100644 index 0000000..a44eaa4 --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/x86_64-var.cmake @@ -0,0 +1 @@ +include(x86_64-common.cmake) diff --git a/Tests/RunCMake/AppleSilicon/x86_64.c b/Tests/RunCMake/AppleSilicon/x86_64.c new file mode 100644 index 0000000..cd3cc9b --- /dev/null +++ b/Tests/RunCMake/AppleSilicon/x86_64.c @@ -0,0 +1,9 @@ +#ifndef __x86_64__ +# error "Not compiling as x86_64" +#endif +#ifdef __aarch64__ +# error "Incorrectly compiling as arm64" +#endif +void x86_64_arch(void) +{ +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 7f79982..0cab867 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -186,6 +186,9 @@ set_property(TEST RunCMake.ABI APPEND PROPERTY LABELS "CUDA") add_RunCMake_test(AndroidTestUtilities) +if(CMake_TEST_APPLE_SILICON) + add_RunCMake_test(AppleSilicon) +endif() set(autogen_with_qt5 FALSE) if(CMake_TEST_Qt5) find_package(Qt5Widgets QUIET NO_MODULE) |