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

Hendrik Sattler post at hendrik-sattler.de
Sat Oct 29 09:25:13 EDT 2016


You need to set these compiler flags BEFORE the project() call to let CMake detect all stuff properly. There is a CMake  variable telling you the size of a void*.


Am 29. Oktober 2016 12:22:07 MESZ, schrieb cen <imbacen at gmail.com>:
>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?

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.


More information about the CMake mailing list