regression when building CMake projects against release 1.1.7
In applications using cmocka built with CMake I used this before:
find_package(cmocka 1.0 REQUIRED CONFIG)
and later:
target_link_libraries(myapp
${CMOCKA_LIBRARIES}
)
This worked with all versions from 1.0 to 1.1.5, but not with 1.1.7 anymore. Build results in a linker error, because ${CMOCKA_LIBRARIES}
is empty now.
The problem was introduced, when file cmocka-config.cmake.in was removed with f24ef3ce, when instead it should have been rewritten for modern CMake use.
A working solution would be to set CMOCKA_LIBRARIES
in cmocka-config.cmake.in to something like cmocka::cmocka
so old projects would just build as before.
However since e4c51ce9 that file is not generated by configure_package_config_file()
anymore but directly through install(TARGETS cmocka EXPORT cmocka-config …
and install(EXPORT …
now. Considering the note in CMake documentation I'm not sure this is the way it is meant to be used. cmake-packages(7) suggests to install targets into a file named differently and include that on from the package config. In other projects I found a package config like this to be working with modern namespaced targets and backwards compatible variables (shamelessly copied and stripped from libcgi):
#
# Copyright 2013,2016–2019 Alexander Dahl <post@lespocky.de>
#
# paths
@PACKAGE_INIT@
set_and_check(CGI_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/libcgi")
# targets
get_filename_component(cgi_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
if(NOT TARGET cgi::cgi)
include("${cgi_CMAKE_DIR}/cgi-targets.cmake")
endif()
set(CGI_LIBRARIES cgi::cgi)