Allow linking to extra libs static when not using find_package()
I build static libxml2 library with latest code, when building dcmtk with BUILD_SINGLE_SHARED_LIBRARY=ON it gives an error because 'bcrypt.lib' is not linked to. The library 'bcrypt.lib' is required by libxml2 (see here).
After some searching, I found that LIBXML2_EXTRA_LIBS_STATIC can be used to add the 'bcrypt.lib' library. But this item is not available when DCMTK_USE_FIND_PACKAGE is OFF
Thank you for the report. Where is LIBXML2_EXTRA_LIBS_STATIC defined?
I downloaded the latest code of libxml2 via https://github.com/GNOME/libxml2. It seems it does not define LIBXML2_EXTRA_LIBS_STATIC.
Also in your patch I noticed that you add EXTRA libs to other packages, like OPENSSL_EXTRA_LIBS_STATIC. Why?
Thank you for the report. Where is LIBXML2_EXTRA_LIBS_STATIC defined?
I downloaded the latest code of libxml2 via https://github.com/GNOME/libxml2. It seems it does not define LIBXML2_EXTRA_LIBS_STATIC.
Also in your patch I noticed that you add EXTRA libs to other packages, like OPENSSL_EXTRA_LIBS_STATIC. Why?
XXX_EXTRA_LIBS_STATIC has been defined and used before in dcmtk. You can search the source code with the keyword "_EXTRA_LIBS_STATIC" (dcmtk\CMake\3rdparty.cmake and dcmtk\CMake\dcmtkPrepare.cmake) dcmtk has some similar definitions so in my patch I also fixed them although they may not make sense at the moment but may be needed in the future When building dcmtk I will set this value, for example: cmake.exe -D LIBXML2_EXTRA_LIBS_STATIC=bcrypt.lib
Oh, wow, you're right, for some reason I never realized those in DCMTK :smile: I will get back to you.
There is one more issue I have not mentioned. In the file dcmtk\CMake\3rdparty.cmake there is a difference regarding the use of the 'LIBXML_STATIC' macro when the DCMTK_USE_FIND_PACKAGE option is ON and OFF. I summarize the differences in that file as follows:
if(DCMTK_USE_FIND_PACKAGE)
if(DCMTK_WITH_XML)
if(NOT LIBXML2_FOUND)
......
else()
.......
set(WITH_LIBXML 1)
endif()
endif()
else()
if(DCMTK_WITH_XML)
if(WITH_LIBXMLINC)
......
set(WITH_LIBXML 1)
# this hides some warnings that are emitted when linking against libxmlXXX.lib instead of linking the DLL directly
add_definitions("-DLIBXML_STATIC")
else()
......
endif()
endif()
endif()
When DCMTK_USE_FIND_PACKAGE is set to ON, the build fails because the LIBXML_STATIC macro cannot be found. If I add line add_definitions("-DLIBXML_STATIC") after set(WITH_LIBXML 1) it builds OK. I only tested on Windows. Append compiler flags can easily fix this problem, so I think it doesn't matter:
cmake.exe -E env CXXFLAGS="/DLIBXML_STATIC" cmake.exe ......
Merged into DCMTK's testing branch.