From b143e43491239347a86323f192415a2d81acd19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Tue, 11 Jun 2019 20:02:27 -0400 Subject: [PATCH] enhancement(cmake): remove all mentions of "dirs" variable --- cmake/common/utils.cmake | 13 +++++++++++++ include/CMakeLists.txt | 4 ---- src/CMakeLists.txt | 9 ++++----- tests/CMakeLists.txt | 5 ++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cmake/common/utils.cmake b/cmake/common/utils.cmake index bc3cb7a8..71f2cf76 100644 --- a/cmake/common/utils.cmake +++ b/cmake/common/utils.cmake @@ -117,4 +117,17 @@ function(checklib flag type pkg) endif() endfunction() +function(get_include_dirs output) + get_filename_component(generated_sources_dir ${CMAKE_BINARY_DIR}/generated-sources ABSOLUTE) + get_filename_component(include_dir ${CMAKE_SOURCE_DIR}/include ABSOLUTE) + + set(${output} ${include_dir} ${generated_sources_dir} PARENT_SCOPE) +endfunction() + +function(get_sources_dirs output) + get_filename_component(src_dir ${CMAKE_SOURCE_DIR}/src ABSOLUTE) + + set(${output} ${src_dir} PARENT_SCOPE) +endfunction() + # }}} diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index cde79735..d949b689 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -2,8 +2,6 @@ # Generate settings.hpp # -list(APPEND dirs ${CMAKE_CURRENT_LIST_DIR}) - if(WITH_XRANDR) list(APPEND XPP_EXTENSION_LIST xpp::randr::extension) endif() @@ -20,6 +18,4 @@ configure_file( ${CMAKE_BINARY_DIR}/generated-sources/settings.hpp ESCAPE_QUOTES) -list(APPEND dirs ${CMAKE_BINARY_DIR}/generated-sources/) set(APP_VERSION ${APP_VERSION} PARENT_SCOPE) -set(dirs ${dirs} PARENT_SCOPE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 53e8b5e2..b61aa2b3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,9 +4,8 @@ # Source tree {{{ -get_filename_component(generated_sources_dir ${CMAKE_BINARY_DIR}/generated-sources ABSOLUTE) -get_filename_component(include_dir ${CMAKE_SOURCE_DIR}/include ABSOLUTE) -get_filename_component(src_dir ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE) +get_include_dirs(includes_dir) +get_sources_dirs(src_dir) set(ALSA_SOURCES ${src_dir}/adapters/alsa/control.cpp @@ -135,7 +134,7 @@ set(POLY_SOURCES # Target: polybar {{{ add_library(poly STATIC ${POLY_SOURCES}) -target_include_directories(poly PUBLIC ${include_dir} ${generated_sources_dir}) +target_include_directories(poly PUBLIC ${includes_dir}) target_link_libraries(poly PUBLIC Threads::Threads Cairo::CairoFC @@ -176,7 +175,7 @@ if(BUILD_IPC_MSG) utils/env.cpp utils/file.cpp utils/string.cpp) - target_include_directories(polybar-msg PRIVATE ${dirs}) + target_include_directories(polybar-msg PRIVATE ${includes_dir}) target_compile_options(polybar-msg PUBLIC $<$:$<$:-flto>>) install(TARGETS polybar-msg diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 02bfa07f..063aee87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,3 @@ -include_directories(${dirs}) -include_directories(${CMAKE_CURRENT_LIST_DIR}) - # Download and unpack googletest at configure time {{{ configure_file( CMakeLists.txt.in @@ -39,6 +36,8 @@ function(add_unit_test source_file) set(name "unit_test.${testname}") add_executable(${name} unit_tests/${source_file}.cpp) + get_include_dirs(includes_dir) + target_include_directories(${name} PRIVATE ${includes_dir} ${CMAKE_CURRENT_LIST_DIR}) # Link against gmock (this automatically links against gtest) target_link_libraries(${name} poly gmock_main)