-
Notifications
You must be signed in to change notification settings - Fork 348
Add USE_SYSTEM_DATE
cmake option
#372
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
Add USE_SYSTEM_DATE
cmake option
#372
Conversation
c465b7b
to
2110f04
Compare
Being a CMake illiterate, I'll say this sounds convincing, but I'll give @Leon0402 a few days to chime in as he introduced FetchContent here.. I kinda hope that the CMake files will converge to an accepted solution at some point :-) |
So you mean you downloaded the library on a machine with internet and then copied it to another machine, which has no internet to build it there?
That is correct. We agreed on that to be acceptable for this library and it's connectors, when I introduced the change. One reason for this was that the newest ubuntu LTS ships with that version, which we took here as a reference.
There are a few scenarios here:
What the canonical way is is to be discussed I would say. Supporting find_package is actually not the most trivial thing and most libraries just don't. Most rely on outdated find Scripts and such stuff, I wouldn't call that the canonical way (I wouldn't call FetchContent the canonical way either, there is just none in my opinion). Regarding your argument: If you install sqlpp11 on your system it will install date as well on your system. So no need to install it extra. That is one of the convenient things. (We could add a Component to the install here, so you can also decide to only install sqlpp11) I think this might be also your misunderstanding. There is no need for you to use FetchContent as well in your own project. Just clone this lib, install it and it will install sqlpp11 and the dependencies (date in this case) as well. Quite convenient actually I would say. Then you can use sqlpp11 in your project just as you would normally. You need a newer version of date? Bump it and you good to go. You also have full control whether you want the lib and it's dependencies static or shared and such stuff. Btw. you probably use a connector as well. In case you use sqlite3 this is even more convenient. Because the connector will FetchContent sqlpp11. So install the connector and you get everything. That being said: A good argument against FetchContent might be that for some reasons you already have date installed and luckily it's already in the right version, so you don't want to build it again. I considered this to be not that likely (Date isn't a library that ships with package managers or such stuff), but I see that it's possible. And as I said above you can easily change it so it works for you. But it could make be simpler. I propose we just leave users the (easy) choice and use a Flag called Nevertheless, you might wanna think if fetchContent is really not the right thing for you. I don't know your exact use case, but for most people this works fine very well and is a lot easier. (Just take the CI/CD as an example. You know need more lines than before. Now imagine that with 20 dependencies instead of one. And take also into account that date is one of the best libraries regarding CMake Support. It won't be so easy with all of them). |
@Leon0402 Thank you for such a detailed answer! Adding |
@@ -22,11 +22,17 @@ | |||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
|
|||
include(FetchContent) | |||
|
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.
Are you sure this works? I'm not quite sure, but if I remember correctly find_package has to be called in the (parent) scope of where it's actually linked to.
That means find_package would need to be in the root CMakeFile (just as in your previous version and the if else has to be around the add_subdirectory(dependencies).
I'm not 100% sure though if I remember here correctly, I can't test it myself right 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.
Yes, I checked that it works on my system (Arch Linux x86-64, cmake 3.21.1) in both configurations: with USE_SYSTEM_DATE
and without it (and it behaves as expected - uses find_package in the first case and fetches the library from github in the second one). Moreover, CI builds pass - it means that it works not only on my system :)
Regarding that:
find_package would need to be in the root CMakeFile
In my practice I put find_package in different level CMakeLists.txt files (trying to minimize the scope and use them only where needed), and never have problems. Perhaps your information is correct for some old cmake versions, but now using find_package
and include
anywhere looks OK.
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.
Ah, sorry, my fault - everything was OK only with -DBUILD_TESTING=OFF
(likely because sqlpp11 is header-only). You are right - date::date
target is used in top-level CMakeLists.txt, that's why find_package
should be located there too.
dependencies/CMakeLists.txt
Outdated
GIT_TAG v3.0.0 | ||
) | ||
if(USE_SYSTEM_DATE) | ||
find_package(Threads 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.
Why Threads here?
If we need this, then presumbably only on non msvc and you would also need to link against it. But I'm not sure if we do. cc: @rbock
It might be that wee need this and relied on Date for this https://github.com/HowardHinnant/date/blob/master/CMakeLists.txt#L152.
While this should work fine in both modes, it would be better to do this here as well if we need it to not rely on date providing it. But in these case we should find_package(Threads) in both cases I assume (and link against 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've added that in the first PR revision because it did not compile on my system without that. Now I've checked that it works correctly without it (and it is expected - date library marks Threads as a dependency, and it is found automatically: https://github.com/HowardHinnant/date/blob/master/cmake/dateConfig.cmake#L4). Deleting this line (as not needed).
@Leon0402 Updated the PR based on your comments. Please see the changes |
USE_SYSTEM_DATE
cmake option
|
||
if(USE_SYSTEM_DATE) | ||
find_package(date REQUIRED) | ||
endif() | ||
|
||
### Dependencies | ||
add_subdirectory(dependencies) |
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.
You should put the add_subdirectory here in the else I suppose :-) Otherwise you have not much gained, it will still fetch date.
And could you move the comment in line 44 "### Dependencies" above the if. That was there to introduce the section for dependencies, so the cmake file will be clean
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.
You should put the add_subdirectory here in the else
Yes, but there is a little inconsistency here: in your case, if not USE_SYSTEM_DATE
, we add_subdirectory(dependencies)
, which potentially might contain not only date dependency.
Otherwise you have not much gained, it will still fetch date.
It will not - I wrapped dependencies/CMakeLists.txt content into if(NOT USE_SYSTEM_DATE)
block. I actually don't like this variant, but putting add_subdirectory(dependencies)
in else branch looks a bit illogical too.
Maybe you could suggest an approach that will avoid the mentioned problems?
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.
Ah right, sorry, I didn't see the other change. I think this is fine. Usually in my projects I use two ifs, one around the fetchContent_Declare and one around the add_subdirectory(). The reason is that with multiple dependencies you first specify all FetchContent_Declare and then all add_subdirectory / FetchContent_MakeAvailable, so common dependencies are only used one.
But as we only have one dependency right now, it doesn't matter I suppose. If there will be a second one we can split this up further.
if(USE_SYSTEM_DATE) | ||
find_package(date REQUIRED) | ||
endif() | ||
|
||
### Dependencies | ||
add_subdirectory(dependencies) |
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.
if(USE_SYSTEM_DATE) | |
find_package(date REQUIRED) | |
endif() | |
### Dependencies | |
add_subdirectory(dependencies) | |
### Dependencies | |
if(USE_SYSTEM_DATE) | |
find_package(date REQUIRED) | |
else() | |
add_subdirectory(dependencies) | |
endif() |
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 found out there is suggest changes button :-) But not tested, please check if it works
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.
Seems fine to me @rbock , although I didn't test it myself (but pipelines runs, so should be alright)
Thanks both, for the intense discussion! Much appreciated. |
* Add `USE_SYSTEM_DATE` cmake option
Massive refactor and cleanup release The changes below require git/build rules to be changed. I am expecting the result to be considerably simpler, though. It will also be much simpler to make changes to the library or individual connectors now (most of the misc changes below would have been much harder to do with the former multiple repos). Some of the misc changes below might break existing code in very rare cases (I am aware of exactly one). Happy to help fixing those :-) Connector libraries - Moved connector libraries for mysql/postgresql/sqlite3 into the sqlpp11 repository - Made connector libraries header-only - Added `USE_SYSTEM_DATE` cmake option (#372) Documentation: - Created docs directory (#364) - Removed wiki pages - Document multi_insert for time_point columns (#367) Fixes: - Several DateTime fixes for mysql - Add order_by and limit for mysql remove and update - Added shift left and shift right operators. - Added blob support for postgresql - Support MySQL connect timeout option Misc: - Replace serializer_t - Remove multi_column. - Remove tvin - Remove rhs_wrap - Remove _is_trivial from *_operand - Add is_equal_or_null(col, some_value_or_null) - Remove variations of serialization from interpretable - Remove null_is_trivial_value - Remove table::ref (see #345). - Remove same-name check for result columns
A user might already have a system/self-built version of a dependency and want to use it. For example, such version might be newer and have some fixes, including security ones. For such users,
USE_SYSTEM_DATE
option (for Howard Hinnant's date library) will be helpful.