Myproject/CMakeLists.txt:
find_package(Foo 2.0 EXACT REQUIRED)
Foo/CMakeLists.txt:
set(Foo_SOVERSION 1)
set(Foo_VERSION ${Foo_SOVERSION}.8)
为什么cmake Myproject
不会失败?它只会通知
-- Found Foo: /usr/local/lib/libfoo.so (Required is exact version "2.0")
并愉快地前进。如果没有满足确切的要求,如何强制终止?
答案 0 :(得分:1)
如果您还编写了 FindFoo.cmake
宏,那么您可以在宏中添加如下内容以强制执行版本检查。
if(FOO_FIND_VERSION)
# Add a version check logic and set FOO_FOUND as true conditionally
else()
set(FOO_FOUND TRUE)
endif()
有关详细信息,请参阅 https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules。