Skip to content

Conversation

@65a
Copy link
Contributor

@65a 65a commented May 29, 2025

Fixes #13902

Separates out header installation and performs it regardless of build shared libs or not. Adds STATIC mtmd objects to link to (same name as before *_static.a), installing those if BUILD_SHARED_LIBS is off. This should allow for static linking without breaking build encapsulation or visibility, and install the headers as before for shared libs.

Make sure to read the contributing guidelines before submitting a PR

@65a 65a changed the title cmake: mtmd: install PUBLIC_HEADERs and allow static linking cmake: mtmd: install PUBLIC_HEADERs and allow static linking (#13902) May 29, 2025
@65a
Copy link
Contributor Author

65a commented May 29, 2025

Found an existing typo in CMakeLists.txt. I'll push that squashed into the commit once it's clear the approach works on Windows, which was causing some checks to fail.

Separates out header installation and performs it regardless of build shared libs or not.
Adds mtmd STATIC objects, installing those if BUILD_SHARED_LIBS is off.
This should allow for static linking without breaking build encapsulation or visibility, and install the headers as before for shared libs.
Fixes a possible type when BUILD_SHARED is enabled (mtmd vs mtmd_shared as the TARGET_OBJECTS target)

set(MTMD_PUBLIC_HEADERS
"mtmd.h"
"clip.h")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clip.h is not a public header, we should remove it

Comment on lines +51 to +57
else()
add_library(mtmd_static STATIC $<TARGET_OBJECTS:mtmd>)
set_target_properties(mtmd_static PROPERTIES PUBLIC_HEADER "${MTMD_PUBLIC_HEADERS}")
add_library(mtmd_helper_static STATIC $<TARGET_OBJECTS:mtmd_helper>)
set_target_properties(mtmd_helper_static PROPERTIES PUBLIC_HEADER "${MTMD_HELPER_PUBLIC_HEADERS}")
install(TARGETS mtmd_static LIBRARY PUBLIC_HEADER PUBLIC_HEADER)
install(TARGETS mtmd_helper_static LIBRARY PUBLIC_HEADER)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be redundant. If anything in the project need mtmd_helper, we can simply link the target binary with it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example:

target_link_libraries(${TARGET} PRIVATE common mtmd mtmd_helper ${CMAKE_THREAD_LIBS_INIT})

So, nothing need to be STATIC

@65a
Copy link
Contributor Author

65a commented May 30, 2025

Resolved by @ngxson in #13917

@65a 65a closed this May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mtmd: cmake: C API broken since last change, static linking always broken

2 participants