[CMake] Proper way to support 64bit and 32bit builds

cen imbacen at gmail.com
Sat Oct 29 06:22:07 EDT 2016


Hi

Once I switch to 32bit builds, CMake fails to recognise that 
glibc-devel.i686 is not installed resulting in an error when running make.
In the same way, my own FindGMP fails to recognize that gmp-devel.i686 
is not installed. I need CMake to fail if these things are missing.
At least for the compiler part, I'm pretty sure I am missing some var or 
flag to tell CMake I expect a 32 bit build.

This is what I use to switch between builds in CMakeLists.txt (ARCH var 
is irrelevant here,  I use it later on for CPack):

if (BUILD_32)
         set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS 
"-m32" LINK_FLAGS "-m32")
         MESSAGE(STATUS "Excluding 64bit library paths from search.")
         set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS OFF)
         set(ARCH i686)
elseif (BUILD_64)
         set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS 
"-m64" LINK_FLAGS "-m64")
         set(ARCH amd64)
else()
         set(ARCH amd64)
endif()


For the FindGMP module, I am not really sure what the best practice 
is.Does the BUILD_32 and BUILD_64 flag propagate into the FindGMP? Do I 
explicitly specify paths for 32bit libs (eg: /usr/lib64) or can  cmake 
be smarter than this?


More information about the CMake mailing list