Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Added a config to export the library as a cmake target #66

Closed
wants to merge 6 commits into from
Closed

Added a config to export the library as a cmake target #66

wants to merge 6 commits into from

Conversation

hellozee
Copy link

This exports the library as a cmake package with sqlpp11::sqlpp-mysql target. Don't know if it is necessary or not, but I needed it to link against my program when installed this library from vcpkg. I have kept it under the sqlpp11 namespace, since package name is pretty long.

src/CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@hellozee hellozee requested a review from rbock January 16, 2021 11:55
@hellozee
Copy link
Author

Sorry for being late, 😸

@rbock
Copy link
Owner

rbock commented Jan 17, 2021

Thanks for the update. I appreciate the effort you put into this.

However, this now has hundreds of lines of code for the equivalent of git tag | sort -V | tail -n1.

Your initial statement was:

Don't know if it is necessary or not, but I needed it to link against my program when installed this library from vcpkg.

I have no relevant knowledge of vcpkg and my cmake skills are rather limited. I cannot imagine that anything like this is necessary to make them work together. Please do more research. There has to be a better way.

Thanks!

@hellozee
Copy link
Author

hellozee commented Jan 17, 2021

However, this now has hundreds of lines of code for the equivalent of git tag | sort -V | tail -n1.

Sorry, that was me being lazy, I copied a whole module where I needed just a single function, removed that and replaced that with a small command.

Your initial statement was:

Don't know if it is necessary or not, but I needed it to link against my program when installed this library from vcpkg.

I have no relevant knowledge of vcpkg and my cmake skills are rather limited. I cannot imagine that anything like this is necessary to make them work together. Please do more research. There has to be a better way.

I can't link against the connector since no targets were exported corresponding to it. So unless the libraries and headers exist in the system path, it would be a hassle to use it. That is what I think, though I could be definitely wrong.

CMakeLists.txt Show resolved Hide resolved
src/CMakeLists.txt Show resolved Hide resolved
@hellozee
Copy link
Author

Put a check for the TAG variable if not set, I am out of ideas on how to tackle this if there is not .git or git isnt available in the system, :)

@rbock
Copy link
Owner

rbock commented Jan 30, 2021

Thanks!

@Leon0402 and @GCarneiroA My cmake foo is insufficient to figure out if this would conflict with #65?


install(
FILES
"../cmake/sqlpp11-connector-mysqlConfig.cmake"

Choose a reason for hiding this comment

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

Why did you copy the config file in the binary directory in line 17, if you now use the path to the cmake directory directly?

Also instead of using "../cmake", you could also use "${PROJECT_SOURCE_DIR}/cmake/", which I personally like more. But that might be preference.

"${CMAKE_CURRENT_BINARY_DIR}/cmake/sqlpp11-connector-mysqlConfig.cmake"
COPYONLY)

set(ConfigPackageLocation lib/cmake/sqlpp11-connector-mysql)

Choose a reason for hiding this comment

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

To be compatible with all major distributions / OS, you should rather not hardcode the destinations path here. Instead cmake can figure out the correct directory:

include(GNUInstallDirs)
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/sqlpp11-connector-mysql)

bind_result.cpp
detail/connection_handle.cpp)
add_library(sqlpp-mysql connection.cpp prepared_statement.cpp char_result.cpp
bind_result.cpp detail/connection_handle.cpp)

install(TARGETS sqlpp-mysql DESTINATION lib)

Choose a reason for hiding this comment

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

This can be removed I guess

VERSION ${TAG}
COMPATIBILITY AnyNewerVersion)

export(

Choose a reason for hiding this comment

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

This shouldn't be necessary, it is done by install(EXPORT ...) in line 23

FILES
"../cmake/sqlpp11-connector-mysqlConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/sqlpp11-connector-mysqlConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation})

Choose a reason for hiding this comment

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

Actually nothing here, but I can't comment on code you haven't changed (Why Github?). In the top level cmake file there is the installation command for the header files. You might wanna move them in here, to have everything installation related in one place

@@ -0,0 +1,6 @@
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

Choose a reason for hiding this comment

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

Seems to be not needed

@Leon0402
Copy link

Thanks!

@Leon0402 and @GCarneiroA My cmake foo is insufficient to figure out if this would conflict with #65?

It should be alright as far as I can see.

But @GCarneiroA made some good changes over there, which this patch could benefit from. He added target specific commands like target_include_directories with the appropriate visibility (most often PUBLIC here). So everyone that links against this library will have set the include directories, libraries set automatically.
There is special handling for Installation though. The path of the headers will change. Therefore you would usually add some logic to make target_include_directories contain relative paths when building, but pathes to the installation folder when installing. It might look like this:

target_include_directories(mysql-connector 
   INTERFACE
       $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
       $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

The INSTALL_INTERFACE part can be removed, when using INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} on the install(TARGETS ...) command. I use it normally, because you can't do anything wrong here :)

As far as I can see the @GCarneiroA took this into account in his patch, although the INSTALL_INTERFACE part isn't correct I think.

So I think it might be better to merge the other PR first and then rebase here. But I'm not sure if @GCarneiroA is still working at the other PR, it seems stale.

@kovdan01 kovdan01 mentioned this pull request Jul 29, 2021
@rbock
Copy link
Owner

rbock commented Dec 18, 2021

The mysql-connector now lives in the sqlpp11 repo.

Closing this before archiving. Please re-open in sqlpp11, if this is still relevant.

Thanks!

@rbock rbock closed this Dec 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants