Skip to content

Commit

Permalink
cmake: generate binaries into build/ directory
Browse files Browse the repository at this point in the history
This makes our post-build source tree much cleaner, reducing the
amount of crap we have to add to .gitignore files, etc. It also
switches to using a different build directory for debug vs release
targets, which makes switching between the two much faster.

Change-Id: I7f4d255f5ff3ee9654ac6a4c52dd7db141cc4b45
Reviewed-on: http://gerrit.ent.cloudera.com:8080/321
Tested-by: jenkins
Reviewed-by: Michael Percy <[email protected]>
  • Loading branch information
toddlipcon authored and mpercy committed Aug 27, 2013
1 parent 9e9827d commit 3a36cc1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*.pb.cc
*.pb.h
*~
*-test
*.a
*.o

Expand All @@ -21,9 +20,4 @@ oprofile_data
*.service.h
*.proxy.cc
*.proxy.h
protoc-gen-krpc
tpch1
rle
cfile-dump
rwlock-perf
rpc-bench
build/
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ if ("${KUDU_USE_UBSAN}" OR "${KUDU_USE_ASAN}")
set(KUDU_STATIC_LINK ON)
endif()

# set compile output directory
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "CODE_COVERAGE_DEBUG")
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/debug/")
else()
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/release/")
endif()

# Link build/latest to the current build directory, to avoid developers
# accidentally running the latest debug build when in fact they're building
# release builds.
FILE(MAKE_DIRECTORY ${BUILD_OUTPUT_ROOT_DIRECTORY})
EXECUTE_PROCESS(COMMAND ln -T -sf ${BUILD_OUTPUT_ROOT_DIRECTORY}
${CMAKE_CURRENT_SOURCE_DIR}/build/latest)

# where to put generated libraries
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
set(ARCHIVE_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")

# where to put generated binaries
set(EXECUTABLE_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}")


INCLUDE_DIRECTORIES(src)

############################################################
Expand All @@ -109,11 +132,14 @@ INCLUDE_DIRECTORIES(src)
# a deadlock or anything.
SET(KUDU_TEST_TIMEOUT 900)

FUNCTION(ADD_KUDU_TEST TEST_NAME)
ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc)
ADD_TEST(${TEST_NAME} ${TEST_NAME})
SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES TIMEOUT ${KUDU_TEST_TIMEOUT})
TARGET_LINK_LIBRARIES(${TEST_NAME} ${KUDU_TEST_LINK_LIBS})
FUNCTION(ADD_KUDU_TEST REL_TEST_BINARY)
SET(TEST_PATH "${EXECUTABLE_OUTPUT_PATH}/${REL_TEST_BINARY}")
GET_FILENAME_COMPONENT(SRC_DIR ${TEST_PATH} PATH)
GET_FILENAME_COMPONENT(TEST_BINARY ${TEST_PATH} NAME)
ADD_EXECUTABLE(${TEST_BINARY} "${REL_TEST_BINARY}.cc")
ADD_TEST(${TEST_BINARY} "${BUILD_OUTPUT_ROOT_DIRECTORY}/${TEST_BINARY}")
SET_TESTS_PROPERTIES(${TEST_BINARY} PROPERTIES TIMEOUT ${KUDU_TEST_TIMEOUT})
TARGET_LINK_LIBRARIES(${TEST_BINARY} ${KUDU_TEST_LINK_LIBS})
ENDFUNCTION()

ENABLE_TESTING()
Expand Down
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ $ cmake .
$ make -j4
$ make test

The build artifacts, including the test binaries, will be stored in
'build/latest/', which itself is a symlink to either build/debug or
build/release.


Running tests with the clang AddressSanitizer enabled
------------------------------------------------------------
Expand All @@ -48,7 +52,7 @@ The tests will run significantly slower than without ASAN enabled, and if any
memory error occurs, the test that triggered it will fail. You can then use a
command like:

$ src/tablet/failing-test 2>&1 | asan_symbolize.py | c++filt | less
$ build/latest/failing-test 2>&1 | asan_symbolize.py | c++filt | less

to get a proper symbolized stack trace. The asan_symbolize program can be found
in the llvm source distribution:
Expand Down
2 changes: 1 addition & 1 deletion cmake_modules/FindKRPC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function(KRPC_GENERATE SRCS HDRS)
file(MAKE_DIRECTORY ${PROTO_DST_ROOT}/${FIL_PT})
endif()

SET(KRPC_BIN "${CMAKE_BINARY_DIR}/src/rpc/protoc-gen-krpc")
GET_TARGET_PROPERTY(KRPC_BIN protoc-gen-krpc LOCATION)
add_custom_command(
OUTPUT "${PROTO_CC_OUT}" "${PROTO_H_OUT}"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
Expand Down
2 changes: 0 additions & 2 deletions src/master/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions src/tserver/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion src/twitter-demo/.gitignore

This file was deleted.

4 changes: 3 additions & 1 deletion src/twitter-demo/parser-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ static string GetExecutableDir() {
}

static Status LoadFile(const string& name, vector<string>* lines) {
string path = GetExecutableDir() + "/" + name;
// The test runs from build/debug|release/, so go up two directories
// to get back to the source dir.
string path = GetExecutableDir() + "/" + "../../src/twitter-demo/" + name;
faststring data;
RETURN_NOT_OK(ReadFileToString(Env::Default(), path, &data));

Expand Down

0 comments on commit 3a36cc1

Please sign in to comment.