From 9fb8d8f4b6d7e4cdbe286f735fd0309e28419a72 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Fri, 25 Oct 2024 10:35:45 +0200 Subject: [PATCH] cmake: improve platform/compiler/architecture detection and make cross-building to QNX on Windows possible (#137) --- SilKit/cmake/get_compiler_arch.cmake | 87 +++++++++++++-------- SilKit/cmake/qnx-cross-base-toolchain.cmake | 2 + docs/CHANGELOG.rst | 6 ++ 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/SilKit/cmake/get_compiler_arch.cmake b/SilKit/cmake/get_compiler_arch.cmake index db08d6b6a..851b8944c 100644 --- a/SilKit/cmake/get_compiler_arch.cmake +++ b/SilKit/cmake/get_compiler_arch.cmake @@ -80,73 +80,92 @@ function(get_linux_distro outDistroName outDistroVersion) endfunction() function(get_compiler_arch outCompiler outArch outPlatform ) - #get arch + # compute bitness + if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") set(SYSTEM_BITNESS "64") elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") set(SYSTEM_BITNESS "32") else() - message(FATAL_ERROR "Bitness is not supported: \"${CMAKE_SIZEOF_VOID_P}\"") + message(FATAL_ERROR "Unsupported pointer size: ${CMAKE_SIZEOF_VOID_P}") endif() - message(STATUS "SIL Kit using ${SYSTEM_BITNESS}-Bit build") - #get OS + message(STATUS "SIL Kit using ${SYSTEM_BITNESS}-bit build") + message(STATUS "SIL Kit using compiler version ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") + + # compute platform and architecture + + set(_platform "${CMAKE_SYSTEM_NAME}") + set(_system_arch "UNKNOWN") + if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") set(_platform "Win") - set(_system_arch "x86") + # building on (or for) Windows-on-ARM will lead to invalid architecture values + if("${SYSTEM_BITNESS}" STREQUAL "64") set(_system_arch "x86_64") + else() + set(_system_arch "x86") endif() + elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "QNX") + set(_system_arch "${SILKIT_TARGET_ARCHITECTURE}") elseif(UNIX) # generic unix has uname get_uname(_un_name _un_machine) set(_platform "${_un_name}") set(_system_arch "${_un_machine}") - else() - set(_system_arch "${CMAKE_SYSTEM_NAME}") endif() if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + # on linux the platform tag is used for the distribution name and version get_linux_distro(_distro_name _distro_version) if( DEFINED _distro_name AND DEFINED _distro_version) set(_platform "${_distro_name}-${_distro_version}") endif() endif() - # get toolset/compiler id + version + # compute compiler name + set(_tool_tag "UNKNOWN") - if(UNIX) - set(_id "${CMAKE_CXX_COMPILER_ID}") + + if(MINGW) + # currently any mingw compiler uses the tag MinGW for the compiler + set(_tool_tag "MinGW") + else() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(_id "gcc") + set(_tool_tag "gcc") elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(_id "clang") - endif() - message(STATUS "Using compiler version: ${_id}-${CMAKE_CXX_COMPILER_VERSION}") - set(_tool_tag ${_id}) - elseif(MINGW) - set(_tool_tag "MinGW") - elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") - silkit_validate_preset_toolset() - if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v140") - set(_tool_tag "VS2015") - elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v141") - set(_tool_tag "VS2017") - elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v142") - set(_tool_tag "VS2019") - elseif(MSVC_TOOLSET_VERSION MATCHES "142") - set(_tool_tag "VS2019") - elseif(MSVC_TOOLSET_VERSION MATCHES "141") - set(_tool_tag "VS2017") - elseif(MSVC_TOOLSET_VERSION MATCHES "140") - set(_tool_tag "VS2015") + set(_tool_tag "clang") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + silkit_validate_preset_toolset() + + if("${MSVC_TOOLSET_VERSION}" STREQUAL "140") + set(_tool_tag "VS2015") + elseif("${MSVC_TOOLSET_VERSION}" STREQUAL "141") + set(_tool_tag "VS2017") + elseif("${MSVC_TOOLSET_VERSION}" STREQUAL "142") + set(_tool_tag "VS2019") + elseif("${MSVC_TOOLSET_VERSION}" STREQUAL "143") + set(_tool_tag "VS2022") + elseif("${MSVC_TOOLSET_VERSION}" STREQUAL "144") + set(_tool_tag "VS2022") + elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio ") + # fallback for VS generators + string(REGEX REPLACE "Visual Studio [0-9]+ ([0-9]+) *.*" "\\1" vers "${CMAKE_GENERATOR}") + set(_tool_tag "VS${vers}") + else() + # fallback for 'unhandled' MSVC toolset versions + set(_tool_tag "MSVC${MSVC_TOOLSET_VERSION}") + endif() else() - string(REGEX REPLACE "Visual Studio [0-9]+ ([0-9]+) *.*" "\\1" vers "${CMAKE_GENERATOR}") - set(_tool_tag "VS${vers}") + # generic fallback + set(_tool_tag "${CMAKE_CXX_COMPILER_ID}") endif() endif() - #return triple + + # set output variables + set(${outPlatform} "${_platform}" PARENT_SCOPE) set(${outCompiler} "${_tool_tag}" PARENT_SCOPE) set(${outArch} "${_system_arch}" PARENT_SCOPE) diff --git a/SilKit/cmake/qnx-cross-base-toolchain.cmake b/SilKit/cmake/qnx-cross-base-toolchain.cmake index 3117cdc90..0f8b80029 100644 --- a/SilKit/cmake/qnx-cross-base-toolchain.cmake +++ b/SilKit/cmake/qnx-cross-base-toolchain.cmake @@ -87,3 +87,5 @@ set(CMAKE_RANLIB ${RANLIB_EXE} CACHE PATH "QNX ranlib" FORCE) set(CMAKE_AR ${AR_EXE} CACHE PATH "QNX ranlib" FORCE) set(CMAKE_MAKE_PROGRAM ${MAKE_EXE} CACHE PATH "QNX make" FORCE) + +set(CMAKE_SKIP_BUILD_RPATH ON) \ No newline at end of file diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 8a1f0676e..9e7071041 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -13,6 +13,12 @@ Changed ~~~~~~~ - Revised the documentation (demos, troubleshooting, doxygen output, file structure) +- Improved platform/compiler/architecture detection + +Fixed +~~~~~ + +- Failure to configure and package cross-builds to QNX on Windows [4.0.53] - 2024-10-11 ---------------------