[CMake] Searching for an undefined symbol in library

Michael Wild themiwi at gmail.com
Tue Nov 16 03:16:37 EST 2010


On 11/15/2010 06:41 PM, Marek Szuba wrote:
> On Mon, 15 Nov 2010 12:00:04 -0500
> cmake-request at cmake.org wrote:
> 
>> How do you select which of the libraries to use? Based on your
>> Fortran compiler?
> To be exact, based on the Fortran compiler used to build the
> binary-only library.
> 
>> If so, I would check for the CMAKE_Fortran_COMPILER_ID variable and
>> then go on from there.
> Hmm. I've looked at CMakeDetermineFortranCompiler.cmake and it seems to
> me the variable you've mentioned is related to the compiler available
> in the system. Is that correct? If so, I am afraid this is not what I
> need. Consider the following two scenarios:
>  - the system has got both the GNU and the PGI compiler, the library
>    variant is for the latter, CMake chooses the former. The program
>    fails to build due to resolved PGI symbols;
>  - the system has got both the GNU and the PGI compiler, the library
>    variant is for the former, CMake chooses the latter. The program
>    ends up unnecessarily linked against PGI run-time libraries,
>    possibly causing binary-portability problems.
> 
> I am of course aware I could override CMake's detection routines to
> choose a specific compiler. However, what I would like to do here is
> have the selection happen automatically depending on the variant of the
> binary-only library... Our user base is of the semi-educated sort,
> familiar with the concept of building the software from source but
> tending to run to us with questions when such building doesn't "just
> go".
> 
> Cheers,

That's kind of recursive... I was asking for the criteria by which you
select the binary-only library. But apparently that choice is made by
the "user", right? You have to detect which of the versions he has
installed?

Either go along with Alex' suggestion (or a variation thereof) or do it
the easy way: Define a cache variable (e.g. LIBX_REQUIRES_PGI) and make
it the responsibility of the user to make the choice. Another way would
be to simply require that the user selects the appropriate compiler
according to the library he has. Then you could do a simple try_compile
to find out whether things work and otherwise error out. The user can
select the compiler in various ways, the easiest is to set the FC
environment variable when invoking CMake, e.g:

$ FC=pgf90 cmake /path/to/source

HTH

Michael


More information about the CMake mailing list