How to identify platforms like ARM, MIPS and IA32?

Something sideways in our CmakeFileList.txt file . He is trying to create an IA32 component on the ARM platform. I am trying to solve a problem.

This file has been filtered from GLOB called rdrand.cpp :

 list(REMOVE_ITEM cryptopp_SOURCES ... ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.cpp ... ${cryptopp_SOURCES_TEST} ) set(cryptopp_SOURCES 

Now I'm trying to add rdrand,cpp back for IA32 platforms. According to Building a C ++ project on Windows using CMake, Clang and Ninja (not very suitable, but has useful information) and CMakePlatformId.h.in , it looks like I need a predicate using ARCHITECTURE_ID and "X86" , "X32" , "X64" or "X64" (not dup, x lowercase instead of uppercase).

Here is my attempt to create a predicate:

 # http://github.com/weidai11/cryptopp/issues/419 if (${ARCHITECTURE_ID} == "X86" OR ${ARCHITECTURE_ID} == "X32" OR ${ARCHITECTURE_ID} == "X64" ) list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.cpp) endif() 

Below are the results with BeagleBoard with Cmake 3.5.2. Neither == , = , STREQUAL does not work:

 CMake Error at CMakeLists.txt:310 (if): if given arguments: "==" "X86" "OR" "==" "X32" "OR" "==" "X64" Unknown arguments specified 

and

 $ cmake . CMake Error at CMakeLists.txt:310 (if): if given arguments: "STREQUAL" "X86" "OR" "STREQUAL" "X32" "OR" "STREQUAL" "X64" Unknown arguments specified 

My attempts to find a way to use ARCHITECTURE_ID almost useless. I cannot find an example or documents on the Cmake website . Adding quotes around "${ARCHITECTURE_ID}" did not help; also did not remove curly braces to indicate the variable ARCHITECTURE_ID .

I also tried using CMAKE_SYSTEM_PROCESSOR and other related definitions, but Cmake basically returns "unknown" for them. This is not very useful, to say the least.

How to use ARCHITECTURE_ID to identify IA32 platforms? Or is there anything else I should use in this case?

Thanks in advance.


Here's what we do in our GNUmakefile . Make is not an assembly, so we must do a heavy lift:

 IS_X86 := $(shell uname -m | $(EGREP) -v "x86_64" | $(EGREP) -i -c "i.86|x86|i86") IS_X64 := $(shell uname -m | $(EGREP) -i -c "(_64|d64)") ... # Need RDRAND for X86/X64/X32 ifeq ($(IS_X86)$(IS_X32)$(IS_X64),000) SRCS := $(filter-out rdrand.cpp, $(SRCS)) endif 
+5
source share
1 answer
  • I do not think that a variable named ARCHITECTURE_ID exists in CMake for the request. This is probably the reason you cannot find any hints in the CMake documentation. It is used only in CMakePlatformId.h to populate MSVC specific internal variable of type MSVC_CXX_ARCHITECTURE_ID .

     /* For windows compilers MSVC and Intel we can determine the architecture of the compiler being used. This is because the compilers do not have flags that can change the architecture, but rather depend on which compiler is being used */ 
  • What you are really looking for is cmake_host_system_information() . The problem is that it does not export all the information that it actually has. I think this is a missing feature, and perhaps in the coming days you will receive a request for a CMake Git source to expand its functionality, but this will not help you in the near future.

    If you have the CMake source code in the system (s) in question, you can run one of the tests

      $ cmsysTestscxx testSystemInformation 

    to see what system information CMake really has.

    𝓝𝓸𝓽𝓮: a request to the host system will not help with cross-compilation or, for example, compiling for 32 bits on a 64-bit machine (which may also be a possible flaw in your GNUMakefile example).

  • To answer the if question, this can simply be solved with Regular Expression :

     cmake_minimum_required(VERSION 2.4) project(TestArchitectureId) if (ARCHITECTURE_ID MATCHES "^(X86|X32|X64|x64)$" ) message(STATUS "Hello ${CMAKE_MATCH_1}") endif() 

Otherwise, it is not related to the detection of a 32-bit x86 processor in CMakeList.txt?

Alternatives

CMake itself uses

 if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "ia64") 

or

 if(NOT CMAKE_GENERATOR MATCHES "IA64") 

or - even this may take an extra mile - calling try_compile() using rdrand.cpp :

 # Choose a configuration for our compiler tests if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_NO_BUILD_TYPE) set(CMAKE_TRY_COMPILE_CONFIGURATION "${CMAKE_BUILD_TYPE}") else() set(CMAKE_TRY_COMPILE_CONFIGURATION RelWithDebInfo) endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) string(TOUPPER "${CMAKE_TRY_COMPILE_CONFIGURATION}" cryptopp_TRY_COMPILE_CONFIGURATION) set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}" "${CMAKE_CXX_FLAGS_${cryptopp_TRY_COMPILE_CONFIGURATION}}") get_directory_property(CMAKE_REQUIRED_INCLUDES INCLUDE_DIRECTORIES) get_directory_property(CMAKE_REQUIRED_DEFINITIONS COMPILE_DEFINITIONS) if (CMAKE_REQUIRED_DEFINITIONS) string(REPLACE ";" ";-D" CMAKE_REQUIRED_DEFINITIONS "-D${CMAKE_REQUIRED_DEFINITIONS}") endif() try_compile( cryptopp_RDRAND_WORKS ${CMAKE_CURRENT_BINARY_DIR} SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.cpp CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} -DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ) 
+2
source

All Articles