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

fix(CMakeLists): build fails when using cmake on mac with Xcode as ge… #949

Closed
wants to merge 1 commit into from

Conversation

cn-nice
Copy link

@cn-nice cn-nice commented Sep 7, 2023

When you use cmake to build with xcode as a generator under Mac, the build will fail.
See https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries

@google-cla
Copy link

google-cla bot commented Sep 7, 2023

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.

@sergiud
Copy link
Collaborator

sergiud commented Sep 7, 2023

Thanks for the PR. However, you need to sign the CLA first.

It is also not clear why such a hack is necessary. Could you please explain? The CMake documentation you reference does not mention any problem with Xcode.

@cn-nice
Copy link
Author

cn-nice commented Sep 8, 2023

Thanks for the PR. However, you need to sign the CLA first.

It is also not clear why such a hack is necessary. Could you please explain? The CMake documentation you reference does not mention any problem with Xcode.

Thank you for your reply.

In the official CMake reference document, it is mentioned that: "Some native build systems (such as Xcode) may not like targets that have only object files, so consider adding at least one real source file to any target that references $<TARGET_OBJECTS:objlib>.". This is exactly the problem I encountered;

When I build glog, although Xcode prompts "Build Successful", it only generates libglog_internal.a, but not libglogd.a. If you generate dynamic libraries, then it will only generate symbolic links, and the final libglogd.0.7.0.dylib is not generated.

This can be solved by adding an empty temporary file, of course there may be a better way to do this, but so far this solves my problem perfectly.

@sergiud
Copy link
Collaborator

sergiud commented Sep 8, 2023

Thanks for the explanation. Can't we just add an existing file such as any header instead of generating a bogus one? Or better yet get rid of the glogtest target completely and use the object library target directly? In either case, I want to avoid additional logic just for Xcode support.

@cn-nice
Copy link
Author

cn-nice commented Sep 8, 2023

Thanks for the explanation. Can't we just add an existing file such as any header instead of generating a bogus one? Or better yet get rid of the glogtest target completely and use the object library target directly? In either case, I want to avoid additional logic just for Xcode support.

I understand what you mean, so I made other attempts.
Add a cpp file that already exists (header files are not allowed, because they do not constitute a compilation unit), as follows:

add_library (glog
  $<TARGET_OBJECTS:glog_internal>
  src/logging.cc
)

This also solves the problem, and if you think it does, I'll resubmit the PR!

@sergiud
Copy link
Collaborator

sergiud commented Oct 8, 2023

I pushed b8a251c which deals with the issue. Please give it a try and let me know if you encounter any problems.

@sergiud sergiud closed this Oct 8, 2023
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.

2 participants