Make almost all libs external

Summary:
Make 'benchmark' external project
Make 'fmt' external project
Make 'gtest' external project
Make 'gflags' external project
Skip fmt tests

Reviewers: mferencevic, mislav.bradac, buda

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D837
This commit is contained in:
Teon Banek 2017-09-27 13:03:44 +02:00
parent 56017e598e
commit e70f4de208
14 changed files with 108 additions and 62 deletions

View File

@ -113,9 +113,8 @@ message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
# setup external dependencies -------------------------------------------------
add_subdirectory(libs)
# fmt
set(fmt_source_dir ${libs_dir}/fmt)
# TODO: is this clang-tidy target needed anymore?
# linter setup (clang-tidy)
# all source files for linting
FILE(GLOB_RECURSE LINTER_SRC_FILES
@ -127,15 +126,15 @@ MESSAGE(STATUS "All cpp files for linting are: ${LINTER_SRC_FILES}")
# linter target clang-tidy
find_program(CLANG_TIDY "clang-tidy")
if(CLANG_TIDY)
add_custom_target(
clang-tidy
COMMAND /usr/bin/clang-tidy
${LINTER_SRC_FILES}
-config=''
--
-std=c++1y
-I${CMAKE_SOURCE_DIR}/include -I${fmt_source_dir}
)
add_custom_target(
clang-tidy
COMMAND /usr/bin/clang-tidy
${LINTER_SRC_FILES}
-config=''
--
-std=c++1y
-I${CMAKE_SOURCE_DIR}/include -I${FMT_INCLUDE_DIR}
DEPENDS fmt)
endif()
# -----------------------------------------------------------------------------
@ -189,9 +188,10 @@ message(STATUS "Generate coverage from unit tests: ${TEST_COVERAGE}")
# includes
include_directories(${src_dir})
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS})
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/libs) # cppitertools
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIR})
include_directories(SYSTEM ${GLOG_INCLUDE_DIR})
include_directories(SYSTEM ${FMT_INCLUDE_DIR})
# -----------------------------------------------------------------------------
# openCypher parser -----------------------------------------------------------
@ -264,8 +264,8 @@ set(memgraph_src_files
# -----------------------------------------------------------------------------
# memgraph_lib and memgraph_pic depend on these libraries
set(MEMGRAPH_ALL_LIBS stdc++fs Threads::Threads fmt
antlr_opencypher_parser_lib dl ${GLOG_LIBRARY} gflags)
set(MEMGRAPH_ALL_LIBS stdc++fs Threads::Threads ${FMT_LIBRARY}
antlr_opencypher_parser_lib dl ${GLOG_LIBRARY} ${GFLAGS_LIBRARY})
if (READLINE_FOUND)
list(APPEND MEMGRAPH_ALL_LIBS ${READLINE_LIBRARY})
endif()
@ -273,8 +273,7 @@ endif()
# STATIC library used by memgraph executables
add_library(memgraph_lib STATIC ${memgraph_src_files})
target_link_libraries(memgraph_lib ${MEMGRAPH_ALL_LIBS})
add_dependencies(memgraph_lib generate_opencypher_parser
glog)
add_dependencies(memgraph_lib generate_opencypher_parser fmt gflags glog)
# -----------------------------------------------------------------------------
# proof of concepts

View File

@ -13,9 +13,7 @@ include_directories(${src_dir})
# totally hacked, no idea why I need to include these again
# TODO: ask teon
include_directories(${CMAKE_SOURCE_DIR}/libs/fmt)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS})
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/libs)
# needed to include configured files (plan_compiler_flags.hpp)
set(generated_headers_dir ${CMAKE_BINARY_DIR}/generated_headers)

View File

@ -11,6 +11,8 @@ get_filename_component(test_type ${CMAKE_CURRENT_SOURCE_DIR} NAME)
file(GLOB_RECURSE test_type_cpps *.cpp)
message(STATUS "Available ${test_type} cpp files are: ${test_type_cpps}")
include_directories(${GTEST_INCLUDE_DIR})
# for each cpp file build binary and register test
foreach(test_cpp ${test_type_cpps})
@ -38,7 +40,8 @@ foreach(test_cpp ${test_type_cpps})
target_link_libraries(${target_name} memgraph_lib)
target_link_libraries(${target_name} ${MEMGRAPH_ALL_LIBS})
# gtest
target_link_libraries(${target_name} gtest gtest_main gmock)
add_dependencies(${target_name} gtest)
target_link_libraries(${target_name} ${GTEST_LIBRARIES})
if(${TEST_COVERAGE})
# for code coverage
target_link_libraries(${target_name} gcov)

View File

@ -27,28 +27,75 @@ set(ANTLR4_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/antlr4/runtime/Cpp/include/an
CACHE PATH "Path to antlr4 include directory" FORCE)
mark_as_advanced(ANTLR4_LIBRARY ANTLR4_INCLUDE_DIR)
# setup google benchmark
add_subdirectory(benchmark EXCLUDE_FROM_ALL)
# Setup google benchmark.
ExternalProject_Add(benchmark
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/benchmark
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/benchmark
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/benchmark)
set(BENCHMARK_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/benchmark/lib/libbenchmark.a
CACHE FILEPATH "Path to benchmark library" FORCE)
set(BENCHMARK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/benchmark/include
CACHE PATH "Path to benchmark include directory" FORCE)
mark_as_advanced(BENCHMARK_LIBRARY BENCHMARK_INCLUDE_DIR)
# setup fmt format
# fmt uses google test but if fmt isn't top project (here it isn't) fmt tests
# are disabled (reasonable configuration)
add_subdirectory(fmt EXCLUDE_FROM_ALL)
ExternalProject_Add(fmt
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/fmt
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fmt
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/fmt
# skip testing
-DFMT_TEST=OFF)
set(FMT_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/fmt/lib/libfmt.a
CACHE FILEPATH "Path to fmt library" FORCE)
set(FMT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include
CACHE PATH "Path to fmt include directory" FORCE)
mark_as_advanced(FMT_LIBRARY FMT_INCLUDE_DIR)
# setup rapidcheck
# setup rapidcheck (it cannot be external, since it doesn't have install
# target)
add_subdirectory(rapidcheck EXCLUDE_FROM_ALL)
# setup google test
add_subdirectory(googletest EXCLUDE_FROM_ALL)
ExternalProject_Add(gtest
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/googletest
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/googletest)
set(GTEST_LIBRARIES
${CMAKE_CURRENT_SOURCE_DIR}/googletest/lib/libgmock.a
${CMAKE_CURRENT_SOURCE_DIR}/googletest/lib/libgmock_main.a
${CMAKE_CURRENT_SOURCE_DIR}/googletest/lib/libgtest.a
${CMAKE_CURRENT_SOURCE_DIR}/googletest/lib/libgtest_main.a
CACHE FILEPATH "Path to googletest library" FORCE)
set(GTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest/include
CACHE PATH "Path to googletest include directory" FORCE)
mark_as_advanced(GTEST_LIBRARIES GTEST_INCLUDE_DIR)
# setup google flags
set(GFLAGS_BUILD_gflags_nothreads_LIB OFF)
set(GFLAGS_BUILD_gflags_LIB ON)
# Gflags has to be position independant otherwise Glog complains.
set(CMAKE_CXX_FLAGS_SAVED ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_subdirectory(gflags EXCLUDE_FROM_ALL)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVED})
ExternalProject_Add(gflags
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/gflags
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gflags
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
# Not needed, since gflags is C++ only.
# -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DBUILD_gflags_nothreads_LIB=OFF
-DREGISTER_INSTALL_PREFIX=OFF
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/gflags)
set(GFLAGS_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/gflags/lib/libgflags.a
CACHE FILEPATH "Path to gflags library" FORCE)
set(GFLAGS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gflags/include
CACHE PATH "Path to gflags include directory" FORCE)
mark_as_advanced(GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR)
# Setup google logging after gflags (so that glog can use it).
ExternalProject_Add(glog DEPENDS gflags
@ -58,16 +105,9 @@ ExternalProject_Add(glog DEPENDS gflags
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/glog
-Dgflags_DIR=${CMAKE_CURRENT_BINARY_DIR}/gflags)
-Dgflags_DIR=${CMAKE_CURRENT_SOURCE_DIR}/gflags/lib/cmake/gflags)
set(GLOG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/glog/lib/libglog.a CACHE FILEPATH
"Path to glog library" FORCE)
set(GLOG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glog/include CACHE PATH
"Path to glog include directory" FORCE)
mark_as_advanced(GLOG_LIBRARY GLOG_INCLUDE_DIR)
# setup cppitertools
# CLion compatiblity; the target won't be built
file(GLOB __CPPITERTOOLS_SOURCES __main.cpp
${CMAKE_SOURCE_DIR}/libs/cppitertools/*.hpp)
add_executable(__cppitertools_target ${__CPPITERTOOLS_SOURCES})
set_target_properties(__cppitertools_target PROPERTIES EXCLUDE_FROM_ALL 1)

View File

@ -1,6 +0,0 @@
// empty cpp main file that is needed to generate
// target for cppitertools in order to import the lib properly in CLion
int main() {
return 0;
}

View File

@ -1,4 +1,6 @@
find_package(Threads REQUIRED)
include_directories(${BENCHMARK_INCLUDE_DIR})
include_directories(${GTEST_INCLUDE_DIR})
# get all cpp abs file names recursively starting from current directory
file(GLOB poc_cpps *.cpp)
@ -26,9 +28,9 @@ foreach(poc_cpp ${poc_cpps})
# link libraries
target_link_libraries(${target_name} memgraph_lib)
# gtest
target_link_libraries(${target_name} gtest gtest_main gmock)
# google-benchmark
target_link_libraries(${target_name} benchmark ${CMAKE_THREAD_LIBS_INIT})
add_dependencies(${target_name} benchmark gtest)
target_link_libraries(${target_name} ${GTEST_LIBRARIES})
# google-benchmark requires threads
target_link_libraries(${target_name} ${BENCHMARK_LIBRARY} Threads::Threads)
endforeach()

View File

@ -21,6 +21,8 @@ add_custom_target(test_data
COMMAND cp -r ${test_data_src} ${test_data_dst})
# -----------------------------------------------------------------------------
include_directories(${GTEST_INCLUDE_DIR})
# benchmark test binaries
add_subdirectory(${PROJECT_SOURCE_DIR}/benchmark)

View File

@ -1,4 +1,5 @@
find_package(Threads REQUIRED)
include_directories(${BENCHMARK_INCLUDE_DIR})
# set current directory name as a test type
get_filename_component(test_type ${CMAKE_CURRENT_SOURCE_DIR} NAME)
@ -28,7 +29,8 @@ foreach(test_cpp ${test_type_cpps})
# link libraries
target_link_libraries(${target_name} memgraph_lib)
# google-benchmark
target_link_libraries(${target_name} benchmark ${CMAKE_THREAD_LIBS_INIT})
add_dependencies(${target_name} benchmark)
target_link_libraries(${target_name} ${BENCHMARK_LIBRARY} Threads::Threads)
# register test
set(output_path

View File

@ -28,7 +28,8 @@ foreach(test_cpp ${test_type_cpps})
# link libraries
target_link_libraries(${target_name} memgraph_lib)
# gtest
target_link_libraries(${target_name} gtest gtest_main gmock)
add_dependencies(${target_name} gtest)
target_link_libraries(${target_name} ${GTEST_LIBRARIES})
# register test
add_test(${target_name} ${exec_name})

View File

@ -33,6 +33,7 @@ foreach(test_cpp ${test_type_cpps})
# link libraries
target_link_libraries(${target_name} memgraph_lib)
# gtest
target_link_libraries(${target_name} gtest gtest_main gmock)
add_dependencies(${target_name} gtest)
target_link_libraries(${target_name} ${GTEST_LIBRARIES})
endforeach()

View File

@ -26,8 +26,9 @@ foreach(test_cpp ${test_type_cpps})
# link libraries
target_link_libraries(${target_name} memgraph_lib)
# gtest
target_link_libraries(${target_name} gtest gtest_main gmock)
target_link_libraries(${target_name} memgraph_lib rapidcheck)
add_dependencies(${target_name} gtest)
target_link_libraries(${target_name} ${GTEST_LIBRARIES})
target_link_libraries(${target_name} rapidcheck)
# register test
set(output_path ${CMAKE_BINARY_DIR}/test_results/unit/${target_name}.xml)

View File

@ -30,7 +30,8 @@ foreach(test_cpp ${test_type_cpps})
# link libraries
target_link_libraries(${target_name} memgraph_lib)
# gtest
target_link_libraries(${target_name} gtest gtest_main gmock)
add_dependencies(${target_name} gtest)
target_link_libraries(${target_name} ${GTEST_LIBRARIES})
if(${TEST_COVERAGE})
# for code coverage
target_link_libraries(${target_name} gcov)

View File

@ -66,9 +66,10 @@ endif()
# Setup external dependencies. Use EXCLUDE_FROM_ALL to prevent *installing* libs.
add_subdirectory(${PROJECT_SOURCE_DIR}/../libs libs EXCLUDE_FROM_ALL)
include_directories(${CMAKE_BINARY_DIR}/libs/gflags/include)
include_directories(${GLOG_INCLUDE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/../libs) # cppitertools
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIR})
include_directories(SYSTEM ${GLOG_INCLUDE_DIR})
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/../libs) # cppitertools
include_directories(SYSTEM ${FMT_INCLUDE_DIR})
# Include memgraph headers
set(memgraph_src_dir ${PROJECT_SOURCE_DIR}/../src)

View File

@ -14,7 +14,8 @@ add_executable(csv_to_snapshot
)
target_link_libraries(csv_to_snapshot stdc++fs Threads::Threads fmt gflags ${GLOG_LIBRARY})
add_dependencies(csv_to_snapshot glog)
target_link_libraries(csv_to_snapshot stdc++fs Threads::Threads ${FMT_LIBRARY}
${GFLAGS_LIBRARY} ${GLOG_LIBRARY})
add_dependencies(csv_to_snapshot gflags glog fmt)
install(TARGETS csv_to_snapshot
RUNTIME DESTINATION .)