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

Konstantin Tokarev annulen at yandex.ru
Sat Oct 29 11:45:32 EDT 2016



29.10.2016, 16:46, "cen" <imbacen at gmail.com>:
> I tried setting CXXFLAGS and CMAKE_CXX_FLAGS to -m32 before the
> project() call but nothing changed. I could make it fail with
> "CXXFLAGS=-m32 cmake -G ..." from command line but this seems wrong. A
> minimal CMakeLists.txt example would be nice.

Use toolchain file

>
> Hendrik Sattler je 29. 10. 2016 ob 15:25 napisal:
>>  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?
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake

-- 
Regards,
Konstantin


More information about the CMake mailing list