[go: nahoru, domu]

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

Added support to build project with CMake #4

Merged
merged 13 commits into from
Jul 18, 2019

Conversation

devsdmf
Copy link
Contributor
@devsdmf devsdmf commented Jul 1, 2019

Hi there,

I took some time to do a simple cmake build system implementation from my point of view that would be good for the project.

Also, I took the freedom to make some decisions for the project structure as the current build system (Bazel) provides an easier way to deal with the project dependencies. So, what I did was to add the dependent project (abseil-cpp) as a submodule of the project, if you guys think that would be better to set this dependency directly into the libs folder instead of using a git submodule, I can do the changes. Or if you get any better idea of how to deal with it, pls, let me know so I can make the changes.

@googlebot
Copy link

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

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 1, 2019

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 4, 2019

Hi there, any news about this?

@devsdmf devsdmf changed the title Added support to cmake build Added support to build project with CMake Jul 4, 2019
@epere4 epere4 added the enhancement New feature or request label Jul 11, 2019
@sdolgikh
Copy link

@devsdmf Hi. As I can see, your CMake configuration is incomplete. You don't provide targets for library and tests (no calls for add_library/add_tests). Which is curious, because this project is intended to be used as library at first.

@lvandeve
Copy link
Contributor
lvandeve commented Jul 11, 2019

Hi, would you mind changing the url of the submodule from git@github.com:abseil/abseil-cpp.git into https://github.com/abseil/abseil-cpp.git

because then building should work for everyone, while the git@ url requires ssh access afaik

edit: also +1 for adding the test and library. thanks!

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 11, 2019

Awesome, I'll do the changes tonight, thanks for the feedbacks! (:

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 11, 2019

Done, added static and shared libraries and tests

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 11, 2019

Also, I changed the dependency management approach to use configure time based resolution instead of git submodules.

@lvandeve
Copy link
Contributor

As of commit 5a7d82f, when following the instructions, using "make" after "cmake .. -DENABLE_TESTS=1" there's a linker error:

/usr/bin/ld: c-build/libs/abseil-cpp-src/absl/strings/libabsl_absl_strings.a(ascii.cc.o): relocation R_X86_64_PC32 against symbol `_ZN4absl14ascii_internal8kToLowerE' can not be used when making a shared object; recompile with -fPIC

Can you reproduce it as well?

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 12, 2019

Weird, I didn't got this error. What's your environment? (OS, compiler, etc..)

@lvandeve
Copy link
Contributor

Trying on Linux with gcc version 9.1.0, ld version (GNU Binutils) 2.32, clang v 8.0.0, cmake version 3.14.5
It's something related to the shared libary of course, not sure what exactly

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 12, 2019

Ok, I'm working from my macbook, I'll try in my linux computer tonight.

@lvandeve
Copy link
Contributor
lvandeve commented Jul 16, 2019

Maybe it's a matter of adding the -fPIC flag somewhere (I couldn't currently tell where exactly though, or if CMake should do that automatically)

@sdolgikh
Copy link
sdolgikh commented Jul 16, 2019

Adding SET(CMAKE_POSITION_INDEPENDENT_CODE ON) to the main CMakeLists.txt does the trick, everything builds successfully on Ubuntu 18.04 and all 20 tests work too. Didn't test the "install" stage though.

By the way, "make test" does not work as expected:

:~/projects/google/robotstxt/c-build$ make test
Running tests...
Test project /home/serg/projects/google/robotstxt/c-build
    Start 1: robots-test
1/1 Test #1: robots-test ......................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.01 sec

Also current cmake configuration does not support out of source builds:

CMake Error at CMakeLists.txt:86 (ADD_SUBDIRECTORY):
  ADD_SUBDIRECTORY not given a binary directory but the given source
  directory "/home/serg/projects/google/robotstxt-build/libs/abseil-cpp-src"
  is not a subdirectory of "/home/serg/projects/google/robotstxt".  When
  specifying an out-of-tree source a binary directory must be explicitly
  specified.


CMake Error at CMakeLists.txt:90 (ADD_SUBDIRECTORY):
  ADD_SUBDIRECTORY not given a binary directory but the given source
  directory "/home/serg/projects/google/robotstxt-build/libs/gtest-src" is
  not a subdirectory of "/home/serg/projects/google/robotstxt".  When
  specifying an out-of-tree source a binary directory must be explicitly
  specified.

Steps to reproduce:

cd .. && mkdir robotstxt-build && cd robotstxt-build
cmake ../robotstxt -DENABLE_TESTS=1

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 16, 2019

@sdolgikh thanks for the tip, I've made the changes in the CMakeLists.txt to set the correct flag.

Regarding to the make test target, I've tested adding the --verbose flag to the ctest command, and it works as expected.

I'm looking now for the problem with the build in a sibling folder, I'll push the changes in a few minutes.

…ation issue in Linux platforms and added new option for improve the library embedding in CMake based projects
@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 16, 2019

@sdolgikh I've tested the out of sources build and I could not reproduce the error, I don't know if the changes that I've pushed already fixed the problem, can you re-run your testes and let me know the error stills happening?

@sdolgikh
Copy link

@devsdmf I guess you neet to set CMAKE_POSITION_INDEPENDENT_CODE earlier, because it still fails with the same error. I placed it in the "build options" section.

Use this container to reproduce the problem:

FROM ubuntu:18.04
RUN apt update && apt upgrade -y
RUN apt install -y build-essential cmake git-core
RUN useradd -M -u 1001 -r cmakebuild && chown -R cmakebuild: /usr/src
USER cmakebuild
WORKDIR /usr/src
RUN git clone --depth=1 -b cmake-build https://github.com/devsdmf/robotstxt.git
RUN mkdir /usr/src/robotstxt-build
WORKDIR /usr/src/robotstxt-build
RUN /usr/bin/cmake /usr/src/robotstxt -DROBOTS_BUILD_TESTS=ON
ENV VERBOSE=1
RUN make
RUN make test

The problem with out-of-source builds seems to be solved in the latest revision.

@devsdmf
Copy link
Contributor Author
devsdmf commented Jul 16, 2019

Awesome! Now the issue is fixed! Ty!

@lvandeve
Copy link
Contributor

It works for me too, thanks!

@lvandeve lvandeve merged commit d37e80e into google:master Jul 18, 2019
@devsdmf devsdmf deleted the cmake-build branch July 23, 2019 20:33
epere4 added a commit that referenced this pull request Aug 23, 2019
PiperOrigin-RevId: 265049741
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants