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

support cmake compiling #227

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

johnzeng
Copy link

@johnzeng johnzeng commented Jan 31, 2017

This is like a pre-staging PR, I am not so sure about your code style, so please do some review and let me know what needs to be changed.

My dev env:

cmake version: v2.8.7
gcc version: 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
os: Ubuntu 12.04

compile command

cmake CMakeLists.txt
make

Supported:

  • build of daemon
  • build of static lib
  • build of Examples
  • build of test exec file
  • build of tags
  • build of docs
  • build of check and lint
  • build of storage tool
  • auto checkout the submodule of gtest
  • no source code is changed

Something changed

  • the test exec file is changed build/test/test -> build/TestRunner
  • the daemon exec file is changed build/LogCabin -> build/LogCabinServer
  • all example exec files are moved to build
  • cmake generates the .o files into CMakeFiles/${executable_name}.dir/${src_dir}.o so it will do some extra compiling for each executable files.

TODO

  • currently, I am using -std=c++0x to compile I will add support to -std=c++11 in the future.
  • lib detecting
  • rpm packing
  • testing action
  • Separate the flags for protoc generated files , gtest files and logcabin project files. You will see tons of warning when compiling those protoc generated files now.
  • update .travis.yml

Let me know if I still have something missed.

commit 2ee4027
Author: zengda <happy_zengda@126.com>
Date:   Tue Jan 31 13:23:35 2017 +0800

    1,Revert the proto import back to the original files so scons will not
    fail to build the project
    2,add a macro to build protobuf files

commit 7c52112
Author: zengda <happy_zengda@126.com>
Date:   Mon Jan 30 22:19:55 2017 +0800

    add test runner compile command

commit 16d889a
Author: zengda <happy_zengda@126.com>
Date:   Mon Jan 30 20:10:50 2017 +0800

    add example
    add storage tool

commit c379fd4
Author: zengda <happy_zengda@126.com>
Date:   Mon Jan 30 19:34:13 2017 +0800

    add server control and client lib

commit 193cbfe
Author: zengda <happy_zengda@126.com>
Date:   Mon Jan 30 12:44:06 2017 +0800

    first commit to cmake
@ongardie ongardie mentioned this pull request Feb 2, 2017
Copy link
Member

@ongardie ongardie left a comment

Choose a reason for hiding this comment

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

I'm new to reading cmake, but this seems very manageable. Here are a few little comments.

CMakeLists.txt Outdated
${TREE_PROTO_SRC}
)

add_custom_command(
Copy link
Member

Choose a reason for hiding this comment

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

Would file(MAKE_DIRECTORY [<directories>...]) work here? Same with the other mkdir -p below (line 234).

CMakeLists.txt Outdated
)
add_custom_command(
OUTPUT gtest/src/gtest-all.cc
COMMAND git submodule update --init
Copy link
Member

Choose a reason for hiding this comment

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

please add --recursive here (in case of nested submodules in the future)

CMakeLists.txt Outdated
foreach(FLAG ${FLAG_LIST})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}" )
endforeach()
# For some unknown reason, this suppresses some definitions
Copy link
Member

Choose a reason for hiding this comment

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

This comment was attached to -DSWIG before; better to place the comment on -DSWIG and/or mention -DSWIG in the text.

-Wno-used-but-marked-unused
-Wno-vla
-Wno-vla-extension
-Wno-weak-vtables
Copy link
Member

Choose a reason for hiding this comment

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

looks like -Weverything got lost during the port. I don't recall why it's on a separate env.Prepend() call in Sconsfile.

COMMAND scripts/cpplint.py
)
add_custom_target(lint
COMMAND scripts/cpplint.py
Copy link
Member

Choose a reason for hiding this comment

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

Please update the regex on line 3143 of cpplint.py to exclude the CMakeFiles directory.

CMakeLists.txt Outdated
COMMAND doxygen docs/Doxyfile
)
add_custom_target(tags
COMMAND ctags -R --exclude=build --exclude=docs .
Copy link
Member

Choose a reason for hiding this comment

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

Also exclude CMakeFiles here, please.

COMMAND scripts/cpplint.py
)
add_custom_target(docs
COMMAND doxygen docs/Doxyfile
Copy link
Member

Choose a reason for hiding this comment

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

docs/Doxyfile EXCLUDE (around line 800) should exclude CMakeFiles directory too.

.gitignore Outdated
CMakeFiles/
CMakeCache.txt
Makefile
*.cmake
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, please prefix all of these with / and sort them above alphabetically.

Also, if *.cmake is just for cmake_install.cmake, please just expand that out here. If there are other possible *.cmake files, then disregard this.

@ongardie
Copy link
Member

ongardie commented Feb 2, 2017

Hey @johnzeng, thanks for doing the heavy lifting here! It's looking pretty good already. A few more thoughts:

the daemon exec file is changed build/LogCabin -> build/LogCabinServer

logcabind might be better to match the install name.

cmake generates the .o files into CMakeFiles/${executable_name}.dir/${src_dir}.o so it will do some extra compiling for each executable files.

I can't tell quite how bad this is. We should time clean and incremental scons vs cmake builds and double-check that compile times haven't gotten much worse.

The protobuf warnings are indeed painful. You might want to prioritize that just because it'll make it easier to see what's going on without all the clutter.

You might not be aware of .travis.yml, but that'll need slight updating too (since you have a TODO list in your description above).

@johnzeng
Copy link
Author

johnzeng commented Feb 3, 2017

Thanks for your comment ,I do know that there is a .travis.yml file , I think it should be modified after the switching. I will do some update on these codes when I get time.

Fix doxy ignore
Fix ctag ignore
Fix mkdir command
Fix flag comment
Fix missing flags for clang
@johnzeng
Copy link
Author

johnzeng commented Feb 4, 2017

I've made some improvement.

  • fixed all your commented codes
  • use different compile flags for different types of fies, so protobuf generated files won't throw lots of warning now
  • libray dependency checking is done
  • build/LogCabinServer changed back to build/LogCabin .(Note: case-unsensitive file system(like the default file system of OSX) will get error because they treat locabin and LogCabin as same target, and that's why I changed it to LogCabinServer )
  • Improve the compile behaviour of .o files, you don't need to compile them again and again now.
  • add gcc version detecting to determine -std flag

about cmake object files

It's a default behaviour that cmake will generate .o files into CMakeFiles/${executable_name}.dir/ for different executable target, it is designed to make sure different target can be built in different setting. But I think logcabin doesn't need this , so I compile them into three static libs:

  • the original locabin static lib
  • server lib for files in /Server
  • and storage lib for files in /Storage

And then linking these libs into the executable files instead of inputing .cc files directly.

about compiler version detecting

In Sconstruct file, you use ${compiler} -v to detect and regex math (gcc|lcang) version to get the version of compiler, it works for gcc on my Linux, but not works for OSX. On OSX, the output is like:

➜  logcabin git:(feature/cmake) clang -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

And this will only affect the gcc's -std flag, so I just don't check compiler version for clang.

Hopes you know this inconvinence.

Copy link
Member

@ongardie ongardie left a comment

Choose a reason for hiding this comment

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

Great work, @johnzeng.

I'm encountering errors with parallel builds (make -j):

build/Protocol/RaftLogMetadata.proto: File not found.
build/Storage/SimpleFileLog.proto: Import "build/Protocol/RaftLogMetadata.proto" was not found or had errors.
build/Storage/SimpleFileLog.proto:26:14: "Protocol.RaftLogMetadata.Metadata" is not defined.

Perhaps we need to copy all the proto files over into build/ before any are compiled. Is that difficult?

CMakeLists.txt Outdated
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message("using gcc")

## detect gcc version to decide wich c std should we use
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

@johnzeng johnzeng Feb 10, 2017

Choose a reason for hiding this comment

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

I am using 2.8.7 version of cmake and this var is not available on this version. On ubuntu12.04, apt-get will install v2.8.7 by default

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry, disregard then.

CMakeLists.txt Outdated
set(PATH_VAR_NAME "${LIB_NAME}_PATH")
find_library(${PATH_VAR_NAME} NAMES ${LIB_NAME})
if("${${PATH_VAR_NAME}}" STREQUAL "${PATH_VAR_NAME}-NOTFOUND")
## sending warrning alows user to compile the lib without unnecessary dependency
Copy link
Member

Choose a reason for hiding this comment

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

nit: alows -> allows

CMakeLists.txt Outdated
check_lib_exist(cryptopp)

# collect all libs when they all exist
SET(LIBRERYS pthread protobuf rt cryptopp)
Copy link
Member

Choose a reason for hiding this comment

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

LIBRERYS -> LIBRARIES or LIBS? This one took me a minute to decipher :)

Copy link
Author

Choose a reason for hiding this comment

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

sorry,misspelt. Will fix it

Copy link
Member

Choose a reason for hiding this comment

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

LIBRARYS is closer but still not correct. The plural of library is libraries. Programmers often shorten it to libs, so pick one of those two please.

CMakeLists.txt Outdated
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message("using clang")
Copy link
Member

@ongardie ongardie Feb 9, 2017

Choose a reason for hiding this comment

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

I think you can safely get rid of this message now, since it's shown in the default cmake output anyway. Same with "using gcc".

@ongardie
Copy link
Member

ongardie commented Feb 9, 2017

Compile times are looking good. Here's some rough times from my dual-core 2012 laptop:

build complete incremental
cmake x 1 CPU 2m39s 0m51s
scons x 1 CPU 3m02s 0m44s
cmake x 5 CPU 1m16s 0m27s
scons x 5 CPU 1m24s 0m22s

From running the following script (keep this outside your git clone or it'll delete itself):

#!/bin/bash
set -e

# ProtoBuf files to copy to build/ first as workaround for cmake parallel build
# issue.
PROTO="
  Core/ProtoBufTest.proto
  Protocol/Client.proto
  Protocol/Raft.proto
  Protocol/RaftLogMetadata.proto
  Protocol/ServerControl.proto
  Protocol/ServerStats.proto
  Server/SnapshotMetadata.proto
  Server/SnapshotStateMachine.proto
  Server/SnapshotStats.proto
  Storage/SegmentedLog.proto
  Storage/SimpleFileLog.proto
  Tree/Snapshot.proto
"

INCRFILE=Storage/Log.h

build() {
  case $BUILD in
    "cmake")
      for FILE in $PROTO; do
        mkdir -p $(dirname build/$FILE)
        cp $FILE build/$FILE
      done
      time sh -c "cmake . && make -j$CPUS" > /dev/null
    ;;

    "scons")
      time scons NUMCPUS=$CPUS > /dev/null
    ;;
  esac
}

for RUN in {1..3}; do
  for CPUS in 1 5; do
    for BUILD in cmake scons; do
      echo "---"
      echo "Running clean build with $BUILD on $CPUS CPUs"
      git clean -fdx > /dev/null
      git checkout $INCRFILE
      build
      echo "---"
      echo "Running incremental build with $BUILD on $CPUS CPUs"
      echo >> $INCRFILE
      build
    done
  done
done

The full output was:

Running clean build with cmake on 1 CPUs
using gcc

real	2m39.385s
user	2m28.208s
sys	0m9.104s
---
Running incremental build with cmake on 1 CPUs
using gcc

real	0m51.379s
user	0m47.788s
sys	0m2.980s
---
Running clean build with scons on 1 CPUs

real	3m1.918s
user	2m50.452s
sys	0m10.184s
---
Running incremental build with scons on 1 CPUs

real	0m43.840s
user	0m41.508s
sys	0m2.144s
---
Running clean build with cmake on 5 CPUs
using gcc

real	1m16.307s
user	4m24.328s
sys	0m13.732s
---
Running incremental build with cmake on 5 CPUs
using gcc

real	0m26.968s
user	1m16.488s
sys	0m4.096s
---
Running clean build with scons on 5 CPUs

real	1m23.762s
user	4m55.588s
sys	0m15.692s
---
Running incremental build with scons on 5 CPUs

real	0m22.370s
user	1m9.072s
sys	0m3.304s
---
Running clean build with cmake on 1 CPUs
using gcc

real	2m40.216s
user	2m29.092s
sys	0m9.084s
---
Running incremental build with cmake on 1 CPUs
using gcc

real	0m52.122s
user	0m48.628s
sys	0m2.848s
---
Running clean build with scons on 1 CPUs

real	3m0.541s
user	2m48.872s
sys	0m10.444s
---
Running incremental build with scons on 1 CPUs

real	0m44.658s
user	0m42.236s
sys	0m2.220s
---
Running clean build with cmake on 5 CPUs
using gcc

real	1m15.214s
user	4m24.972s
sys	0m13.532s
---
Running incremental build with cmake on 5 CPUs
using gcc

real	0m26.388s
user	1m17.080s
sys	0m4.132s
---
Running clean build with scons on 5 CPUs

real	1m24.206s
user	4m56.604s
sys	0m15.804s
---
Running incremental build with scons on 5 CPUs

real	0m23.377s
user	1m10.392s
sys	0m3.172s
---
Running clean build with cmake on 1 CPUs
using gcc

real	2m39.735s
user	2m28.880s
sys	0m8.824s
---
Running incremental build with cmake on 1 CPUs
using gcc

real	0m52.694s
user	0m49.004s
sys	0m3.072s
---
Running clean build with scons on 1 CPUs

real	3m22.524s
user	3m10.216s
sys	0m10.864s
---
Running incremental build with scons on 1 CPUs

real	0m46.009s
user	0m43.376s
sys	0m2.444s
---
Running clean build with cmake on 5 CPUs
using gcc

real	1m16.466s
user	4m23.892s
sys	0m13.692s
---
Running incremental build with cmake on 5 CPUs
using gcc

real	0m25.774s
user	1m17.000s
sys	0m4.196s
---
Running clean build with scons on 5 CPUs

real	1m23.515s
user	4m56.128s
sys	0m15.764s
---
Running incremental build with scons on 5 CPUs

real	0m22.251s
user	1m9.988s
sys	0m3.312s

@ongardie
Copy link
Member

ongardie commented Feb 9, 2017

I think we should merge this once you've taken care of those minor nits, then address the remaining to-do items in subsequent PRs. Sound good?

@johnzeng
Copy link
Author

It's ok to copy proto files at the begin. Will fix it soon

copy all proto files at the beginning of building
remvoe useless debug message
@johnzeng
Copy link
Author

Please clean up the build, CMakeFiles and CMakeCache files and re-run it with make -j8 (or something else if you get enough CPU cores) to test it. My working env is a virtual machine with single core only, so I am not sure if it works perfectly or not.

@ongardie
Copy link
Member

Thanks. I tried a couple of make -j builds and they seem to work.

@ongardie
Copy link
Member

BTW the Ninja build is broken for me:

$ cmake -GNinja . && ninja -j1
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ongardie/logcabin
[6/156] Building CXX object CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o
FAILED: /usr/bin/c++    -fno-strict-overflow -fPIC -std=c++11 -I./gtest/include -I./gtest -I./build -I./include -I.      -DSWIG -MMD -MT CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o -MF CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o.d -o CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o -c Server/RaftConsensusInvariants.cc
In file included from Server/RaftConsensusInvariants.cc:18:0:
./Server/RaftConsensus.h:24:38: fatal error: build/Protocol/Client.pb.h: No such file or directory
 #include "build/Protocol/Client.pb.h"
                                      ^
compilation terminated.
ninja: build stopped: subcommand failed.
Exited with status 1.

I don't know how much we care (I'm perfectly OK with not supporting Ninja), except that this may be symptom of having incorrectly defined dependencies.

That's with cmake 3.0.2 and ninja 1.3.4.

@johnzeng
Copy link
Author

Fixed the spelling error. As for ninja build, I haven't really used it yet, but it looks like the dependency is wrong, build/Protocol/Client.pb.h should be generated before Server/RaftConsensus.h is compiled. I add protocol as a dependency of Server, pls try to compile it by ninja again, let me know if it works or not.

@tigerzhang
Copy link

@ongardie Ninja works for me, with cmake 3.6.3 and 1.3.4.

@johnzeng I found a problem, this version of CMakeList.txt only works in the root direcotry of the project, cause of copying of the .proto files.

If I build the project in a subdirectory, I got errors.

$ mkdir cmake_build
$ cd !$
$ cmake ..
$ make
Scanning dependencies of target copy_proto_files_to_build
cp: failed to get attributes of ‘Core’: No such file or directory
cp: failed to get attributes of ‘Protocol’: No such file or directory
...

It's expected to work.

@ongardie
Copy link
Member

Well, 7ecba30 didn't quite fix Ninja for me:

$ cmake -GNinja . && ninja -j1
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:384 (add_dependencies):
  Policy CMP0046 is not set: Error on non-existent dependency in
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "build/Protocol/Client.pb.cc" of target
  "ServerSrcObject" does not exist.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:384 (add_dependencies):
  Policy CMP0046 is not set: Error on non-existent dependency in
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "build/Protocol/Raft.pb.cc" of target
  "ServerSrcObject" does not exist.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:384 (add_dependencies):
  Policy CMP0046 is not set: Error on non-existent dependency in
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "build/Protocol/RaftLogMetadata.pb.cc" of target
  "ServerSrcObject" does not exist.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:384 (add_dependencies):
  Policy CMP0046 is not set: Error on non-existent dependency in
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "build/Protocol/ServerControl.pb.cc" of target
  "ServerSrcObject" does not exist.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:384 (add_dependencies):
  Policy CMP0046 is not set: Error on non-existent dependency in
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "build/Protocol/ServerStats.pb.cc" of target
  "ServerSrcObject" does not exist.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/ongardie/logcabin
[6/156] Building CXX object CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o
FAILED: /usr/bin/c++    -fno-strict-overflow -fPIC -std=c++11 -I./gtest/include -I./gtest -I./build -I./include -I.      -DSWIG -MMD -MT CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o -MF CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o.d -o CMakeFiles/ServerSrcObject.dir/Server/RaftConsensusInvariants.cc.o -c Server/RaftConsensusInvariants.cc
In file included from Server/RaftConsensusInvariants.cc:18:0:
./Server/RaftConsensus.h:24:38: fatal error: build/Protocol/Client.pb.h: No such file or directory
 #include "build/Protocol/Client.pb.h"
                                      ^
compilation terminated.
ninja: build stopped: subcommand failed.

Maybe @tigerzhang's newer cmake version makes a difference.

@ongardie
Copy link
Member

I did get a successful ninja -j5 build after making these changes:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2d5391d..4b7de53 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -174,6 +174,7 @@ set(SERVER_PROTO_FOR_STORAGE_TOOL_SRC
 set(SERVER_PROTO_SRC
     build/Server/SnapshotStats.pb.cc
     ${SERVER_PROTO_FOR_STORAGE_TOOL_SRC}
+    ${PROTOCOL_SRC}
     )
 
 set(STORAGE_PROTO
@@ -184,6 +185,7 @@ set(STORAGE_PROTO
 set(STORAGE_PROTO_SRC
     build/Storage/SegmentedLog.pb.cc
     build/Storage/SimpleFileLog.pb.cc
+    ${PROTOCOL_SRC}
     )
 
 set(TREE_PROTO
@@ -381,7 +383,6 @@ add_library(ServerSrcObject STATIC
     ${SERVER_SRC}
     ${SERVER_PROTO_SRC}
     )
-add_dependencies(ServerSrcObject ${PROTOCOL_SRC})
 
 add_library(StorageSrcObject STATIC 
     ${STORAGE_PROTO_SRC}

But I don't know how much wasted compiler effort this might be causing.

@tigerzhang
Copy link

@ongardie CMake shipped a protobuf module. That module should work well and efficiently.

And I guess I know why @johnzeng was trying to write an ad-hoc protobuf compiling command for logcabin. The shipped protobuf module doesn't work with our protobuf importing manner, ex:

import "build//.proto"

I modified all these imports and removed the leading "build/" in my forked repo. But there are a couple of modifications needed for .h/.cc files, for header file including.

I agree we can go with @johnzeng's version at this stage. Nothing changed, just a new CMakeLists.txt file added.

@johnzeng
Copy link
Author

@ongardie Including these files into SERVER_PROTO_SRC and STORAGE_PROTO may fix the error, but I believe make them as a target which is built before these two object will be better.

Another thing is about copying proto files to build and including proto files from build. I don't know why you did that before, looks like scons won't work if you don't do that. So I just kept them. If you think changing these codes is acceptable, it will be much easier to build.

@tigerzhang For cmake v2.8.7, cmake always generate the build files beside the cmakelist.txt so I didn't realize that the cp command will result in an error. I am looking for a better solution.

➜  logcabin git:(feature/cmake) ✗ mkdir compiling
➜  logcabin git:(feature/cmake) ✗ cd compiling
➜  compiling git:(feature/cmake) ✗ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/johnzeng/logcabin

@jeking3
Copy link

jeking3 commented Feb 12, 2018

In your pull request description you gave some bad advice to do an in-tree build:

cmake CMakeLists.txt
make

It is much better to do an out-of-tree build so you do not dirty up the source tree with build files, and to use separate output directories for each build type. This makes building exactly what you want easier to do. You can also use cmake to run the build in a platform-independent manner that will work on all platforms:

mkdir ../build-Debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=<some dir> ../logcabin/CMakeLists.txt
cmake --build . --config Debug --target install

Note that on Windows, setting CMAKE_BUILD_TYPE when running cmake doesn't do anything, as you select the build type when building; however on Linux you set the build type while running cmake.

@jeking3
Copy link

jeking3 commented Feb 12, 2018

It would be advisable, before merging this, to:

  1. [required] Have the cmake build work in Travis CI.
  2. [desired] Add Appveyor support to prove Windows builds work too.
  3. [optional] add codecov.io support so we can see what kind of code coverage this project provides as part of build and test.

-Weverything
-Wno-unreachable-code ## clang 3.4 is knon to emit warnings without -Wno-unreachable-code, I will move this out when I have idea to get compiler version
)
foreach(FLAG in FLAG_LIST)

Choose a reason for hiding this comment

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

should be ${FLAG_LIST}

${SERVER_SRC}
${SERVER_PROTO_SRC}
)
add_dependencies(ServerSrcObject ${PROTOCOL_SRC})
Copy link

@jackyjia jackyjia Sep 12, 2018

Choose a reason for hiding this comment

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

This doesn't work with cmake 3.1x plus clang++ 6.0, as StorageSrcObject will be built first. Add ${PROTOCOL_SRC} to above add_library solves the issue.

${STORAGE_PROTO_SRC}
${STORAGE_SRC}
)
add_dependencies(StorageSrcObject ${PROTOCOL_SRC})

Choose a reason for hiding this comment

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

ditto

jackyjia pushed a commit to jackyjia/logcabin that referenced this pull request Sep 24, 2018
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.

None yet

5 participants