[CMake] TARGET_SUPPORTS_SHARED_LIBS not set

Nico Schlömer nico.schloemer at gmail.com
Tue Sep 11 13:48:20 EDT 2012


> Compiler is not supposed to be set y a call to find_package.

Hm, I understand. Strictly speaking, FIND_PACKAGE(Foobar) doesn't
override CMAKE_C_FLAGS or anything like that, but rather provides a
number of extra variables that the user can then exploit.
The idea of using the same compiler is to assure binary compatibility
between the library and what I compile. Foobar (actually: Trilinos) is
a numerical library that's often deployed in HPC environments with a
number of mutually incompatible compilers, which is why I deemed it
useful to make sure the compilers are the same/compatible.

Now apparently this isn't very cmaky. Would rather recommend using CC
& friends and then checking things with

IF(${CMAKE_C_COMPILER} NOT STREQUAL ${Foobar_C_COMPILER})

?


On Tue, Sep 11, 2012 at 7:33 PM, Eric Noulard <eric.noulard at gmail.com> wrote:
> 2012/9/11 Nico Schlömer <nico.schloemer at gmail.com>:
>> Indeed, that gets set up by the PROJECT() call.
>>
>> Now, this creates a little bit of a problem here.
>> The main CMakeLists.txt looks something like
>>
>> =============== *snip* ===============
>> CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
>>
>> FIND_PACKAGE(Foobar REQUIRED)
>>
>> # Set compilers before the PROJECT is declared.
>> SET(CMAKE_CXX_COMPILER ${Foobar_CXX_COMPILER})
>>
>> PROJECT(MyProject CXX)
>> [...]
>> =============== *snap* ===============
>>
>> Evidently, FIND_PACKAGE() must be called before PROJECT(),
>> specifically before TARGET_SUPPORTS_SHARED_LIBS is set.
>
> Nope I think your usage is not supported.
> Compiler is not supposed to be set y a call to find_package.
>
> Compiler may be define:
>   - By CMake discovery during project(...) command processing
>   - By a [cross-compiling] toolchain file provided on the command line
>     (or to cmake-gui)
>   - By CMakeForceCompiler module
>     see cmake --help-module CMakeForceCompiler
>
>> However, the Foobar package not only defines some compiler variables,
>> but also includes libraries like
>>
>> ADD_LIBRARY(barfoo SHARED IMPORTED)
>>
>> Those ADD_LIBRARY(... SHARED ...) calls however check for
>> TARGET_SUPPORTS_SHARED_LIBS and choke if it is not defined.
>>
>> What could be identified as the bug here?
>
> Defining compiler inside find package.
> How did you get the "FindFoobar.cmake"  file?
>
> --
> Erk
> Le gouvernement représentatif n'est pas la démocratie --
> http://www.le-message.org


More information about the CMake mailing list