[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
This commit is contained in:
Victor Perevertkin 2021-04-15 04:50:12 +03:00
parent 72ad37c1cd
commit f0b53998c8
No known key found for this signature in database
GPG key ID: C750B7222E9C7830
4 changed files with 15 additions and 14 deletions

View file

@ -28,8 +28,9 @@ set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
#set_property(GLOBAL PROPERTY RULE_MESSAGES OFF) #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
# check that the ARCH (target architecture) variable is defined
if(NOT ARCH) if(NOT ARCH)
set(ARCH i386) message(FATAL_ERROR "Target architecture (ARCH) is not defined. Please, choose one of: i386, amd64, arm")
endif() endif()
# Now the ARCH variable will be in lowercase. # Now the ARCH variable will be in lowercase.
# It is needed because STREQUAL comparison # It is needed because STREQUAL comparison
@ -38,6 +39,9 @@ endif()
# for more information. # for more information.
string(TOLOWER ${ARCH} ARCH) string(TOLOWER ${ARCH} ARCH)
# set possible values for cmake GUI
set_property(CACHE ARCH PROPERTY STRINGS "i386" "amd64" "arm")
# Alternative WinNT-compatible architecture string # Alternative WinNT-compatible architecture string
if(ARCH STREQUAL "i386") if(ARCH STREQUAL "i386")
set(WINARCH "x86") set(WINARCH "x86")

View file

@ -1,12 +1,11 @@
if(NOT ARCH)
set(ARCH i386)
endif()
if(DEFINED ENV{_ROSBE_ROSSCRIPTDIR}) if(DEFINED ENV{_ROSBE_ROSSCRIPTDIR})
set(CMAKE_SYSROOT $ENV{_ROSBE_ROSSCRIPTDIR}/$ENV{ROS_ARCH}) set(CMAKE_SYSROOT $ENV{_ROSBE_ROSSCRIPTDIR}/$ENV{ROS_ARCH})
endif() 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 # The name of the target operating system
set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_NAME Windows)
# The processor we are targeting # The processor we are targeting
@ -17,7 +16,7 @@ elseif (ARCH STREQUAL "amd64")
elseif(ARCH STREQUAL "arm") elseif(ARCH STREQUAL "arm")
set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_SYSTEM_PROCESSOR arm)
else() else()
message(ERROR "Unsupported ARCH: ${ARCH}") message(FATAL_ERROR "Unsupported ARCH: ${ARCH}")
endif() endif()
if (DEFINED CLANG_VERSION) if (DEFINED CLANG_VERSION)

View file

@ -1,14 +1,13 @@
if(NOT ARCH)
set(ARCH i386)
endif()
# Default to Debug for the build type # Default to Debug for the build type
if(NOT DEFINED CMAKE_BUILD_TYPE) if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING 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.") "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif() endif()
# pass variables necessary for the toolchain (needed for try_compile)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH)
# Choose the right MinGW toolchain prefix # Choose the right MinGW toolchain prefix
if(NOT DEFINED MINGW_TOOLCHAIN_PREFIX) if(NOT DEFINED MINGW_TOOLCHAIN_PREFIX)
if(ARCH STREQUAL "i386") if(ARCH STREQUAL "i386")

View file

@ -1,14 +1,13 @@
if(NOT ARCH)
set(ARCH i386)
endif()
# Default to Debug for the build type # Default to Debug for the build type
if(NOT DEFINED CMAKE_BUILD_TYPE) if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING 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.") "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif() 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 # the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR i686) set(CMAKE_SYSTEM_PROCESSOR i686)