Skip to content
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

Findsodium.cmake doesn't support looking for static libsodium and falling back to looking for static one on Windows #757

Closed
nurupo opened this issue Sep 24, 2018 · 2 comments

Comments

@nurupo
Copy link

nurupo commented Sep 24, 2018

Expected:

I use Findsodium.cmake without defining sodium_USE_STATIC_LIBS on Windows. It will look for shared libsodium libraries first and if not found, it will fallback to looking for static ones. This behaviour would be consistent with the one on Linux, as on Linux Findsodium.cmake would check pkg-config, which would tell it to -lsodium, and the compiler would link to whatever sodium is available, by default trying shared first and then static.

Observed:

Findsodium.cmake looks for libraries based on library filename, which is fine, but it will look either only for .dll or only for .a/.lib depending on what sodium_USE_STATIC_LIBS is set to, which is not fine. It looks either for shared libraries or for static. It has no mechanism of falling back. On Linux it would fallback searching for static libraries if shared weren't found, but not on Windows. If you try to be smart and try to make it fallback like that:

set(sodium_USE_STATIC_LIBS OFF)
find_package(sodium)
if (NOT sodium_FOUND)
  set(sodium_USE_STATIC_LIBS ON)
  find_package(sodium REQUIRED)
endif()

the second find_package(sodium) will always fail because it tries to create a sodium target, but it already exists, the first call to find_package(sodium) creates it unconditionally, no matter if it does or doesn't find the library:

-- Could NOT find sodium (missing:  sodium_LIBRARY_RELEASE sodium_LIBRARY_DEBUG) 
-- Found sodium: /root/prefix/i686/lib/libsodium.a  
CMake Error at cmake/Findsodium.cmake:251 (add_library):
  add_library cannot create imported target "sodium" because another target
  with the same name already exists.
Call Stack (most recent call first):
  cmake/Dependencies.cmake:31 (find_package)
  CMakeLists.txt:123 (include)
@jedisct1
Copy link
Owner

Hi,

And thanks for reporting this. Would you be able to submit a pull request to fix this?

@vlad230
Copy link

vlad230 commented Oct 15, 2018

I got the latest code libsodium-1.0.16-mingw.tar.gz but still can't use sodium for a project.
I'm getting the same issue as above:
Could NOT find sodium (missing: sodium_LIBRARY_RELEASE sodium_LIBRARY_DEBUG) CMake Error at CMakeLists.txt:9 (MESSAGE): libsodium is required

What can I do to fix it?
To which files should sodium_LIBRARY_RELEASE & sodium_LIBRARY_DEBUG point to?

@jedisct1 jedisct1 closed this as completed Dec 6, 2018
Repository owner locked and limited conversation to collaborators Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants