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

buildsystem: relax requirement on cmake version #1409

Merged
merged 1 commit into from
Jan 1, 2019
Merged

buildsystem: relax requirement on cmake version #1409

merged 1 commit into from
Jan 1, 2019

Conversation

yann-morin-1998
Copy link
Contributor

Commit 73cc508 (Using target_compile_features to specify C++ 11
standard) bumped the required cmake version, from 3.0 to 3.8, so
as to get the definition of target_compile_features().

However, target_compile_features() was introduced in cmake-3.1:
https://cmake.org/cmake/help/v3.1/command/target_compile_features.html

And using cmake-3.1 is indeed sufficient to properly build.

As such, relax the minimum required version down to cmake-3.1,
so we can build on oldish, entreprise-grade distributions that
only have cmake-3.1 (or at least, don't have up to cmake-3.8).

Reported-by: Thomas Petazzoni thomas.petazzoni@bootlin.com
Signed-off-by: "Yann E. MORIN" yann.morin.1998@free.fr

Commit 73cc508 (Using target_compile_features to specify C++ 11
standard) bumped the required cmake version, from 3.0 to 3.8, so
as to get the definition of target_compile_features().

However, target_compile_features() was introduced in cmake-3.1:
    https://cmake.org/cmake/help/v3.1/command/target_compile_features.html

And using cmake-3.1 is indeed sufficient to properly build.

As such, relax the minimum required version down to cmake-3.1,
so we can build on oldish, entreprise-grade distributions that
only have cmake-3.1 (or at least, don't have up to cmake-3.8).

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e8b6b7a on yann-morin-1998:yem/cmake-version into c682b98 on nlohmann:develop.

@nlohmann
Copy link
Owner

nlohmann commented Jan 1, 2019

Thanks for the PR! I’ll check it soon.

Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@nlohmann nlohmann self-assigned this Jan 1, 2019
@nlohmann nlohmann added this to the Release 3.5.1 milestone Jan 1, 2019
@nlohmann nlohmann merged commit 676c847 into nlohmann:develop Jan 1, 2019
@nlohmann
Copy link
Owner

nlohmann commented Jan 1, 2019

Thanks!

@yann-morin-1998
Copy link
Contributor Author

@nlohmann Thanks for the quick handling of the MR! :-)

Happy New Year and best wishes!

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

Sorry to be late, but I think this PR will actually break things for old CMake-versions. Indeed target_compile_features() has been added to CMake 3.1. However, the requested feature by this library (cxx_std_11) has only been added in CMake 3.8. See the changelog of cmake 3.8

One possible solution before 3.8 to solve a dependency to C++11 with target_compile_features was requesting a feature which implied C++11-support for compiler such as cxx_range_for.

@nlohmann
Copy link
Owner

nlohmann commented Jan 3, 2019

@pboettch Thanks for reporting!

@yann-morin-1998
Copy link
Contributor Author

@pboettch Indeed, cxx_std_11 was added only with 3.8.0. I only
checked for the addition of target_compile_features(). My bad, sorry.

However, I've actually been able to build with just cmake-3.1.

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

GCC from version 5 on enables C++11 by default, however, cmake should moan about the unknown feature.

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

Error on my side: even gcc 5.4 does NOT (edit) build c++11 by default.

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

I just tried on a Ubuntu 14.04 platform which uses cmake 3.5.1 the following:

add_executable(t t.cpp)
target_compile_features(t PRIVATE cxx_std_11)

And I got

CMake Error at CMakeLists.txt:4 (target_compile_features):
  target_compile_features specified unknown feature "cxx_std_11" for target
  "t".

@yann-morin-1998
Copy link
Contributor Author

@pboettch Arg.. I had a more recent version of cmake lying around, that was
taking precedence. I just retried, and indeed cmake-3.1 errors out too.

Shall I send a revert, or will you do?

(lesson learnt: next time, do not append to PATH, but prefix to it...)

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

@yann-morin-1998 If you change it to target_compile_features( ... cxx_range_for) in the CMakeLists.txt of this library, does it it work for you?

@yann-morin-1998
Copy link
Contributor Author

@pboettch So, replacing cxx_std_11 with cxx_range_for does work with cmake-3.1, yes.

@nlohmann
Copy link
Owner

nlohmann commented Jan 3, 2019

Just to nitpick: are there compilers that support range fors but not the rest?

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

Maybe some versions before GCC 4.8. IOW versions of compilers which had partial support of some C++11 features. Normally you should already not support these compilers.

AFAIK, CMake cxx_range_for pulls in C++11 support on GCC, Clang and VS.

@yann-morin-1998
Copy link
Contributor Author

@nlohmann @pboettch Here's what it got me:

[  2%] Building CXX object test/CMakeFiles/catch_main.dir/src/unit.cpp.o
cd /home/ymorin/tmp/json/json/build-me/test && /usr/bin/c++    -I/home/ymorin/tmp/json/json/test/thirdparty/catch    -std=gnu++11 -o CMakeFiles/catch_main.dir/src/unit.cpp.o -c /home/ymorin/tmp/json/json/test/src/unit.cpp

So it is using the gnu++11 suport.

@pboettch
Copy link
Contributor

pboettch commented Jan 3, 2019

That's CMake's default for GCC when C++11 is required.

@nlohmann
Copy link
Owner

Would someone volunteer for a PR on this issue?

@yann-morin-1998
Copy link
Contributor Author

@nlohmann I'll do something over the WE.

If I understood @pboettch correctly, we "just" have to use cxx_range_for to
get the same behaviour as we previously had with cxx_std_11 (sorry, but
C++ is not my cup of tea...;-))

Again, I'm sorry I broke the thing to start with. :-(

@yann-morin-1998
Copy link
Contributor Author

@nlohmann In the meantime, until I actually come up with a PR, you should just revert the merge, no?

@nlohmann
Copy link
Owner

No, do not revert the merge. There is no need to rush here. But it would be great to get back to the earlier CMake prerequisite with the next release.

@nlohmann
Copy link
Owner

So basically this would work, right?

if (${CMAKE_VERSION} VERSION_LESS "3.8.0") 
    target_compile_features(catch_main PUBLIC cxx_range_for)
else()
    target_compile_features(catch_main PUBLIC cxx_std_11)
endif()

@yann-morin-1998
Copy link
Contributor Author

@nlohmann I've just opened #1428 with code even simpler than your proposal.

I'd like @pboettch to review it, though, since that was their idea. I'll ping them
directly from the PR.

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.

4 participants