Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow linking to extra libs static when not using find_package() #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

khangthk
Copy link

@khangthk khangthk commented Jul 13, 2024

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

image

@michaelonken
Copy link
Member

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?

@khangthk
Copy link
Author

khangthk commented Jul 15, 2024

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

@michaelonken
Copy link
Member

Oh, wow, you're right, for some reason I never realized those in DCMTK 😄 I will get back to you.

@khangthk
Copy link
Author

khangthk commented Jul 16, 2024

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 ......

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants