Reputation: 948
I am trying to make a library. My CMakeLists.txt looks something like this:
add_library(Lib STATIC)
set_target_properties(Lib PROPERTIES
VERSION 0.1)
export(TARGETS Lib
FILE ${BIN_DIR}/LibConfig.cmake)
When an outside project uses this library, CMake shows the error:
CMake Error at CMakeLists.txt:10 (find_package):
Could not find a configuration file for package "Lib" that is
compatible with requested version "0.1".
The following configuration files were considered but not accepted:
some directory/Lib/bin/LibConfig.cmake, version: unknown
Looking at the generated LibConfig.cmake, nothing is wrong except that it doesn't carry the version information.
Upvotes: 0
Views: 1879
Reputation: 1974
To allow CMake determining the version of your library, you need to create a LibConfigVersion.cmake
file.
An example can be found in the CMake documentation: generating package files
For your library, this results in something like this:
add_library(Lib STATIC)
set_target_properties(Lib PROPERTIES VERSION 0.1)
export(TARGETS LibFILE ${BIN_DIR}/LibConfig.cmake)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(${BIN_DIR}/LibConfigVersion.cmake
VERSION 0.1
COMPATIBILITY SameMajorVersion)
Instead of providing the version information multiple times, you may set it once in the project
command:
project(Lib VERSION 0.1)
Upvotes: 1