Remove global include directories in CMake

Summary:
All external libraries now automatically include their include directories. It
is necessary only to link to the external library using
`target_link_libraries(target library)` and the include directory of the
library will be automatically available for the binary.

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2654
This commit is contained in:
Matej Ferencevic 2020-01-31 16:27:10 +01:00
parent a3229881bf
commit 6c422f3208
4 changed files with 11 additions and 22 deletions

View File

@ -148,16 +148,6 @@ find_package(OpenSSL REQUIRED)
set(libs_dir ${CMAKE_SOURCE_DIR}/libs)
add_subdirectory(libs EXCLUDE_FROM_ALL)
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIR})
include_directories(SYSTEM ${GLOG_INCLUDE_DIR})
include_directories(SYSTEM ${FMT_INCLUDE_DIR})
include_directories(SYSTEM ${ANTLR4_INCLUDE_DIR})
include_directories(SYSTEM ${BZIP2_INCLUDE_DIR})
include_directories(SYSTEM ${ZLIB_INCLUDE_DIR})
include_directories(SYSTEM ${ROCKSDB_INCLUDE_DIR})
include_directories(SYSTEM ${LIBRDKAFKA_INCLUDE_DIR})
# Optional subproject configuration -------------------------------------------
option(TEST_COVERAGE "Generate coverage reports from running memgraph" OFF)
option(TOOLS "Build tools binaries" ON)

View File

@ -17,7 +17,7 @@ function(import_header_library name include_dir)
mark_as_advanced(${_upper_name}_INCLUDE_DIR)
endfunction(import_header_library)
function(import_library name type location)
function(import_library name type location include_dir)
add_library(${name} ${type} IMPORTED GLOBAL)
if (${ARGN})
# Optional argument is the name of the external project that we need to
@ -26,10 +26,12 @@ function(import_library name type location)
else()
add_dependencies(${name} ${name}-proj)
endif()
# Unfortunately, we cannot use include_dir before it is built.
# set_property(TARGET ${name} PROPERTY
# INTERFACE_INCLUDE_DIRECTORIES ${include_dir})
set_property(TARGET ${name} PROPERTY IMPORTED_LOCATION ${location})
# We need to create the include directory first in order to be able to add it
# as an include directory. The header files in the include directory will be
# generated later during the build process.
file(MAKE_DIRECTORY ${include_dir})
target_include_directories(${name} INTERFACE ${include_dir})
endfunction(import_library)
# Calls `ExternalProject_Add(${name}-proj` with default arguments for cmake
@ -74,7 +76,7 @@ macro(import_external_library name type library_location include_dir)
set(${_upper_name}_INCLUDE_DIR ${include_dir} CACHE FILEPATH
"Path to ${name} include directory" FORCE)
mark_as_advanced(${_upper_name}_LIBRARY ${_upper_name}_INCLUDE_DIR)
import_library(${name} ${type} ${${_upper_name}_LIBRARY})
import_library(${name} ${type} ${${_upper_name}_LIBRARY} ${${_upper_name}_INCLUDE_DIR})
endmacro(import_external_library)
# setup antlr
@ -131,10 +133,10 @@ set(GTEST_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/googletest/lib/libgtest.a
set(GTEST_MAIN_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/googletest/lib/libgtest_main.a
CACHE FILEPATH "Path to gtest_main library" FORCE)
mark_as_advanced(GTEST_INCLUDE_DIR GMOCK_LIBRARY GMOCK_MAIN_LIBRARY GTEST_LIBRARY GTEST_MAIN_LIBRARY)
import_library(gtest STATIC ${GTEST_LIBRARY} gtest-proj)
import_library(gtest_main STATIC ${GTEST_MAIN_LIBRARY} gtest-proj)
import_library(gmock STATIC ${GMOCK_LIBRARY} gtest-proj)
import_library(gmock_main STATIC ${GMOCK_MAIN_LIBRARY} gtest-proj)
import_library(gtest STATIC ${GTEST_LIBRARY} ${GTEST_INCLUDE_DIR} gtest-proj)
import_library(gtest_main STATIC ${GTEST_MAIN_LIBRARY} ${GTEST_INCLUDE_DIR} gtest-proj)
import_library(gmock STATIC ${GMOCK_LIBRARY} ${GTEST_INCLUDE_DIR} gtest-proj)
import_library(gmock_main STATIC ${GMOCK_MAIN_LIBRARY} ${GTEST_INCLUDE_DIR} gtest-proj)
# setup google flags
set(GFLAGS_NO_FILENAMES "0")

View File

@ -1,5 +1,3 @@
include_directories(${GTEST_INCLUDE_DIR})
# benchmark test binaries
add_subdirectory(benchmark)

View File

@ -12,7 +12,6 @@ function(add_benchmark test_cpp)
# requires unique logical target names
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${exec_name})
target_link_libraries(${target_name} benchmark)
target_include_directories(${target_name} PRIVATE ${BENCHMARK_INCLUDE_DIR})
# register test
add_test(${target_name} ${exec_name})
add_dependencies(memgraph__benchmark ${target_name})