Finding internal libraries

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Finding internal libraries

John LaGrone
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
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding internal libraries

Stephen Kelly-2
John LaGrone wrote:

> 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, ...

I don't understand. Does building the examples and lib (ie, 'everything')
together work or not?

Thanks,

Steve.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding internal libraries

John LaGrone
In reply to this post by John LaGrone
On 07/08/2015 06:52 PM, [hidden email] wrote:

>> 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)
>
> I don't understand. Does building the examples and lib (ie, 'everything')
> together work or not?
>
> Thanks,
>
> Steve.

If I remove the "find_package(foo REQUIRED)" line or don't make it
required, everything compiles. With the find_package command in place,
the build fails at the configuration stage because it cannot find the
package foo since it has not been built/installed. I think this makes
perfect sense, but was wondering if there was a way to keep the
find_package commands in the examples because it more accurately
reflects a typical usage and hence makes for a better example.

Thanks,
John

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding internal libraries

Petr Kmoch
Hi John.

I have no first-hand experience with it, but I believe the ExternalProject module could be just what you're looking for ( http://www.cmake.org/cmake/help/v3.2/module/ExternalProject.html ). It allows you to configure and build several projects at build time under a CMake "superbuild" master project, while the "subprojects" themselves remain unaware of this setup.

Petr

On Thu, Jul 9, 2015 at 5:18 PM, John LaGrone <[hidden email]> wrote:
On 07/08/2015 06:52 PM, [hidden email] wrote:

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)

I don't understand. Does building the examples and lib (ie, 'everything')
together work or not?

Thanks,

Steve.

If I remove the "find_package(foo REQUIRED)" line or don't make it required, everything compiles. With the find_package command in place, the build fails at the configuration stage because it cannot find the package foo since it has not been built/installed. I think this makes perfect sense, but was wondering if there was a way to keep the find_package commands in the examples because it more accurately reflects a typical usage and hence makes for a better example.

Thanks,
John


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding internal libraries

Ruslan Baratov
In reply to this post by John LaGrone
John LaGrone wrote
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)
Just check that library exists already:

if(NOT TARGET foo)
  find_package(foo REQUIRED)
endif()