diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b1268c0d..9dc76d99a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/experimental/distributed/CMakeLists.txt b/experimental/distributed/CMakeLists.txt index 15ec7a016..fa6818f2d 100644 --- a/experimental/distributed/CMakeLists.txt +++ b/experimental/distributed/CMakeLists.txt @@ -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) diff --git a/experimental/distributed/tests/CMakeLists.txt b/experimental/distributed/tests/CMakeLists.txt index 75d8078ef..1f2920781 100644 --- a/experimental/distributed/tests/CMakeLists.txt +++ b/experimental/distributed/tests/CMakeLists.txt @@ -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) diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index e5a89a4e6..41a8dd482 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -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) diff --git a/libs/__main.cpp b/libs/__main.cpp deleted file mode 100644 index e5f7d71fe..000000000 --- a/libs/__main.cpp +++ /dev/null @@ -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; -} diff --git a/poc/CMakeLists.txt b/poc/CMakeLists.txt index 2be78a07e..9d7f71892 100644 --- a/poc/CMakeLists.txt +++ b/poc/CMakeLists.txt @@ -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() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 77b36ae71..f4dde1fb3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/benchmark/CMakeLists.txt b/tests/benchmark/CMakeLists.txt index d82f159cf..cee1ce30d 100644 --- a/tests/benchmark/CMakeLists.txt +++ b/tests/benchmark/CMakeLists.txt @@ -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 diff --git a/tests/concurrent/CMakeLists.txt b/tests/concurrent/CMakeLists.txt index 3f3b1c7d6..369be0867 100644 --- a/tests/concurrent/CMakeLists.txt +++ b/tests/concurrent/CMakeLists.txt @@ -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}) diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt index e0d04a77d..d2d998371 100644 --- a/tests/manual/CMakeLists.txt +++ b/tests/manual/CMakeLists.txt @@ -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() diff --git a/tests/property_based/CMakeLists.txt b/tests/property_based/CMakeLists.txt index d4e3dd0f2..4874c6dd7 100644 --- a/tests/property_based/CMakeLists.txt +++ b/tests/property_based/CMakeLists.txt @@ -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) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 23e76c80d..3dda16221 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -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) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 95b307551..95467a6ec 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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) diff --git a/tools/src/CMakeLists.txt b/tools/src/CMakeLists.txt index 404fff43a..d66fa442d 100644 --- a/tools/src/CMakeLists.txt +++ b/tools/src/CMakeLists.txt @@ -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 .)