Skip to content
Prev 8397 / 12125 Next

[R-pkg-devel] MacOS CMAKE_OSX_ARCHITECTURES

Florian,

I think the CMake version is the least of your problems (that one would be trivial to address and I don't think it's needed at all). You cannot really assume that building multi-arch binaries is supported (most compilers don't support it) nor that it will work with R, so you cannot hard-code DCMAKE_OSX_ARCHITECTURES. If you are building a package, you have to use the compilers and flags from R - and they will differ a lot between architectures. Note that you have similar problem on other systems, not just macOS, there is no need to treat macOS differently in that respect.

I don't understand why you have four different CMakeLists - you only need one, the point of cmake is that it will correctly detect dependencies regardless of the OS and arch. However, you have to make sure you pass compiler flags from R so you have the right compilers and flags for the system and architecture that is being built. Once you do that, stock CMakeList typically work just fine.

I had a quick look and this worked for me (not using any of your patches):

## set R flags and compilers
export CC=`R CMD config CC`
export CXX=`R CMD config CXX`
export CXXFLAGS=`R CMD config CXXFLAGS`
export CFLAGS=`R CMD config CFLAGS`
export CPPFLAGS=`R CMD config CPPFLAGS`
export LDFLAGS=`R CMD config LDFLAGS`

${CMAKE_EXE} .. -DCMAKE_POSITION_INDEPENDENT_CODE:bool=ON -DSHARED:bool=OFF -DBUILD_TESTING:bool=OFF

(Maybe you need CXX11 instead of CXX above since CMakeList seems to suggest that it requires C++11)

Cheers,
Simon