-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmake: fix pkgconfig and cmake interaction #471
Conversation
Adding @diizzyy, @dg0yt and @jimwang118 for review. |
It hardlinks libminizip and library paths gets omitted but it works as long as you already have paths in place
|
That is probably okay but not great. Let me have another look. |
You may use |
30777ca
to
35bddac
Compare
I had a look at this and the output is the same in each case according to LDD. However, I have updated the fix to just avoid using pkgconf when compiling for MSVC. This seems the simplest and in line with the vcpkg fix that @dg0yt proposed. I'm presuming that I don't also need to add extra sentinel checks like this?: diff --git a/CMakeLists.txt b/CMakeLists.txt
index 969e3808..49b6daa4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -311,17 +311,17 @@ target_sources(${PROJECT_NAME}
PRIVATE ${LXW_SOURCES}
PUBLIC ${LXW_HEADERS}
)
-if(ZLIB_LDFLAGS)
+if(NOT MSVC AND ZLIB_LDFLAGS)
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${ZLIB_LDFLAGS})
else()
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${ZLIB_LIBRARIES})
endif()
-if(MINIZIP_LDFLAGS)
+if(NOT MSVC AND MINIZIP_LDFLAGS)
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${MINIZIP_LDFLAGS})
else()
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${MINIZIP_LIBRARIES})
endif()
-if(LIBCRYPTO_LDFLAGS)
+if(NOT MSVC AND LIBCRYPTO_LDFLAGS)
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${LIBCRYPTO_LDFLAGS})
else()
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${LIB_CRYPTO} ${OPENSSL_CRYPTO_LIBRARY}) |
@@ -228,18 +230,19 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | |||
if(PKG_CONFIG_FOUND) | |||
pkg_check_modules(ZLIB zlib) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW this is not marked REQUIRED
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is intentional. For me, at least, it isn't a requirement. @diizzyy can comment on whether it is a requirement or a nice to have.
I've always presumed that Cmake just does the same thing via findpackage
and additional logic/searching. Unlike meson which (afaik) relies on pkgconf more (at least on Unix).
CMakeLists.txt
Outdated
@@ -228,18 +230,19 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | |||
if(PKG_CONFIG_FOUND) | |||
pkg_check_modules(ZLIB zlib) | |||
list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) | |||
else(NOT ZLIB_FOUND) | |||
else() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the original intention might have been:
else() | |
endif() | |
if(NOT ZLIB_FOUND) |
(and similar below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. You are probably correct that was the intention: in case pkgconf is available but still doesn't find the required lib.
@diizzyy was that the intention?
The intention was to mimic the logic already in use as close as possible, elseif is "new" syntax according to CMake's documentation and else with args will probably be deprecated at some point (tm). Given that target is still ancient versions I went for the old variant. I didn't define REQUIRED as that would prevent CMake from trying to find the requested library using the "fallback" logic. Wrapping find_package(PkgConfig) seems to indeed be the easiest solution. |
35bddac
to
cd1510e
Compare
I made some of the simplifying changes and updated the PR if folks would like to have a look.
I need to clean up the CMakeList.txt file and remove some of the cruft. Bumping to a more recent version of CMake should be part of that. Any suggestions on what is a reasonable version to support? |
The variable _LINK_LIBRARIES is explained on the cmake official website as containing the library with the corresponding path, so directly linking this variable can accurately find the library. |
Recent versions of CMake warn when |
Thanks for the help folks. I have merged the changes to main. I have some other small changes to make and they I will release another vcpkg version to close the issues/PRs there. |
If you want to re-enable pkgconfig in the vcpkg port, it must also work for MSVC. |
Personally I don't want to enable it in
Does pc here mean portfile.cmake? (https://github.com/microsoft/vcpkg/blob/master/ports/libxlsxwriter/portfile.cmake) or the generated .pc file. Could you explain this a bit more. |
vcpkg has working pkg-config also for Windows. One just has to be aware of using
"pc file" refered to the module file for pkg-config, suffix This is the patch I refered to: |
Proposed fix for microsoft/vcpkg#43653
Fixes previous PR #454