[CMake] Finding internal libraries

John LaGrone jlagrone at smu.edu
Wed Jul 8 13:14:50 EDT 2015


I am trying to build a library along with examples on how to use the 
library. For simplicity, let's say the structure is

CMakeLists.txt
src/
     CMakeLists.txt
     foo.c
     foo.h
examples/
     CMakeLists.txt
     ex1/
        CMakeLists.txt
        ex1.c
     ex2/
        CMakeLists.txt
        ex2.c

The cmake files for the examples are simple and look like

     cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(ex1)
find_package(foo REQUIRED)
add_executable(ex1.x ex1.c)
target_link_libraries(ex1.x foo)

As I currently have it, I can built the library "foo" and install it 
with all the configuration files, etc. that it needs and everything with 
that process seems fine. I can then build the examples and everything 
works fine with that process as well. However, if I try to build the 
examples and the library at the same time, the configuration fails 
because it cannot find the library "foo" for examples because it has not 
been compiled.

I know I can build everything at once and it will work, but I would like 
to keep the cmake files for the examples essentially as they are so they 
can serve as a simple example of how an user might link to the library. 
Can this be done through Cmake or should I just write the documentation 
to indicate that the library needs to be compiled/installed then the 
examples can be built?

Thanks,
John


More information about the CMake mailing list