-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Use generator expressions for variables instead of branching ifs, which don't work on multi-config generators. #17042
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
Comments
The condition curl uses here is not In this case, wouldn't it be more straightforward to restore the pre- a1eaa12 if(CURL_HAS_LTO)
if(CMAKE_CONFIGURATION_TYPES)
set_target_properties(${LIB_OBJECT} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
else()
set_target_properties(${LIB_OBJECT} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif() |
@vszakats OK, I've never worked on this library, I'm not familiar with anything, this is just a heads-up to let you know in case you want to do something about it. |
No worries, thanks for reporting this. I was contemplating addressing |
To avoid having LTO enabled for Debug configurations with multi-config generators (e.g. MSVC.) Reported-by: PleaseJustDont Fixes curl#17042 Ref: #curl#17034 Follow-up to a1eaa12 curl#15829 Closes curl#17043
To avoid having LTO enabled for Debug configurations with multi-config generators (e.g. MSVC.) Reported-by: PleaseJustDont Fixes curl#17042 Ref: #curl#17034 Follow-up to a1eaa12 curl#15829 Closes curl#17043
Uh oh!
There was an error while loading. Please reload this page.
I did this
MSVC and XCode are what are known as multi-config generators, and it's not possible to branch on CMAKE_BUILD_TYPE using if statements. Meaning, that if in Curl CMakeLists the condition of whether to enable LTO (interprocedural optimization) looks like this:
if (USE_LTO)
Then it can never work with MSVC or XCode, is my understanding. I guess this is a limitation of CMake.
In my code I want to enable LTO in Debug mode, so I do:
set(CURL_LTO $<$<CONFIG:DEBUG>:TRUE> CACHE BOOL "")
But then when Curl checks this variable to decide whether to enable LTO, it's too early, as generator expressions don't work in if statements.
Suggestion:
As far as I know, generator expressions work with multi-config and non multi-config generators. The relevant part in CMakeLists.txt is:
The user sets CURL_LTO with a generator expression, or a simple set, both should work. And then in the lib CMakeLists.txt:
change:
to
set_target_properties(${LIB_OBJECT} PROPERTIES INTERPROCEDURAL_OPTIMIZATION $<CURL_LTO:TRUE>)
This should work on CURL_LTO variables set through normal 'set' and set through generator expressions, and will get rid of inconsistent settings at build time (I got warnings on MSVC that that LTCG wasn't set, or something like that.) Someone who knows CMake better can come up with something better. Just to reiterate, it's my belief that this won't change behaviour with users who have already set CURL_LTO through a simple variable (non-generator-expression) variable, I think.
I expected the following
No response
curl/libcurl version
Latest, linking from source code.
operating system
Windows, Linux.
The text was updated successfully, but these errors were encountered: