[CMake] Finding an unexisting library

clinton at elemtech.com clinton at elemtech.com
Sat Jul 20 20:06:05 EDT 2013



----- Original Message -----
> Hello,
> 
> I'm trying to write a CMakeLists that allows linking against a library that
> does not exist yet but that would be created by the build process.
> 
> I'm wondering how I can get find_library() working with such a scheme,
> because if I give it the library name and directory, it'll obviously not
> find it. The non-existing library is created during a configure/make build
> process triggered by a add_custom_target() and I don't think I can have a
> reliable way of knowing the exact output name of the library (especially
> concerning the file extension, or is there a CMake variable for that?).
> 
> I want to use find_library() because it correctly handles the library names
> on the different platforms, and I prefer not to handle this manually.
> 
> Is this possible?
> 

Here are a couple ideas...

1. use execute_process() to do the configure step of the sub project, during the configure time of the parent project.
  If the subproject can export its targets, you can simply include them in the parent project.  Or use find_library() otherwise.  Somewhat similar is the idea of using ExternalProject module to build both the child and parent project.

2. CMake provides variables such as CMAKE_SHARED_LIBRARY_PREFIX/CMAKE_SHARED_LIBRARY_SUFFIX for shared libraries, and CMAKE_STATIC_LIBRARY_PREFIX/CMAKE_STATIC_LIBRARY_SUFFIX for static libraries.  You can use those variables to create the name of the library that will exist at build time.

Clint


More information about the CMake mailing list