[CMake] OS X Fortran flags (Bill Somerville)

Bill Somerville bill at classdesign.com
Fri Oct 24 14:03:14 EDT 2014


On 24/10/2014 18:39, Zaak Beekman wrote:
> Hi Bill,
Hi Zaak,

thanks for the detailed suggestions, more comments in line below.

> I feel your pain. I suspect a CMake bug is hidden away somewhere 
> causing this behavior, and have struggled with this quite a lot.
I think you are correct.
>
> I *think* explicitly passing the relevant option to the linker fixes 
> this, although I have some other CMake/Fortran/Mac hackery happening 
> in my CMakeLists.txt and I can’t remember the reasoning for 
> everything. The following is wrapped in something like if(APPLE), and 
> annoyingly, a slightly different form needs to be used if passing this 
> flag to the linker when using the Intel compilers:
>
> if ( CMAKE_OSX_DEPLOYMENT_TARGET )
>  set ( CMAKE_EXE_LINKER_FLAGS
>  "${CMAKE_EXE_LINKER_FLAGS} 
> -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}" )
> endif ( CMAKE_OSX_DEPLOYMENT_TARGET )
>
> I *suspect* this work around will fix your problem.
Well in my case it is the compiler flags that need adding to.

I think what is happening is that the compiler is using an intrinsic 
system call __stret_sincos to optimize sin and cos calculations with the 
same arguments, this is only available on 10.9 so builds done on 10.9 
will not run on earlier versions of OS X unless 
-mmacosx-version-min=<version> is specified. This is exactly the reason 
for the whole deployment target switch.

I don't know ifort so don't know if it has similar options or even if it 
uses system calls that are that new. But for sure passing linker flags 
is only part of the solution.
>
> Some more details:
> I can’t seem to follow my reasoning for exactly what hacks fixed what 
> problems; essentially I wanted to build a redistributable binary for 
> Mac using Fortran sources. Some of my hackery might be to allow for 
> statically linked builds, but here is my basic approach. First the 
> main CMakeLists.txt file:
Steering clear of static builds for our project. We have a application 
bundle as out Mac deployable so we include any frameworks and extra 
support dylibs within that.
>
> cmake_minimum_required ( VERSION 2.8.11 FATAL_ERROR )
> include ( checkOutOfSource.cmake )
> include ( configurePlatform.cmake )
> include ( configureBuilds.cmake )
> enable_language ( C )
> enable_language ( Fortran )
> include ( compiler-specific-settings.cmake )
> project ( myproj NONE )
>
> add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/src )
>
> Have found that the order of setting certain variables can make a big 
> difference, and that some are better set before the project command or 
> between the enable_language and project command. The other relevant 
> commands are in configurePlatform.cmake and 
> compiler-specific-settings.cmake.
>
> In configurePlatform.cmake I have:
>
>   if ( APPLE )
>     set ( CMAKE_OSX_DEPLOYMENT_TARGET "10.6"
>       CACHE STRING "Oldest OS X version to compile and link for." )
>     set_property ( CACHE CMAKE_OSX_DEPLOYMENT_TARGET PROPERTY STRINGS
>       "10.6" "10.7" "10.8" "10.9" )
>>
> and then in compiler specific settings I have the modification to the 
> linker flags given above.
>
> I hope this fixes your issue, and that someone with more intimate 
> knowledge of CMake can work on Fortran support using different 
> compilers on Mac.
I am rebuilding right now with manually set options. I agree better 
Fortran compiler support on Mac seems necessary.
>
>
>
> Izaak Beekman
> ===================================
> (301)244-9367
> Princeton University Doctoral Candidate
> Mechanical and Aerospace Engineering
> ibeekman at princeton.edu <mailto:ibeekman at princeton.edu>
>
> UMD-CP Visiting Graduate Student
> Aerospace Engineering
> ibeekman at umiacs.umd.edu <mailto:ibeekman at umiacs.umd.edu>
> ibeekman at umd.edu <mailto:ibeekman at umd.edu>
>
Regards
Bill.
>
>     Message: 3
>     Date: Fri, 24 Oct 2014 16:31:49 +0100
>     From: Bill Somerville <bill at classdesign.com
>     <mailto:bill at classdesign.com>>
>     To: CMake ML <cmake at cmake.org <mailto:cmake at cmake.org>>
>     Subject: [CMake] OS X Fortran flags
>     Message-ID: <544A70E5.3040807 at classdesign.com
>     <mailto:544A70E5.3040807 at classdesign.com>>
>     Content-Type: text/plain; charset=utf-8; format=flowed
>
>     Hi,
>
>     I am building some Fortran sources and on Mac I want to make the
>     resulting executable portable back to 10.7.
>
>     So I have:
>
>     if (APPLE)
>        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
>        set (CMAKE_OSX_DEPLOYMENT_TARGET 10.7) # Earliest version we can
>     support with C++11 & libc++
>        set (CMAKE_OSX_SYSROOT
>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk)
>     endif (APPLE)
>
>     in my CMakeLists.txt.
>
>     I am building on a 10.8 system with the 10.9 SDK installed.
>
>     This all works as expected with the C and C++ sources in the
>     project but
>     the Fortran compiles are not being passed the relevant options:
>
>     -isysroot
>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
>     -mmacosx_version_min=10.7
>
>     The Fortran compiler is the MacPorts gcc49 itself built from sources
>     using the same options so that the distributable libraries
>     reference the
>     correct system library function versions.
>
>     So what am I missing? A brief scan of the CMake sources looks like it
>     should be doing this right for GNU compilers as the compiler tests
>     should check for those options being supported and supply them.
>
>     Do I have to add these options to the FFLAGS in my CMakeLists.txt?
>
>     Regards
>     Bill.
>
>
>     ------------------------------
>
>     Message: 4
>     Date: Fri, 24 Oct 2014 17:44:56 +0100
>     From: Bill Somerville <bill at classdesign.com
>     <mailto:bill at classdesign.com>>
>     To: cmake at cmake.org <mailto:cmake at cmake.org>
>     Subject: Re: [CMake] OS X Fortran flags
>     Message-ID: <544A8208.7030602 at classdesign.com
>     <mailto:544A8208.7030602 at classdesign.com>>
>     Content-Type: text/plain; charset=windows-1252; format=flowed
>
>     A small correction:
>
>     On 24/10/2014 16:31, Bill Somerville wrote:
>     > Hi,
>     >
>     > I am building some Fortran sources and on Mac I want to make the
>     > resulting executable portable back to 10.7.
>     >
>     > So I have:
>     >
>     > if (APPLE)
>     >   set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
>     >   set (CMAKE_OSX_DEPLOYMENT_TARGET 10.7) # Earliest version we can
>     > support with C++11 & libc++
>     >   set (CMAKE_OSX_SYSROOT
>     >
>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk)
>     > endif (APPLE)
>     >
>     > in my CMakeLists.txt.
>     >
>     > I am building on a 10.8 system with the 10.9 SDK installed.
>     >
>     > This all works as expected with the C and C++ sources in the project
>     > but the Fortran compiles are not being passed the relevant options:
>     >
>     > -isysroot
>     >
>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
>     > -mmacosx_version_min=10.7
>     -mmacosx-version-min=10.7
>     >
>     > The Fortran compiler is the MacPorts gcc49 itself built from sources
>     > using the same options so that the distributable libraries reference
>     > the correct system library function versions.
>     >
>     > So what am I missing? A brief scan of the CMake sources looks
>     like it
>     > should be doing this right for GNU compilers as the compiler tests
>     > should check for those options being supported and supply them.
>     >
>     > Do I have to add these options to the FFLAGS in my CMakeLists.txt?
>     >
>     > Regards
>     > Bill.
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141024/817774c7/attachment.html>


More information about the CMake mailing list