Skip to content

CPP: Fix cmake build failure + export libphonenumber-config.cmake#2818

Merged
penmetsaa merged 9 commits intogoogle:masterfrom
temideoye:cpp_fix-cmake-build-issues
Jan 4, 2023
Merged

CPP: Fix cmake build failure + export libphonenumber-config.cmake#2818
penmetsaa merged 9 commits intogoogle:masterfrom
temideoye:cpp_fix-cmake-build-issues

Conversation

@temideoye
Copy link
Copy Markdown
Contributor

@temideoye temideoye commented Sep 9, 2022

Currently, the project fails to build when BUILD_GEOCODER=OFF due to a missing dependency. The issue is described here. This push fixes the bug and proposes the following additional features to enhance the CMake build process overall:

  1. Expose BUILD_SHARED_LIBS and BUILD_TESTING as user configurable options
  2. Add functionality to build and export CMake package config files so downstream projects can consume the library with a simple find_package(libphonenumber), without creating a FindLibPhonenumber.cmake file
  3. Issue: https://issuetracker.google.com/issues/239501100

@google-cla
Copy link
Copy Markdown

google-cla bot commented Sep 9, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@temideoye
Copy link
Copy Markdown
Contributor Author

Hey, @penmetsaa! Just checking in, have you been able to review this?

@penmetsaa
Copy link
Copy Markdown
Contributor

Hi @temideoye ,

Thanks so much for your patience. We are planning to review this in next 4 weeks.


project (generate_geocoding_data)

# Helper functions dealing with finding libraries and programs this library
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As we have moved the download functionality to main library's CMAKE, we were unable to build the offline geocoder individually. Could we not remove this from here OR have this as a common build rule file?

CMake Error at CMakeLists.txt:39 (target_link_libraries):
  Target "generate_geocoding_data" links to:

    absl::strings

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Note: I am not expertise in CPP builds, please suggest and do what you think is best :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we do anything about this..?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@penmetsaa, I had assumed (erroneously) that tools/cpp is merely a dependency of the main project, but now I understand you build it independently for other purposes as well.

There are 2, or 3 possible ways to resolve this:

  1. Copy the find abseil functions back to tools/cpp. The demerit of this is obviously the maintenance overhead.
  2. Create a new shared cmake module for the find abseil functions. This is DRYer than 1, but still a bit of a dance.
  3. Build tools/cpp via the main project with an option like -DBUILD_TOOLS_ONLY=ON. This should simplify the interface in that all dependency resolutions happen in the same file. It would be my preference too.

I will share a pull request in a moment. Let me know if it works for you, or if you'd rather resolve it a different way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@penmetsaa, please see 2869.

option (USE_LITE_METADATA "Use lite metadata" OFF)
option (USE_RE2 "Use RE2" OFF)
option (USE_STD_MAP "Force the use of std::map" OFF)
option (BUILD_STATIC_LIB "Build static libraries" ON)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

About these new options, could you please add some notes in cpp/README file.
It helps readers to know about these options.

Copy link
Copy Markdown
Contributor

@penmetsaa penmetsaa left a comment

Choose a reason for hiding this comment

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

Thanks so much for meticulous work.
Mentioned some minor suggestions / doubts I have, please take a look. :)

@temideoye
Copy link
Copy Markdown
Contributor Author

Hiya, @penmetsaa.

I've gone through your comments. Thanks.

First, it looks like you ran your tests against each of the commits in the pull request. Only the last commit is designed to be whole and complete, please limit your test to that. The preceding commits are mostly of documentary value and not guaranteed to be stable.

If you could test the repo at this point, I expect it to build without errors with the only necessary change being bumping the version number to 8.13.0. Please confirm and let me know.

With regards to the readme; sure I'm happy to send a pull request that documents what's new.

Happy new year!

@penmetsaa
Copy link
Copy Markdown
Contributor

penmetsaa commented Jan 4, 2023

Thanks! +1 to what you mentioned.. Some pending AIs:

  • Reply to my comment on: tools/cpp/CMakeLists.txt
  • Documentation update (a new PR) regarding the new oprions

@penmetsaa penmetsaa merged commit 88c175c into google:master Jan 4, 2023
@penmetsaa
Copy link
Copy Markdown
Contributor

penmetsaa commented Jan 4, 2023

Hi,
There is a breakage in CPP build after this merge, could you please look into this?

  - Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
  -- Found Threads: TRUE
  -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found suitable version "1.74.0", minimum required is "1.40.0") found components: date_time system thread
  -- Checking for module 'protobuf>=2.4'
  --   Found protobuf, version 3.12.4
  -- Checking for module 'icu-uc>=4.4'
  --   Found icu-uc, version 71.1
  -- Checking for module 'icu-i18n>=4.4'
  --   Found icu-i18n, version 71.1
  -- Looking for C++ include tr1/unordered_map
  -- Looking for C++ include tr1/unordered_map - found
  -- Configuring done
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "phonenumber" which requires target "absl_node_hash_set" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "phonenumber" which requires target "absl_strings" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "phonenumber" which requires target "absl_synchronization" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "geocoding" which requires target "absl_node_hash_set" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "geocoding" which requires target "absl_strings" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "geocoding" which requires target "absl_synchronization" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "phonenumber-shared" which requires target "absl_node_hash_set" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "phonenumber-shared" which requires target "absl_strings" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "phonenumber-shared" which requires target "absl_synchronization" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "geocoding-shared" which requires target "absl_node_hash_set" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "geocoding-shared" which requires target "absl_strings" that is not in any export set.
  CMake Error: install(EXPORT "libphonenumber-targets" ...) includes target "geocoding-shared" which requires target "absl_synchronization" that is not in any export set.
  -- Generating done
  CMake Generate step failed.  Build files cannot be regenerated correctly.
  (END)

Is this something related to https://stackoverflow.com/questions/5378528/install-export-problem-for-library-with-dependencies, should we link_libraries?, if not feasible to export these external deps..

@temideoye
Copy link
Copy Markdown
Contributor Author

@penmetsaa, that looks like cmake couldn't find your abseil lib directory. Do you have the installation path of abseil in CMAKE_PREFIX_PATH? You may try something like cmake -S "path/to/libphonenumber/cpp" -B "path/to/build/directory" -DCMAKE_PREFIX_PATH="path/to/abseil;path/to/other/dependencies" .

@penmetsaa
Copy link
Copy Markdown
Contributor

Hi @temideoye

  • When I tried installing abseil at system level and then mentioning path in the CMAKE_PREFIX_PATH -> it is working correctly.
  • When there is no abseil found, we know that FetchContent() dowloads and builds the abseil to temp/cache dir and referring from there -> This is working before our/this commit.

Is it that after the change, the cached abseil binaries are not been able to found?

@temideoye
Copy link
Copy Markdown
Contributor Author

Oh dang, I see what you mean. The issue seems to be that abseil disables its install rules in superbuilds:

https://github.com/abseil/abseil-cpp/blob/b0cc11b9763d50f6ecd160719b0f78fde9712a7f/CMakeLists.txt#L60-L66

Setting ABSL_ENABLE_INSTALL=ON should fix the errors. My bad, I should have also tested the build without a prebuilt abseil. Will send you a patch to test in a moment.

@temideoye
Copy link
Copy Markdown
Contributor Author

@penmetsaa, I've added a fix for the install errors to 2869. Let me know if it resolves the issue for you.

@penmetsaa
Copy link
Copy Markdown
Contributor

Thanks much for the patch @temideoye..
Closing the thread as that fix resolved the issue

Comment on lines -361 to +385
"test_metadata"
"metadata"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this rename conflicts with the metadata.h generated above in the non-test METADATA_TARGET. they both output a metadata.h like this, which means the build has two rules that generate the same output file (one for metadata_target, and one for test_metadata_target).

this breaks the build for cmake -G Ninja, because the .ninja spec forbids two distinct rules for the same output:

$ ninja -C build/
ninja: entering directory 'build/'
ninja: multiple rules generate '/home/demon/src/aports/community/libphonenumber/src/libphonenumber-8.13.4/cpp/src/phonenumbers/metadata.h'

Copy link
Copy Markdown
Contributor Author

@temideoye temideoye Jan 10, 2023

Choose a reason for hiding this comment

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

@nekopsykose, thanks for the catch. The bug was fixed here, but was reintroduced by a clumsy merge. @penmetsaa, will send in a quick pull request to restore the fix if that's OK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regression fixed with 2874.

@penmetsaa
Copy link
Copy Markdown
Contributor

penmetsaa commented Jan 10, 2023

Thanks for correcting the thing that we overlooked @nekopsykose and @temideoye. Merged the #2874 PR

@nekopsykose
Copy link
Copy Markdown

@penmetsaa thanks!

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 this pull request may close these issues.

3 participants