-
Notifications
You must be signed in to change notification settings - Fork 8
fix: Allow for environment override of CMAKE_CXX_FLAGS #29
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
fix: Allow for environment override of CMAKE_CXX_FLAGS #29
Conversation
* Allow for CMAKE_CXX_FLAGS to use its default behavior of taking the value of CXXFLAGS if it exists in the environment. - c.f. https://cmake.org/cmake/help/v3.31/envvar/CXXFLAGS.html - Set CMAKE_CXX_FLAGS and then determine all other compiler or linker flags. * Remove subtractive behavior of removing compiler flags and instead use additive behavior. This both makes the user more responsible for their flag choices and ensures that known required flags can be added without interfering as repeated flags are safe. * Set range of compatible CMake versions to allow more modern CMake to be used if available. - Bump lower bound on CMake to v3.12 when this feature was added. - c.f. https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html * Correct typos: - 'CMAKE_INSTALL_INCLUDE_DIR' -> 'CMAKE_INSTALL_INCLUDEDIR' * Add pixi ignores to .gitignore.
9db26ad to
deac7cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High level comments for the reviewer.
| @@ -1,4 +1,4 @@ | |||
| cmake_minimum_required (VERSION 3.0.2) | |||
| cmake_minimum_required(VERSION 3.12...3.31) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use range of compatible CMake versions (https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html) which was introduced in v3.12. This will take the newest available CMake version between v3.12 and v3.31 that can be found a build time.
| # Set default CXXFLAGS but allow for environment override | ||
| # c.f. https://cmake.org/cmake/help/v3.31/envvar/CXXFLAGS.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First determine the values of CMAKE_CXX_FLAGS: Either taken from the environment CXXFLAGS like normal, or if they are absent, set defaults manually.
| set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address ${CMAKE_CXX_FLAGS}" CACHE STRING "debug CXXFLAGS" FORCE) | ||
| set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING "debug linker flags" FORCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once CMAKE_CXX_FLAGS has been set, then all other compiler or linker flags can be set accordingly in an additive fashion to their existing environmental defaults based on the CMAKE_CXX_COMPILER_ID.
|
This is ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewfeickert thanks a lot for this. I have tested on linux and m3 and it works fine.
Description
CMAKE_CXX_FLAGSto use its default behavior of taking the value ofCXXFLAGSif it exists in the environment.CMAKE_CXX_FLAGSand then determine all other compiler or linker flags.CMAKE_INSTALL_INCLUDE_DIR->CMAKE_INSTALL_INCLUDEDIRpixiignores to.gitignore.