SCOREC / core

parallel finite element unstructured meshes
Other
183 stars 62 forks source link

CMAKE_CXX_FLAGS are overwritten #316

Open jacobmerson opened 4 years ago

jacobmerson commented 4 years ago

The CMAKE_CXX_FLAGS variable is overwritten by bob_begin_cxx_flags. I see that the variables SCOREC_CXX_FLAGS and SCOREC_EXTRA_CXX_FLAGS can be used instead.

However, this behavior is not "standard" and I had to go into the bob.cmake file to figure out how to change the flags.

I think it makes more sense to have the default behavior for CMAKE_CXX_FLAGS do what SCOREC_EXTRA_CXX_FLAGS currently does.

If we don't want to go that route, then there needs to be some sort of documentation on how to set the cxx flags and a comment in the CMakeLists.txt

jacobmerson commented 3 years ago

As evidence of this problem see issue #338. Symbols were not exporting due to us overwriting flags in bob.cmake and this made the debug process much harder.

KennethEJansen commented 3 years ago

Obviously, I agree with Jacob. I might have below average CMAKE skills but, if the intent is to control/protect the flags being set to somehow reduce mistakes that objective is not being met. A few more "seasoned" CMAKE gurus also had eyes on my CMAKE configuration and did not see my "foul" of adding a flag and clobbering my request for symbols. It was not until the third person plainly told me that my binary had no symbols even though the file command reported that it was not stripped that it occurred to me that adding -fpermissive to kill the warnings that were promoted to errors regarding casting MIGHT have been the culprit.

cwsmith commented 3 years ago

The documentation here:

https://github.com/SCOREC/core/wiki/General-Build-instructions#configure

describes that SCOREC_CXX_FLAGS overrides while SCOREC_CXX_EXTRA_FLAGS adds.

Clearly, this is not documented enough and there is not enough of a warning. Towards Jacob's point, this wrapper layer for flags maybe against modern CMake best practices.

As Ken said, the main intent of SCOREC_CXX_FLAGS and SCOREC_CXX_EXTRA_FLAGS is to prevent the user of pumi from unintentionally overriding default flags that pumi developers have deemed important. I suggest we do the following in the short term:

and towards longer term improvements, email the CMake mailing list to get opinions on the approach.

edit: changed todo

jacobmerson commented 3 years ago

The problem isn't so much that it's not documented, but that overriding CMAKE_CXX_FLAGS (or any other CMAKE_ variable ith a set() command is not standard practice. Most C++ devs who have used CMake will just expect whatever you set there gets passed through.

looking through bob.cmake

I see almost no flags that we should be explicitly setting...

If we want to provide default flags for our developers like -Werror we should use provide either a toolchain file, or CMakePresets.json file (although this isn't available until cmake 3.19).

I can take responsibility for updating the CMake stuff, although I have a lot on my plate with trying to finish up my thesis, so it won't happen immediately. I'm also not familiar with what the XSDK folks require.

cwsmith commented 3 years ago

Given that cmake has moved on since bob.cmake was written I think we are due for a more comprehensive and cohesive overhaul. The current approach basically defines a custom interface to control some key cmake variables. If users understand it, it works, but there is a lack of documentation and 'strange' things happen when users make changes by directly changing cmake variables. I'm fine with overhauling it to make it more intuitive.

The other big feature bob.cmake provides is an export capability for creating .cmake files placed with the install to support find_package(...). IIRC, cmake cannot completely populate these files by itself yet with all the things we currently have (transitive dependencies, compiler flags, versions, etc..).

I don't think there is a big rush in the short term on making these changes/improvements as most users have either kludged their way through problems or know what to do. If you can help after doing thesis work that would be much appreciated.

Responses to the bob.cmake review items are below.