-
Notifications
You must be signed in to change notification settings - Fork 769
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
C++11 and "-march=native" flags done via "modern" CMake target-based properties #27
Conversation
We just had an issue with "modern" cmake... Is this supported by cmake that is installed with Ubuntu 16.04? |
For record, all on board it if it works with that cmake :-) |
Modulo comment above, looks good to me, but on cmake PR's I will typically defer to @chrisbeall to do final check and merge... |
Ok, let's wait for @chrisbeall opinion!
Hmm... it seems that your Jenkins instance uses Ubuntu 18.04 (CMake 3.10), and I don't have any 16.04 (with cmake 3.5) around to test. So this PR is not tested against that older version, though "modern" here normally means cmake >=3.0 so it should not be a problem, but it would be better to be sure. Probably the best way to do this is by adding several docker images to CI? |
I'll test this on Ubuntu 16.04, but might not have time until Thursday evening or Friday. |
Rebased on top of develop so Travis con run on this PR too. Edit: it's failing now in travis, will fix it. |
Woohoo, travis is working :-) Seems that maybe the c++11 flags do not work for all configs? |
Chris, I’ll let you merge… |
@chrisbeall are you good now? |
@jlblancoc can you paste an example of new output? |
(I just solved the merge conflict) Sure:
|
That's super-cool :-) |
I'm not a huge fan of:
That doesn't look very user friendly. This was easy to understand:
|
Two thoughts:
|
Hmm... I guess it could be done such that the There are some pros and cons in both the "old" and the "new" cmake ways, see for example:
But for library authors, I would strongly advise using the "modern" way to make exported targets as self-contained, and automatically-configured as possible. If all/most dependencies and users adhere to the "new" (cmake >=3.0) way, things are way simpler and more robust to maintain in the long term :-) |
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.
In general, I like the changes - seems cleaner. What I am missing is maybe a comment that explains the overall scheme you propose to use. Specifically, PUBLIC vs PRIVATE and how the compile options are applied. Now is the time to add that :-)
I do see Chris's issue with communication to the users, however. Also, how can they add system specific flags? Maybe that should also be explained.
We might have to go back and forth on this a few times to make sure this improvement (which I think it is!) is also transparent and not too alien to users.
GTSAM_CMAKE_SHARED_LINKER_FLAGS_TIMING GTSAM_CMAKE_MODULE_LINKER_FLAGS_TIMING | ||
GTSAM_CMAKE_C_FLAGS_PROFILING GTSAM_CMAKE_CXX_FLAGS_PROFILING GTSAM_CMAKE_EXE_LINKER_FLAGS_PROFILING | ||
GTSAM_CMAKE_C_FLAGS_PROFILING GTSAM_ GTSAM_CMAKE_EXE_LINKER_FLAGS_PROFILING |
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.
Is this a typo?
endif() | ||
endif() | ||
|
||
if (NOT MSVC) | ||
option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" ON) | ||
if(GTSAM_BUILD_WITH_MARCH_NATIVE) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") | ||
# Add as public flag so all dependant projects also use it, as required |
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.
dependent
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") | ||
# Add as public flag so all dependant projects also use it, as required | ||
# by Eigen to avid crashes due to SIMD vectorization: |
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.
avoid
cmake/GtsamBuildTypes.cmake
Outdated
|
||
# Also, ensure the compiler uses at least C++11. | ||
# The use of target_compile_features() is preferred since it will be not in | ||
# conflict with a more modern C++ standard, if used in a client program. |
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.
I like this!
cmake/GtsamBuildTypes.cmake
Outdated
target_compile_features(${target_name_} PUBLIC cxx_std_11) | ||
else() | ||
if (NOT MSVC) | ||
target_compile_options(${target_name_} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-std=c++11>) |
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.
Add comment ?
endif() | ||
target_compile_options(gtsam PRIVATE ${GTSAM_COMPILE_OPTIONS_PRIVATE}) | ||
|
||
# Apply build flags: |
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.
in comment, say where that function is defined...
PS: I'll come back to this issue soon and improve things. Thanks for the patience! |
Please, checkout the latest version. Options for each configuration are now editable from the cache, see attached screenshot. As CMake does, we have separate variables for preprocessor macros, and for all other compiler flags, and for "private" and "public" properties.
Note that the "final option variables" (those without the suffix Even with this limitation, it's been far from straightforward to set this up, but I think the result is much better now.... PS: Still not tested on Windows. |
It seems there are tests failing now, will look at it... Apparently, there are errors after not finding test datasets (?). Any wild guess of possible reasons would be appreciated... otherwise, will dig into the code. I'm not familiar (yet) with the so many tests in gtsam ;-) |
Yeah, I saw that. Maybe an option problem screwed up something in |
All tests pass now. Let's see if Travis agrees... |
Segfaults? Restarted last build to confirm. |
Still segfauls :-) I recommend checking detailed build commands between develop and this branch. Seems serialization-related. |
The only difference I found (for both, gcc and clang) was PS: If it works and someone wants to merge, feel free of using "squash merge" to simplify all the changes into a single commit... or wait until I rebase the commits. |
@@ -1,3 +1,5 @@ | |||
project(gtsam LANGUAGES CXX) |
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.
Just want to make sure I understand what you did here: We now have a top-level project GTSAM
, and two sub-projects gtsam
and gtsam_unstable
, and the main benefit of having the sub-projects is that we don't have to write /gtsam/
, or is there something else less obvious that I'm missing?
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.
Exactly, the top-level was named all upper case just to make it different from the actual library.
I normally add these project()
s for many subdirectories because it's handy: for some IDEs (e.g. MSVC) CMake generates "solutions" that only include the dependent projects, so for large projects it's much faster to load only that part of the project.
Anyway, that's not why I added the two projects: it was the only way I found to prevent MSVC to fail, it was done here: 65f442c
Unfortunately, I didn't documented very well (at all, actually...) which was the error and can't remember it. Could checkout the former version just to test, will try to do it if time permits.
Bottom line anyway: something in the targets configuration broke with the new variables and the only way to make CMake to get things right was to add these project() definitions.
@chrisbeall : What do you think of the new build CMake variables? I'm afraid you will think there are too many cache entries now, but in this way things should be much easier when packaging GTSAM as a Debian packages with CMake exported projects and such, for example.
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.
Ok, that makes sense. Definitely useful to add a comment for those kinds of workarounds in the future.
I think the new CMake variables are good, although I haven't yet tested building another project against it.
Have you had a chance to test this on Windows? Seems we always get surprises there.
wow... well, I don't know if that's good news. There is something we can try: to run valgrind at Travis. Could be done in a separate PR to see if it detects something weird. Having |
Not sure it's a memory issue, but adding a valgrind cmake target would be cool. |
Add commented out code to turn off clang on Linux.
…uted by environment variables. This should allow ccache to use caches from build stage for testing stage.
…or estimating covariance.
"const" ignored in this return type
Also: - Allow users to edit cmake target build options in the cache variables. - We had to add project() commands for gtsam and gtsam_unstable, the PROJECT_SOURCE_DIR changed, but the root GTSAM_SOURCE_DIR instead. - Ensure use of standard C++11 (no extensions)
Closing, there are conflicts that have been more easily solved by cherry-picking and rebasing on a fork. |
85d34351c Merge pull request #27 from borglab/fix/python3.5 dfe7639c0 support for python 3.5 git-subtree-dir: wrap git-subtree-split: 85d34351cdb29172601845f73d3281e786a531b3
I think the title says it all :-)
The PUBLIC flags ensures that "-march=native" & "c++11" propagates to all dependent projects automatically.