[CMake] Dependency problem with 2.8.0 (but not 2.8.2+)

Raymond Wan r.wan at aist.go.jp
Tue May 17 05:17:15 EDT 2011


Hi all,

I'm having a problem with cmake giving me an error about attempting to
add a Boost library to a target.  However, I have confirmed that my
CMakeLists.txt works fine in 2.8.2 and 2.8.4; however, it doesn't work
in 2.8.0.  Unfortunately, I'm trying to get it work on a machine
running on 2.8.0 and before doing a user install of cmake 2.8.4 (I'm
not a sysadmin of this machine), I was wondering if I can fix my
problem another way.

Actually, I'm also curious if I'm just doing something wrong and
2.8.2+ has just been lenient on me so far...

Basically, I have three parts:  prog, func1, and func2.  They depend
on each other like this:

prog --> func2 and func1
func2 --> func1

That is, prog depends on both func1 and func2; func2 depends on func1.
 Each one has a main () test driver to perform module-level testing,
but the most important main () is in prog.

The 3 CMakeLists.txt are as follows [I've cut out things which I think
aren't relevant to keep this message short].  Also,
ADD_SUBDIRECTORY_ONCE adds a subdirectory once to the list of included
directories (from [1]).

####################
##  prog
IF (NOT TARGET main)
  ADD_EXECUTABLE (main ${MAIN_SRCS})
  TARGET_LINK_LIBRARIES (main func1_ar func2_ar)
ENDIF (NOT TARGET main)

IF (NOT TARGET main_ar)
  ADD_LIBRARY (main_ar ${MAIN_SRCS})
ENDIF (NOT TARGET main_ar)

INCLUDE_DIRECTORIES (func1 func2)
ADD_SUBDIRECTORY_ONCE (func1)
ADD_SUBDIRECTORY_ONCE (func2)
ADD_DEPENDENCIES (main func1)
ADD_DEPENDENCIES (main func2)

####################
##  func1
IF (NOT TARGET func1-test)
  ADD_EXECUTABLE (func1-test func1-main.cpp ${FUNC1_SRCS})
ENDIF (NOT TARGET func1-test)

IF (NOT TARGET func1_ar)
  ADD_LIBRARY (func1_ar ${FUNC1_SRCS})
  SET_TARGET_PROPERTIES (func1_ar PROPERTIES OUTPUT_NAME "func1")
ENDIF (NOT TARGET func1_ar)

##  Check for Boost (not shown)

MESSAGE ("** Checking Boost in func1")

IF (Boost_FOUND)
  IF (TARGET func1-test)
    LINK_DIRECTORIES ( ${Boost_LIBRARY_DIRS} )
    INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})
    TARGET_LINK_LIBRARIES (func1-test ${Boost_LIBRARIES})
  ENDIF (TARGET func1-test)
ENDIF()


####################
##  func2
IF (NOT TARGET func2-test)
  ADD_EXECUTABLE (func2-test func2-main.cpp ${FUNC2_SRCS})
ENDIF (NOT TARGET func2-test)

IF (NOT TARGET func2_ar)
  ADD_LIBRARY (func2_ar ${FUNC2_SRCS})
  SET_TARGET_PROPERTIES (func2_ar PROPERTIES OUTPUT_NAME "func2")
ENDIF (NOT TARGET func2_ar)

INCLUDE_DIRECTORIES (../func1)
ADD_SUBDIRECTORY_ONCE (../func1 ${CMAKE_CURRENT_BINARY_DIR}/func1)
ADD_DEPENDENCIES (func1-test ../func1)


When I run cmake 2.8.0, I get this output:

-- The CXX compiler identification is GNU
-- 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
-- Boost version: 1.46.0
-- Found the following Boost libraries:
--   program_options
--   system
--   filesystem
** Checking Boost in func1
** Checking Boost in func1
CMake Error: Attempt to add link library
"/usr/local/boost_1_46_0/lib/libboost_program_options.a" to target
"func1-test" which is not built by this project.
CMake Error: Attempt to add link library
"/usr/local/boost_1_46_0/lib/libboost_system.a" to target "func1-test"
which is not built by this project.
CMake Error: Attempt to add link library
"/usr/local/boost_1_46_0/lib/libboost_filesystem.a" to target
"func1-test" which is not built by this project.
-- Configuring incomplete, errors occurred!

With cmake 2.8.2 (and 2.8.4), I get this:

-- The CXX compiler identification is GNU
-- 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
-- Boost version: 1.46.0
-- Found the following Boost libraries:
--   program_options
--   system
--   filesystem
** Checking Boost in func1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rwan/tmp/cmake/prog/build


So, there are no errors with 2.8.2+.  But also of interest is that "**
Checking Boost in func1" appears once here but twice with 2.8.0, which
I thought was strange...

If this is indeed a bug in 2.8.0 that has since been fixed, then I'm
quite happy to just make the cmake minimum requirement to 2.8.2 and
leave it at this.  :-)  But I am now wondering if there is something
that I've done in my CMakeLists.txt that is wrong that I should be
correcting.

I'd appreciate any suggestions and sorry for the long posting!  Thank you!

Ray


[1]  http://www.cmake.org/pipermail/cmake/2010-December/041150.html


More information about the CMake mailing list