From f0b53998c81f7db0c2aa8106f82fe91841c22457 Mon Sep 17 00:00:00 2001 From: Victor Perevertkin Date: Thu, 15 Apr 2021 04:50:12 +0300 Subject: [PATCH] [CMAKE] Require ARCH variable to be specified explicitly Also, use CMAKE_TRY_COMPILE_PLATFORM_VARIABLES in toolchain files to solve issues with ARCH not being passed during try_compile --- CMakeLists.txt | 6 +++++- toolchain-clang.cmake | 9 ++++----- toolchain-gcc.cmake | 7 +++---- toolchain-msvc.cmake | 7 +++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eca63cb4723..8796992b5e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,9 @@ set(CMAKE_C_STANDARD 99) set(CMAKE_CXX_STANDARD 11) #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF) +# check that the ARCH (target architecture) variable is defined if(NOT ARCH) - set(ARCH i386) + message(FATAL_ERROR "Target architecture (ARCH) is not defined. Please, choose one of: i386, amd64, arm") endif() # Now the ARCH variable will be in lowercase. # It is needed because STREQUAL comparison @@ -38,6 +39,9 @@ endif() # for more information. string(TOLOWER ${ARCH} ARCH) +# set possible values for cmake GUI +set_property(CACHE ARCH PROPERTY STRINGS "i386" "amd64" "arm") + # Alternative WinNT-compatible architecture string if(ARCH STREQUAL "i386") set(WINARCH "x86") diff --git a/toolchain-clang.cmake b/toolchain-clang.cmake index e181bf0baf4..e06a4116438 100644 --- a/toolchain-clang.cmake +++ b/toolchain-clang.cmake @@ -1,12 +1,11 @@ -if(NOT ARCH) - set(ARCH i386) -endif() - if(DEFINED ENV{_ROSBE_ROSSCRIPTDIR}) set(CMAKE_SYSROOT $ENV{_ROSBE_ROSSCRIPTDIR}/$ENV{ROS_ARCH}) endif() +# pass variables necessary for the toolchain (needed for try_compile) +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH CLANG_VERSION) + # The name of the target operating system set(CMAKE_SYSTEM_NAME Windows) # The processor we are targeting @@ -17,7 +16,7 @@ elseif (ARCH STREQUAL "amd64") elseif(ARCH STREQUAL "arm") set(CMAKE_SYSTEM_PROCESSOR arm) else() - message(ERROR "Unsupported ARCH: ${ARCH}") + message(FATAL_ERROR "Unsupported ARCH: ${ARCH}") endif() if (DEFINED CLANG_VERSION) diff --git a/toolchain-gcc.cmake b/toolchain-gcc.cmake index 44f6d0ce166..9d2a51899ee 100644 --- a/toolchain-gcc.cmake +++ b/toolchain-gcc.cmake @@ -1,14 +1,13 @@ -if(NOT ARCH) - set(ARCH i386) -endif() - # Default to Debug for the build type if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") endif() +# pass variables necessary for the toolchain (needed for try_compile) +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH) + # Choose the right MinGW toolchain prefix if(NOT DEFINED MINGW_TOOLCHAIN_PREFIX) if(ARCH STREQUAL "i386") diff --git a/toolchain-msvc.cmake b/toolchain-msvc.cmake index 2aae2edbdd4..9de8fca31e9 100644 --- a/toolchain-msvc.cmake +++ b/toolchain-msvc.cmake @@ -1,14 +1,13 @@ -if(NOT ARCH) - set(ARCH i386) -endif() - # Default to Debug for the build type if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") endif() +# pass variables necessary for the toolchain (needed for try_compile) +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH USE_CLANG_CL) + # the name of the target operating system set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR i686)