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

cmake: Improve handling of SECP256K1_APPEND_*FLAGS options #1648

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Dec 13, 2024

On the master branch @ f79f46c, setting SECP256K1_APPEND_*FLAGS when using IDE build tool generators, such as "Visual Studio" and "Xcode", has no effect because these generators do not utilise low-level rule variables when creating project files.

This PR disables SECP256K1_APPEND_*FLAGS options in such scenarios. CMake will issue a warning if any of them are set.

Additionally, this PR fixes a bug with the clang-cl compiler (see #1647):

> cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang-cl -DSECP256K1_APPEND_CFLAGS=/W4
> cmake --build build
...
clang-cl: error: no such file or directory: '/W4'
...

The last change is beneficial in its own right, as it makes the compile invocation string more natural by ensuring that flags do not follow source files.

@real-or-random
Copy link
Contributor

Can you indicate why this is a draft?

@hebasto
Copy link
Member Author

hebasto commented Dec 13, 2024

Can you indicate why this is a draft?

I haven't tested this branch with Xcode on macOS yet.

@hebasto hebasto marked this pull request as ready for review December 15, 2024 13:15
@hebasto
Copy link
Member Author

hebasto commented Dec 15, 2024

Can you indicate why this is a draft?

I haven't tested this branch with Xcode on macOS yet.

Reworked to support only command-line build tool generators.

Undrafted and ready for review :)

Copy link
Contributor

@real-or-random real-or-random left a comment

Choose a reason for hiding this comment

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

On the master branch @ f79f46c, setting SECP256K1_APPEND_*FLAGS when using IDE build tool generators, such as "Visual Studio" and "Xcode", has no effect because these generators do not utilise low-level rule variables when creating project files.

This PR disables SECP256K1_APPEND_*FLAGS options in such scenarios. CMake will issue a warning if any of them are set.

Concept ACK

Special casing generators is not elegant, but yeah, it's probably a good idea. Otherwise, anyone who wants to use SECP256K1_APPEND_CFLAGS on an unsupported build system will waste hours trying to understand why this is the case.

CMakeLists.txt Outdated
Comment on lines 283 to 285
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
# Only command-line build tool generators support low-level rule
# variables.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

While this seems to be true, I think it's a coincidence that these happen to be the command-line tools.

Suggested change
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
# Only command-line build tool generators support low-level rule
# variables.
# Only some generators use low-level rule variables.
if(CMAKE_GENERATOR MATCHES "Make|Ninja")

And I think the command should be above the if line because it comments on the if.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Reworked.

@@ -287,7 +287,7 @@ if(CMAKE_GENERATOR MATCHES "Make|Ninja")
# guarantee that the flags appear at the end of the command line.
set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
if(SECP256K1_APPEND_CFLAGS)
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
string(REPLACE "<FLAGS>" "<FLAGS> ${SECP256K1_APPEND_CFLAGS}" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this same should be done for CMAKE_C_CREATE_SHARED_LIBRARY and/or CMAKE_C_LINK_EXECUTABLE?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Done.

Command-line build tool generators are the only ones that support
low-level rule variables. IDE build tool generators, such as "Visual
Studio" and "Xcode", do not utilize these variables when creating
project files.

This change ensures that CMake warns users if any of the
`SECP256K1_APPEND_*FLAGS` options are set while using an unsupported
generator.
This change also makes the compile invocation string more natural by
ensuring flags do not follow source files.

Linker flags are also amended for consistency.
Copy link
Contributor

@real-or-random real-or-random left a comment

Choose a reason for hiding this comment

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

utACK c12bc01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants