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

Issue building couchbase-cxx-client in static #701

Open
Thomas-Barbier-1A opened this issue Nov 26, 2024 · 2 comments · May be fixed by #707
Open

Issue building couchbase-cxx-client in static #701

Thomas-Barbier-1A opened this issue Nov 26, 2024 · 2 comments · May be fixed by #707

Comments

@Thomas-Barbier-1A
Copy link

Hello,

I contact you because I am trying to build the client in static and I am facing some issues.

couchbase-cxx-client version 1.0.4 (tarball from https://github.com/couchbase/couchbase-cxx-client/releases/download/1.0.4/couchbase-cxx-client-1.0.4.tar.gz)

I am using the following cmake command

mkdir -p build
cmake -S "." -B build  \
    -DCMAKE_INSTALL_PREFIX=%{buildroot} \
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
    -DBUILD_SHARED_LIBS=OFF \
    -DCOUCHBASE_CXX_CLIENT_INSTALL=ON \
    -DCOUCHBASE_CXX_CLIENT_BUILD_EXAMPLES=OFF \
    -DCOUCHBASE_CXX_CLIENT_BUILD_TESTS=OFF \
    -DCOUCHBASE_CXX_CLIENT_BUILD_TOOLS=ON \
    -DCOUCHBASE_CXX_CLIENT_BUILD_STATIC=ON \
    -DCOUCHBASE_CXX_CLIENT_BUILD_SHARED=OFF

And I am getting the following errors:

CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "project_options" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "project_warnings" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "fmt" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "spdlog" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "GSL" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "asio" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "snappy" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "jsonsl" that is not in any export set.
CMake Error: install(EXPORT "couchbase_cxx_client-targets" ...) includes target "couchbase_cxx_client_static" which requires target "couchbase_backtrace" that is not in any export set.

If I build the client in shared it works fine

cmake -S "." -B build  \
    ${BuildTarget} -DCMAKE_INSTALL_PREFIX=%{buildroot} \
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
    -DBUILD_SHARED_LIBS=OFF \
    -DCOUCHBASE_CXX_CLIENT_INSTALL=ON \
    -DCOUCHBASE_CXX_CLIENT_BUILD_EXAMPLES=OFF \
    -DCOUCHBASE_CXX_CLIENT_BUILD_TESTS=OFF \
    -DCOUCHBASE_CXX_CLIENT_BUILD_TOOLS=ON \
    -DCOUCHBASE_CXX_CLIENT_BUILD_STATIC=OFF \
    -DCOUCHBASE_CXX_CLIENT_BUILD_SHARED=ON

Maybe I am using the wrong flags to build in static but I have the feeling there is some issues in the cmake files for the static build.
What triggers the issue seems to be the usage of both -DCOUCHBASE_CXX_CLIENT_INSTALL=ON and -DCOUCHBASE_CXX_CLIENT_BUILD_STATIC=ON

Can you please confirm that the cmake command I am using is correct to build in static and install the couchbase-cxx-client?

Cheers
Thomas

Note: I am sorry for creating the issue on Github but I cannot create an account on your Couchbase JIRA, there is only the option to sign in and if I sign in with my company or my personal account I have not access to your board.

@avsej
Copy link
Member

avsej commented Dec 2, 2024

Hi @Thomas-Barbier-1A, thanks for the report. You are right. At this moment it is a limitation as I have not figured out how to export library targets, but keep dependencies hidden (as we statically link dependencies, and do not export their interfaces anyway).

The "static build" right now works the best, when you use the SDK as subproject of your project. This way you can do -DCOUCHBASE_CXX_CLIENT_INSTALL=OFF and then combination of -DCOUCHBASE_CXX_CLIENT_BUILD_STATIC=ON -DCOUCHBASE_CXX_CLIENT_BUILD_SHARED=OFF would work.

This is what I'm doing right now in PHP SDK wrapper:
https://github.com/couchbase/couchbase-php-client/blob/2dd0e58b5bfa485803faa287c651657f654071f5/src/CMakeLists.txt#L45-L47

@Thomas-Barbier-1A
Copy link
Author

Thomas-Barbier-1A commented Dec 3, 2024

Hi @avsej , thank you for your reply. Unfortunately we have a particular UseCase that prevent us to use the libcouchbase as a CMake subproject:
In our company we build the opensource stack a bit like an Linux distribution: We compile all the libraries and deliver them (in shared, static or both depending on the UseCase), then our users build and link with the pre-compiled libraries.
We don't rebuild all our dependencies for each project (no vendoring). This is the reason why we need to "install" the libraries we compiled.
In the case of couchbase-cxx-client, the reason we want to link statically instead of shared libraries, is because we want to "aggregate" the library into an internal middleware component: This way we would be able to upgrade regularly the couchbase-cxx-client even if there are non ABI compatible or non source compatible changes without impacting our users.
Is there any other way to generate the libcouchbase-cxx-client.a even if the generated cmake files contain unneeded targets?
In our particular case, we won't use the generated cmake files anyway.
Cheers

avsej added a commit to avsej/couchbase-cxx-client that referenced this issue Jan 14, 2025
To avoid issues with generation of cmake helper scripts the following
changes has been made:

* interface libraries that are used to carry compiler options and flags
  are declared as IMPORTED to avoid unnecessary INTERFACE_LINK
  dependencies for the static library

* jsonsl, asio and couchbase_backtrace libraries are not linked as a
  targets, but rather as a object files directly. This is also done to
  avoid announcing them as a transitive dependencies. All these
  libraries are hidden and never exposed.

* for other third-party dependencies do not disable install tasks, which
  generate export files

This patch also removes some unused cmake files (of crypto, sasl and
operations/management directories).

Fixes couchbase#701
avsej added a commit to avsej/couchbase-cxx-client that referenced this issue Jan 14, 2025
To avoid issues with generation of cmake helper scripts the following
changes has been made:

* interface libraries that are used to carry compiler options and flags
  are declared as IMPORTED to avoid unnecessary INTERFACE_LINK
  dependencies for the static library

* jsonsl, asio and couchbase_backtrace libraries are not linked as a
  targets, but rather as a object files directly. This is also done to
  avoid announcing them as a transitive dependencies. All these
  libraries are hidden and never exposed.

* for other third-party dependencies do not disable install tasks, which
  generate export files

This patch also removes some unused cmake files (of crypto, sasl and
operations/management directories).

Fixes couchbase#701
avsej added a commit to avsej/couchbase-cxx-client that referenced this issue Jan 15, 2025
To avoid issues with generation of cmake helper scripts the following
changes has been made:

* interface libraries that are used to carry compiler options and flags
  are declared as IMPORTED to avoid unnecessary INTERFACE_LINK
  dependencies for the static library

* jsonsl, asio and couchbase_backtrace libraries are not linked as a
  targets, but rather as a object files directly. This is also done to
  avoid announcing them as a transitive dependencies. All these
  libraries are hidden and never exposed.

* for other third-party dependencies do not disable install tasks, which
  generate export files

This patch also removes some unused cmake files (of crypto, sasl and
operations/management directories).

Fixes couchbase#701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants