CMake: CMake config files are defining CURL_STATICLIB for static builds#2823
CMake: CMake config files are defining CURL_STATICLIB for static builds#2823Adnn wants to merge 2 commits into
Conversation
This change allows to use the CMake config files generated by Curl's CMake scripts for static builds of the library. The symbol CURL_STATIC lib must be defined to compile downstream, thus the config package is the perfect place to do so. Fixes curl#2817 Reported-by: adnn
|
The Travis failures were caused by download failures, I've restarted the jobs. This looks generally good to me, but shouldn't the condition for library users defining |
|
@MarcelRaad Thank you for your review and restarting the job (is the failed result below the first attempt, or did the restart also fail?) I am not sure to understand what is your suggestion? Sadly, I am not familiar with this build system, but I think you are referring to an Automake file, and it seems unlikely that CMake share the same variables? Anyway, the CMake variable allowing the user to request a static build is indeed Do you have an alternative in mind? |
|
The Travis failure is from the restarted build, but looks unrelated as it's from an autotools build. Sorry, you're right, What I was looking for is where |
|
The failed travis build is the mysterious new mac fail due some weirdo SecureTransport thing that started showing up recently! =( @nickzman can you figure out why this happens now on travis? It looks like it doesn't happen every time which is even worse... |
|
@MarcelRaad The CURL_STATICLIB define sits here: https://github.com/Adnn/curl/blob/master/lib/curl_config.h.cmake#L80 . If the CURL_STATICLIB CMake option is set, this line https://github.com/Adnn/curl/blob/master/lib/CMakeLists.txt#L3 will bring it to life ;) |
|
@jzakrzewski Thank you for that explanation, TIL about |
|
Well, that's bizarre. What's happening is SSLCopyALPNProtocols() and SSLSetALPNProtocols() are defined in the Secure Transport headers, but Apple did not actually implement the functions in the Security framework until macOS 10.13.4 (which is Darwin 7.5.0), and this particular computer is using a pre-.4 point release of macOS 10.13. Those functions are behind __builtin_available(), so they won't be executed if the user is using an older OS than 10.13.4. But the SecureTransport.h header incorrectly specifies that the function became available in 10.13.0, so I think the linker is trying to hard-link to the function, and that would explain the undefined symbols error you are seeing. Upgrading the OS on Travis' side would solve the problem. You could also solve it by using the -mmacosx-version-min compiler flag set to 10.12 or earlier to force it to weak-link the symbol. I would recommend you just upgrade the OS, since stock 10.13 had a catastrophic security hole you may have heard about, and there have been other security holes patched as well. |
MarcelRaad
left a comment
There was a problem hiding this comment.
Note that I'm none of the CMake experts, but this looks good to me.
|
As @jzakrzewski already mentioned, CURL_STATICLIB will be set through curl_config.h and not through compiler command line. Latest master (ref #2755) slightly changed behavior to control build static/shared by using Resulting curl_config.h will be @Adnn should we close this or you have objections? |
|
@snikulov But curl_config.h is not meant for inclusion by users of libcurl, or is it? If I understood correctly, |
|
@snikulov I am not sure to follow, do you propose to discard the PR? @MarcelRaad You are right about the |
|
|
|
@Adnn @MarcelRaad now I see what you mean. |
|
@snikulov should I take that as a 👍 from you on merging this? |
|
@bagder not exactly. |
snikulov
left a comment
There was a problem hiding this comment.
Use BUILD_SHARED_LIBS option in condition check
| set_target_properties(${LIB_NAME} PROPERTIES STATIC_LIBRARY_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) | ||
| endif() | ||
|
|
||
| if(CURL_STATICLIB) |
There was a problem hiding this comment.
@Adnn maybe change it to if(NOT BUILD_SHARED_LIBS) ?
|
Hi, If that sounds sensible, I'll update my PR |
|
@Adnn I see no cases where |
|
@snikulov Thank you for your feedback. It should not be different, but it could be more future-proof. Any reason for avoiding |
|
@Adnn another reason - less code. |
|
@bagder could you please merge it? Thank you. |
|
Thanks! |
This change allows to use the CMake config files generated by Curl's
CMake scripts for static builds of the library.
The symbol CURL_STATIC lib must be defined to compile downstream,
thus the config package is the perfect place to do so.
Fixes #2817
Reported-by: adnn