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

Forward CMake variables to prebuilding dependencies #1161

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

sfod
Copy link
Contributor

@sfod sfod commented Oct 23, 2024

Issue #, if available:

When prebuilding dependencies, we need to pass certain CMake variables from parent cmake process to child cmake process (e.g. toolchain file or path to C compiler). CMake doesn't provide this functionality out of the box.

Description of changes:

This PR implements a new CMake function that checks CMake cache file and collects variables that may affect build process. aws_prebuild_dependency uses this new function, so no changes are required in the downstream projects.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.63%. Comparing base (63187b9) to head (3944483).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1161      +/-   ##
==========================================
- Coverage   83.64%   83.63%   -0.01%     
==========================================
  Files          57       57              
  Lines        5954     5953       -1     
==========================================
- Hits         4980     4979       -1     
  Misses        974      974              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sfod sfod changed the title Add CMake function to gather cmd arguments Pass CMake command line variables to prebuilding dependencies Nov 8, 2024
@sfod sfod changed the title Pass CMake command line variables to prebuilding dependencies Forward CMake variables to prebuilding dependencies Nov 13, 2024
Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

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

Looking pretty good.
There might be a few more things we should look into (mentioned in comments), but when you're happy with it, I'm happy with it.

# on other platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT). Refer to
# https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html to update the list of handled variables, and
# then you can enable a new platform here.
if (NOT UNIX OR APPLE)
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial: add parens to make this more clear

Suggested change
if (NOT UNIX OR APPLE)
if ((NOT UNIX) OR APPLE)

# Get list of optional or platform-specific variables that may affect build process.
function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
set(variables "")
set(variablesToIgnore CMAKE_INSTALL_PREFIX)
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial: I don't see variablesToIgnore being used anywhere. Should it be deleted, or did we forget to do a check later?


# The CMake variables below were chosen for Linux, BSD, and Android platforms. If you want to use the prebuild logic
# on other platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT). Refer to
# https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html to update the list of handled variables, and
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 great docs on the thinking behind this, and what someone would need to look into if they're going to modify it in the future

foreach(var ${vars})
# Variables in this block make sense only in cross-compiling mode. The variable list is created from the CMake
# documentation on toolchains: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
# NOTE: Some variables are missed here (e.g. CMAKE_SYSROOT) because they can be set via toolchain file only.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 again great docs

# Other optional variables applicable both in cross-compiling and non-cross-compiling modes.
if (var STREQUAL "CMAKE_C_COMPILER"
OR var STREQUAL "CMAKE_CXX_COMPILER"
OR var STREQUAL "CMAKE_C_FLAGS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does AWS-LC use C++ anywhere? If so, we also need CMAKE_CXX_FLAGS. If not, maybe remove CMAKE_CXX_COMPILER?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh man. Should we also worry about linker flags? https://cmake.org/cmake/help/latest/envvar/LDFLAGS.html

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

4 participants