[CMake] generator expressions

Andrew Fuller mactalla.obair at gmail.com
Fri Jun 6 11:07:26 EDT 2014


On Fri, Jun 6, 2014 at 6:08 AM, Brad King <brad.king at kitware.com> wrote:
>
> I cannot reproduce these.  Can you provide a complete CMakeLists.txt
> example please?
>
>
Attached (I hope the mailing list accepts attachments) is a demonstration
of the problem.  In creating it I discovered that a target created by
add_executable does not seem to exhibit the problem.  So the more exact
situation is: using a generator expression to guard a list of more than one
entry on target_link_libraries where the target itself is a library.

Let me know if the attahced .zip doesn't make it.  The .zip file contains
the CMakeLists.txt, a helloworld program and a script to run through the
iterations the output of which is:

$./run.sh

Testing linking to a single lib.
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Testing a single library guarded by a generator expression. This works.
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/afuller/src/slow/cmakelink/test/single
Scanning dependencies of target random
[ 50%] Building CXX object CMakeFiles/random.dir/random.cpp.o
Linking CXX static library librandom.a
[ 50%] Built target random
Scanning dependencies of target hello
[100%] Building CXX object CMakeFiles/hello.dir/helloworld.cpp.o
Linking CXX executable hello
[100%] Built target hello

Testing linking to multiple libs.
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Testing a list of libraries guarded by a generator expression. This
leaks all but the first.
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/afuller/src/slow/cmakelink/test/multi
Scanning dependencies of target random
[ 50%] Building CXX object CMakeFiles/random.dir/random.cpp.o
Linking CXX static library librandom.a
[ 50%] Built target random
Scanning dependencies of target hello
[100%] Building CXX object CMakeFiles/hello.dir/helloworld.cpp.o
Linking CXX executable hello
/usr/bin/ld: cannot find -lsecondwindows.lib
collect2: error: ld returned 1 exit status
make[2]: *** [hello] Error 1
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2

Observing what happens with $<JOIN...> in an unused generator expression.
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Testing $<JOIN:...> inside an inactive generator expression (you are
building on Linux, right?). This plugs the leak.
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/afuller/src/slow/cmakelink/test/joinunused
Scanning dependencies of target random
[ 50%] Building CXX object CMakeFiles/random.dir/random.cpp.o
Linking CXX static library librandom.a
[ 50%] Built target random
Scanning dependencies of target hello
[100%] Building CXX object CMakeFiles/hello.dir/helloworld.cpp.o
Linking CXX executable hello
[100%] Built target hello

Observing what happens with $<JOIN...> in a used generator expression.
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Testing $<JOIN:...> inside an active generator expression (you are
building on Linux, right?). Gives a CMake syntax error.
-- Configuring done
CMake Error:
  Error evaluating generator expression:

    $<JOIN:libXrandr.a>

  $<JOIN> expression requires 2 comma separated parameters, but got 1
  instead.


CMake Error:
  Error evaluating generator expression:

    $<JOIN:libXrandr.a>

  $<JOIN> expression requires 2 comma separated parameters, but got 1
  instead.


CMake Error:
  Error evaluating generator expression:

    $<JOIN:libXrandr.a>

  $<JOIN> expression requires 2 comma separated parameters, but got 1
  instead.


CMake Error:
  Error evaluating generator expression:

    $<JOIN:libXrandr.a>

  $<JOIN> expression requires 2 comma separated parameters, but got 1
  instead.


CMake Error:
  Error evaluating generator expression:

    $<JOIN:libXrandr.a>

  $<JOIN> expression requires 2 comma separated parameters, but got 1
  instead.


CMake Error:
  Error evaluating generator expression:

    $<JOIN:libXrandr.a>

  $<JOIN> expression requires 2 comma separated parameters, but got 1
  instead.


-- Generating done
-- Build files have been written to:
/home/afuller/src/slow/cmakelink/test/joinused
$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140606/8c125599/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: conditionallibs.zip
Type: application/zip
Size: 1783 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140606/8c125599/attachment-0001.zip>


More information about the CMake mailing list