[CMake] What combinations must be set for *_LINKER_FLAGS?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Jul 27 14:14:24 EDT 2006


On 2006-07-27 10:01-0400 Brad King wrote:

> Alan W. Irwin wrote:
>> One of our PLplot developers with access to Mac OS X ran into the following
>> error message for the shared libraries for that platform:
>>
>> ld: common symbols not allowed with MH_DYLIB output format with the -
>> multi_module option
>>
>> I have no idea what constraints there are for Mac OS X linking, but
>> fortunately, he was able to make an inspired guess and get around the
>> problem by setting CMAKE_SHARED_LINKER_FLAGS to "-single_module".  I don't
>> know for sure, but I assume he did that with a -D option.
>>
>> To make this a permanent fix I am thinking of doing the following:
>>
>> if(APPLE)
>>   set(CMAKE_SHARED_LINKER_FLAGS "-single_module" CACHE INTERNAL "")
>> endif(APPLE)
>>
>> Is 'CACHE INTERNAL ""' the correct way to set this variable?
>
> If you don't want users to be able to change it this is the right way.
> The standard way to do this is to put the line
>
> set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/User.cmake)
>
> at the VERY TOP of your top level CMakeLists.txt file before the PROJECT
> command.  Then put the lines
>
> if(APPLE)
>  set(CMAKE_SHARED_LINKER_FLAGS "-single_module" CACHE STRING "Flags
> used to link a shared library.")
> endif(APPLE)
>
> in the file User.cmake.
>
> The above will change the default flags stored in that variable when a
> new build tree is created.  CMake will not touch the value after that so
> users can still edit it.  Without this override CMake would store its
> own default value in the variable.

Once you pointed the way I had a look at CMakeCInformation.cmake and other
*Information.cmake files and decided instead to use the more generic
CMAKE_USER_MAKE_RULES_OVERRIDE since I wanted to keep all our default
overrides for compilers and linkers in one spot.

>
>> What about all the related *_LINKER_FLAGS variables that show up in
>> CMakeCache.txt?  Is it necessary to set all of DEBUG, MINSIZEREL, RELEASE,
>> and RELWITHDEBINFO variations as well or is CMAKE_SHARED_LINKER_FLAGS a
>> "master switch" for all those variations?  We don't want to lose the
>> ability
>> to link on Mac OS X just when we make a release.
>
> CMAKE_SHARED_LINKER_FLAGS will be used for all configurations.  The
> variables with per-configuration names are appended to the main
> variable's value for their respective configuration.

Thanks for that information.  Once again, you have been most helpful.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list