[CMake] Using CMake to interface with non-CMake libraries

Zoey McCarthy ZoeyMcCarthy at gmail.com
Sun Jul 24 06:09:10 EDT 2011


Hello everyone,

I am new to using CMake and I am trying to compile a program that uses two 
libraries, one of which needs to be built using CMake, and the other, that 
utilizes its own build system(the Makefiles were generated using ./configure).  
The two libraries are CGAL and SOLID (for collision detection).

CGAL provides a script, cgal_create_cmake_script , that produces the 
CMakeLists.txt file for an executable that includes the CGAL library.  I can 
build my executable fine using cmake and make when I only try to include CGAL.  
When I try to include SOLID, I have issues with finding class definitions during 
linking, i.e. I get errors of the type:

/home/zoeymccarthy/hybrid_PRM/CollisionChecker.h:146: undefined reference to 
`DT_GenResponseClass'

SOLID is installed in /usr/local/include/SOLID/ and /usr/include/SOLID/. The 
header files for the library were installed there, but I have since tried 
copying the rest of the files associated with the library there since the 
compiler was able to locate the header files.


This is the CMakeLists.txt that the CGAL script generated for my project:



# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.


project( hybrid_PRM_demo )

CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5)

set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
 
if ( COMMAND cmake_policy )
  cmake_policy( SET CMP0003 NEW )  
endif()

find_package(CGAL QUIET COMPONENTS Core Qt3 )

if ( CGAL_FOUND )

  include( ${CGAL_USE_FILE} )
  
  find_package(Qt3-patched QUIET )
  # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so
  # that it can be used together with FindQt4: all its variables are prefixed
  # by "QT3_" instead of "QT_".
  
  if(CGAL_Qt3_FOUND AND QT3_FOUND)
  
    include( Qt3Macros-patched )
    qt3_automoc(  main.cpp )

    # Make sure the compiler can find generated .moc files
    include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
  
    include_directories( ${QT3_INCLUDE_DIR} )

    add_executable  (hybrid_PRM_demo  main.cpp)
  
    add_to_cached_list( CGAL_EXECUTABLE_TARGETS hybrid_PRM_demo )
  
  
    # Link the executable to CGAL and third-party libraries
    target_link_libraries(hybrid_PRM_demo ${QT3_LIBRARIES} ${CGAL_LIBRARIES} 
${CGAL_3RD_PARTY_LIBRARIES} )
  else()
  
    message(STATUS "NOTICE: This demo requires Qt3 and the CGAL Qt3 library, and 
will not be compiled.")
  
  endif()
  
else()
  
    message(STATUS "NOTICE: This demo requires the CGAL library, and will not be 
compiled.")
  
endif()




As you can see, there is no reference to SOLID.  How should I modify it so that 
the resulting Makefile will know where to link to my SOLID object files, given 
that SOLID has no .cmake file associated with it, and the library was built 
without any CMakeLists.txt files?  I've tried adding the following two lines:

include_directories(/usr/include/SOLID/)
link_directories(/usr/include/SOLID/)

to the middle of my CMakeLists.txt (before if ( CGAL_FOUND) ), but it results in 
the same error.

I'm sorry if this is a stupid question, but for the life of me I can't get it to 
work.


Thank you for your help,

Zoey



More information about the CMake mailing list