Compilation with/for multiarch
Cmake
If order to compile to 32 bit from a 64 bit gcc multilib with cmake:
cmake \ -DCMAKE_C_FLAGS=-m32 \ -DCMAKE_CXX_FLAGS=-m32 \ -DCMAKE_Fortran_FLAGS=-m32 \ -DCMAKE_EXE_LINKER_FLAGS=-m32 \ -DCMAKE_MODULE_LINKER_FLAGS=-m32 \ -DCMAKE_SHARED_LINKER_FLAGS=-m32 \ -DCMAKE_ASM-ATT_FLAGS=-m32 \ .
The CMAKE_LIBRARY_ARCHITECTURE variable should be automatically defined correctly.
In order to install the libraries in the correct multiarch-aware location, the CMAKE_LIBRARY_ARCHITECTURE can be used. Its value is set by cmake to the suitable multiarch folder name (i386-linux-gnu, x86_64-linux-gnu…):
install(TARGETS foo DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE})