[CMake] add_library and PARENT_SCOPE

mbritton at astro.caltech.edu mbritton at astro.caltech.edu
Thu Mar 5 10:22:45 EST 2009


Hello:

I am trying to assemble sources that are distributed across a number of
subdirectories into a variable for inclusion in an add_library command.
I've tried using PARENT_SCOPE to do so, but I haven't been successful.

Here is a specific example:

toplevel CMakeLists.txt:

  cmake_minimum_required(VERSION 2.6)

  add_subdirectory(sub)

  message(status " subfiles ${subfiles}")

  add_library(tst ${subfiles})


CMakeLists.txt in subdirectory sub:

  set(subfiles file.cpp PARENT_SCOPE)


Output from cmake version 2.6-patch 3

  -- The C compiler identification is GNU
  -- The CXX compiler identification is GNU
  -- Check for working C compiler: /usr/bin/gcc
  -- Check for working C compiler: /usr/bin/gcc -- 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
  status subfiles file.cpp
  -- Configuring done
CMake Error in CMakeLists.txt:
  Cannot find source file "file.cpp".  Tried extensions .c .C .c++ .cc
.cpp .cxx
  .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx


-- Build files have been written to: /home/matthew/tmp/build


As you can see, the variable ${subfiles} is set correctly, but does not
seem to be expanded when placed into the add_library command.


Sincerely yours
Matthew



More information about the CMake mailing list