-
-
Notifications
You must be signed in to change notification settings - Fork 892
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
Export CMake Config file and "modernize" CMake scripts #87
Conversation
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.
Thank you very much for your PR.
I'm far from being an expert of cmake, so help on this is really appreciated!!
I put some comments around, can you address them before to merge?
CMakeLists.txt
Outdated
HAS_LIBCPP) | ||
|
||
cmake_pop_check_state() | ||
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") |
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.
Can you please get rid of commented lines? This is git, we won't miss them! :-)
CMakeLists.txt
Outdated
# | ||
|
||
include_directories(${entt_SOURCE_DIR}/src) | ||
#message(STATUS "Compile features: ${CMAKE_CXX_COMPILE_FEATURES}") |
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.
As above, I would delete this.
@@ -4,6 +4,8 @@ | |||
|
|||
cmake_minimum_required(VERSION 3.2) | |||
|
|||
include(GNUInstallDirs) |
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.
EnTT
fully supports also VS. Isn't this inherently wrong in that case?
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.
Actually this only makes some variables avialable where only CMAKE_INSTALL_INCLUDEDIR
is used and which evaluates to include
. This should be correct or okay for most platforms. The other variables from GNUInstallDirs
are not needed because the library is header only. We could also omit the include and replace the variable with a simple include
if prefered.
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.
Don't worry, often I make comments just to better understand what's going on. If you confirm that it works also on VS, it's fine for me.
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 confirm it works under VS. Just tested it for playing safe.
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, I just noticed that I also used the ${CMAKE_INSTALL_LIBDIR} variable from GNUInstallDirs
for the exported and installed config file. This also works like a charm on Windows (VS) though I install it to one of the most common path from the unix conventions: <prefix>/(lib/<arch>|lib|share)/cmake/<name>*/
. But there seems to be different conventions where to install the config file on different platforms: https://cmake.org/cmake/help/v3.2/command/find_package.html
CMake constructs a set of possible installation prefixes for the package. Under each prefix several directories are searched for a configuration file. The tables below show the directories searched. Each entry is meant for installation trees following Windows (W), UNIX (U), or Apple (A) conventions.
This is merely a convention, so all (W) and (U) directories are still searched on all platforms.
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 there a reason you didn't add -pedantic -Wall for MSVC?
If a reasons existed, I forgot it actually.
I think the optimization and the libc++ options are also belonging to usage requirements. Do you want to keep them on board? - is libc++ improving performance?
If I remember it right, it was due to the fact that on mac it didn't compile without including libc++. Because of this I put a line to prefer libc++ in general. We can rearrange it differently, not a problem. PR are compiled on the fly both on Travis and appveyor, so we know immediately if changes ruin something.
On my system [...]
Well, I don't think we can assume this on all systems and putting twice those options isn't a problem, so...
In general, it looks like you are very skilled with cmake, so I tend to consider your suggestions.
If you find we can further improve the build system of EnTT
, feel free to continue pushing on the PR. We aren't in a hurry to merge it. ;-)
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 think for MSVC, we miss much things, especially as CMake Interface EnTT should use those flags on MSVC ->
/Zi - Produces a program database (PDB) that contains type information and symbolic debugging information for use with the debugger.
/FS - Allows multiple cl.exe processes to write to the same .pdb file
/DEBUG - Enable debug during linking
/Od - Disables optimization
/Ox - Full optimization
/permissive- (c++ conformance)
and on linux i'm in favor to use:
-Weff-c++
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.
@skypjack Alright I think it's best to add the flags to the test targets then.
@Milerius I think these options/flags are no real requirements for using the library and so they don't have to be set as usage requirements on the EnTT target. But we can add some flags individually for the tests if needed. Projects depending on EnTT can define their own 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.
@m-waka Fine for me. Do you plan to do it on your branch and therefore with this PR?
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.
@skypjack yes I will implement it on my branch with this PR tomorrow.
CMakeLists.txt
Outdated
add_library(EnTT INTERFACE) | ||
|
||
target_include_directories(EnTT INTERFACE | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src> |
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 know it's probably annoying, but currently EnTT
uses 4 spaces for indentation. I'd prefer to keep it consistent throughout the whole project. Thank you.
…h Config Version file, Export CMake package
…r using libc++, Remove from EnTT target and move it to test targets
Alright, perhaps the added -pedantic and -Wall is the reason I will test and try to fix it on my Windows machine. So further commits will come.
|
The problem with -Wall is not due to the platform but due to the compiler MSVC
So this builds now with MSVC2017 (at least on my system, let's wait for appveyor). Adding -Wall on MSVC was creating lots of warnings... I'm not sure whether these are problematic in any way. |
I think appveyor isn't starting because of a conflict within |
So we have now two new CMake options which are by default option(ENTT_COMPILE_OPTIONS "Use compile options from EnTT." ON) |
Really THANK YOU for your efforts!! |
You did it!! Thank you!! |
…_VARS CMAKE_INSTALL_INCLUDE_DIR of configure_package_config_file, Remove redundant options, correct target_include_directory for INSTALL_INTERFACE, set the Version in EnTTConfig file and check CMake version
Some tiny improvements/fixes, sorry... |
Not a problem. Do you want to take your time to review it before to merge on |
Okay, I will review it a bit and tell you if I think everything works and do some small commits if necessary. |
I think this is fine now. We have now an additional build tree CMake config file generated besides the config file for the install tree. |
Is it ignored by git or at least created within the build directory? |
It is here: |
If it's fine for you, I'm merging it on a dedicated branch ( |
As you want. 👍 If there are any questions concerning the PR, feel free to ask. |
So, what do we expect an user to do now to be able to easily use |
Another question. Why this: target_compile_features(
EnTT
INTERFACE cxx_std_14
) Instead of this? set(CMAKE_CXX_STANDARD 14) |
If it is already installed on your system you can easily call:
If it is not installed you can either clone and install it or add it as ExternalProject. If you as developer of You can still add it as subdirectory and as we also have a build tree config file it can then also be used without installing.
To your second question: I hope this was comprehensible. |
Do you want to become the official maintainer of the |
It's shouldn't be ignored since CMake need it for the installation
|
Yep, I realized it and deleted the message a couple of minutes ago... :-) |
Yeah, why not. Would be a great honor. I hope I will also improve my (modern) C++ knowledge while using |
In order to avoid polluting the build directory of external projects, shouldn't we replace |
As |
In modern CMake it's prefered to export a CMake configuation file for a package which can then be found by find_package(). This is also the prefered way to import external packages instead of find module scripts.
There is also no install target for entt, yet. Even for header only libraries one can use add_library as an INTERFACE library for generation of a target.
Some references for modern CMake are found in: https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1 and in Daniel Pfeifer’s C++Now 2017 talk Effective CMake (and cmake - Introduction and best practices, 2015).
So this PR tries to "modernize" the CMake scripts and exports a CMake configuration, which can be found by find_package(). It also adds an option for building the documentation, preventing an error when calling make install without having build the docs before.