[R-pkg-devel] MacOS CMAKE_OSX_ARCHITECTURES

Simon Urbanek @|mon@urb@nek @end|ng |rom R-project@org
Tue Sep 6 00:46:41 CEST 2022


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



> On Sep 6, 2022, at 2:27 AM, Florian Schwendinger <FlorianSchwendinger using gmx.at> wrote:
> 
> Dear package developers,
> 
> I currently try to debug a few issues which occur on MacOS
> r-release-macos-arm64 and r-oldrel-macos-arm64.
> 
> To the setting I wrote an interface to mixed integer linear optimization
> solver highs. Thereby I use the configure script + a bash file called
> from configure to build a static library to which I link afterwards.
> 
> For MacOS M1 this was a little bit tricky since I needed to add the
> CMAKE_OSX_ARCHITECTURES flag to get it to work (I have no direct access to MacOS M1).
> What I currently doing for MacOS-M1 is
> ${CMAKE_EXE} \
> -DCMAKE_INSTALL_PREFIX=${R_HIGHS_LIB_DIR} \
> -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
> 
> As far as I understand from the cmake release page
> https://cmake.org/cmake/help/latest/release/3.19.html#id13
> which states
> "The precompiled macOS binary provided on cmake.org is now a universal
> binary with x86_64 and arm64 architectures."
> for this to work I need at least cmake version "3.19.2"?
> Is this correct?
> Is there a better way / another option?
> 
> 
> I used for MacOS-M1 the minimum cmake version "3.20" since
> this is the version I could test with a testing service.
> Now seeing the error messages on
> "r-release-macos-arm64" and "r-oldrel-macos-arm64"
> I see these two setups use cmake "3.19.4" which means
> I should have stuck to "3.19.2" if my assumption above is
> correct. Is it possible to see beforehand what the highest
> possible cmake version for CRAN is?
> 
> Best regards,
> Florian
>  
>  
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> 



More information about the R-package-devel mailing list