Modules/FindLibXml2.cmake sets LIBXML2_LIBRARIES even if libxml2 was not found
Hello,
I noticed some strange behaviour of Modules/FindLibXml2.cmake. Even if libxml2 is not found on a system, the variable LIBXML2_LIBRARIES is set (to LIBXML2_LIBRARIES-NOTFOUND if I'm correct). I'd expect that LIBXML2_LIBRARIES remains empty if libxml2 is not found.
See this simple example below on a system without libxml2. I'd assume that this should work.
Modules/FindLibXml2.cmake calls find_library(LIBXML2_LIBRARIES ...), which sets LIBXML2_LIBRARIES in any case. It seems to me that other FindXXX modules use a temporary variable for find_library() and assign this temporary variable to an output variable if the library was found.
If you agree that this is a cmake bug, I can try to create a patch.
Best regards, Martin
martin@reykholt:~/src/cmXml$ cat bar.c
int main(void)
{
return 0;
}
martin@reykholt:~/src/cmXml$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
find_package(LibXml2)
add_executable(foo bar.c)
target_link_libraries(foo ${LIBXML2_LIBRARIES})
martin@reykholt:~/src/cmXml$ mkdir build
martin@reykholt:~/src/cmXml$ cd build/
martin@reykholt:~/src/cmXml/build$ cmake ..
-- Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBXML2_LIBRARIES (ADVANCED)
linked by target "foo" in directory /home/martin/src/cmXml
-- Configuring incomplete, errors occurred!