From 4cedd4619db126984fd362a1a094d5a99e484f2b Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Sun, 16 Feb 2020 11:04:03 +0300 Subject: [PATCH] Code clean-up --- CMakeLists.txt | 4 +++ base/CMakeLists.txt | 5 --- base/common/CMakeLists.txt | 41 +++++++++------------- cmake/add_warning.cmake | 15 ++++++-- cmake/lib_name.cmake | 1 - dbms/CMakeLists.txt | 8 ----- dbms/programs/CMakeLists.txt | 1 - dbms/src/AggregateFunctions/CMakeLists.txt | 1 - utils/CMakeLists.txt | 5 --- 9 files changed, 33 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bd77cb1fcc..436e2cec6d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,6 +229,10 @@ endif () # Using system libs can cause a lot of warnings in includes (on macro expansion). if (UNBUNDLED OR NOT (OS_LINUX OR OS_DARWIN) OR ARCH_32) option (NO_WERROR "Disable -Werror compiler option" ON) + + if (NOT NO_WERROR) + add_warning(error) + endif () endif () # Make this extra-checks for correct library dependencies. diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 4cc9cb51670..cca578815e0 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -1,8 +1,3 @@ -if (NOT NO_WERROR) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") -endif () - if (USE_DEBUG_HELPERS) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${CMAKE_CURRENT_SOURCE_DIR}/common/iostream_debug_helpers.h") endif () diff --git a/base/common/CMakeLists.txt b/base/common/CMakeLists.txt index 7990ef74a57..32aa25e40ea 100644 --- a/base/common/CMakeLists.txt +++ b/base/common/CMakeLists.txt @@ -1,13 +1,12 @@ -set (CONFIG_COMMON ${CMAKE_CURRENT_BINARY_DIR}/config_common.h) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config_common.h.in ${CONFIG_COMMON}) +configure_file (config_common.h.in config_common.h) add_library(apple_rt apple_rt.cpp) -target_include_directories (apple_rt PUBLIC ${COMMON_INCLUDE_DIR}) +target_include_directories(apple_rt PRIVATE ..) # TODO: replace with proper header-only target. if (DEFINED APPLE_HAVE_CLOCK_GETTIME) target_compile_definitions(apple_rt PUBLIC -DAPPLE_HAVE_CLOCK_GETTIME=${APPLE_HAVE_CLOCK_GETTIME}) endif () -set (COMMON_SRCS +set (SRCS argsToConfig.cpp coverage.cpp DateLUT.cpp @@ -26,30 +25,24 @@ set (COMMON_SRCS ) if (ENABLE_REPLXX) - set (COMMON_SRCS + set (SRCS ${SRCS} ReplxxLineReader.cpp ReplxxLineReader.h - - ${COMMON_SRCS} ) endif () -add_library (common - ${COMMON_SRCS} - ${CONFIG_COMMON}) +add_library (common ${SRCS}) + +target_include_directories(common PUBLIC .. ${CMAKE_CURRENT_BINARY_DIR}/..) if (USE_INTERNAL_MEMCPY) set (MEMCPY_LIBRARIES memcpy) endif () -find_package (Threads) - if(CCTZ_INCLUDE_DIR) target_include_directories(common BEFORE PRIVATE ${CCTZ_INCLUDE_DIR}) endif() -target_include_directories (common PUBLIC ${COMMON_INCLUDE_DIR}) - if (NOT USE_INTERNAL_BOOST_LIBRARY) target_include_directories (common SYSTEM BEFORE PUBLIC ${Boost_INCLUDE_DIRS}) endif () @@ -62,19 +55,17 @@ if(CCTZ_LIBRARY) target_link_libraries(common PRIVATE ${CCTZ_LIBRARY}) endif() -if (ENABLE_REPLXX) - target_link_libraries(common PUBLIC replxx) -endif () +target_link_libraries(common PUBLIC replxx) target_link_libraries (common - PUBLIC - ${Poco_Util_LIBRARY} - ${Poco_Foundation_LIBRARY} - ${CITYHASH_LIBRARIES} - PUBLIC - ${Boost_SYSTEM_LIBRARY} - PRIVATE - ${MEMCPY_LIBRARIES}) + PUBLIC + ${Poco_Util_LIBRARY} + ${Poco_Foundation_LIBRARY} + ${CITYHASH_LIBRARIES} + ${Boost_SYSTEM_LIBRARY} + PRIVATE + ${MEMCPY_LIBRARIES} +) if (RT_LIBRARY) target_link_libraries (common PRIVATE ${RT_LIBRARY}) diff --git a/cmake/add_warning.cmake b/cmake/add_warning.cmake index 9bf2b1b5e93..3a776c98ab6 100644 --- a/cmake/add_warning.cmake +++ b/cmake/add_warning.cmake @@ -1,15 +1,26 @@ include (CheckCXXCompilerFlag) +include (CheckCCompilerFlag) # Try to add -Wflag if compiler supports it macro (add_warning flag) string (REPLACE "-" "_" underscored_flag ${flag}) string (REPLACE "+" "x" underscored_flag ${underscored_flag}) - check_cxx_compiler_flag("-W${flag}" SUPPORTS_FLAG_${underscored_flag}) - if (SUPPORTS_FLAG_${underscored_flag}) + + check_cxx_compiler_flag("-W${flag}" SUPPORTS_CXXFLAG_${underscored_flag}) + check_c_compiler_flag("-W${flag}" SUPPORTS_CFLAG_${underscored_flag}) + + if (SUPPORTS_CXXFLAG_${underscored_flag}) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${flag}") else () message (WARNING "Flag -W${flag} is unsupported") endif () + + if (SUPPORTS_CFLAG_${underscored_flag}) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W${flag}") + else () + message (WARNING "Flag -W${flag} is unsupported") + endif () + endmacro () # Try to add -Wno flag if compiler supports it diff --git a/cmake/lib_name.cmake b/cmake/lib_name.cmake index a793e8a1163..51a424cb4e2 100644 --- a/cmake/lib_name.cmake +++ b/cmake/lib_name.cmake @@ -1,5 +1,4 @@ set(DIVIDE_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libdivide) -set(COMMON_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/base ${ClickHouse_BINARY_DIR}/base) set(DBMS_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/dbms/src ${ClickHouse_BINARY_DIR}/dbms/src) set(DOUBLE_CONVERSION_CONTRIB_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/double-conversion) set(METROHASH_CONTRIB_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src) diff --git a/dbms/CMakeLists.txt b/dbms/CMakeLists.txt index eeda7aa6a1f..30c5f5fddb4 100644 --- a/dbms/CMakeLists.txt +++ b/dbms/CMakeLists.txt @@ -36,11 +36,6 @@ if (NOT MSVC) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") endif () -if (NOT NO_WERROR) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") -endif () - # Add some warnings that are not available even with -Wall -Wextra -Wpedantic. option (WEVERYTHING "Enables -Weverything option with some exceptions. This is intended for exploration of new compiler warnings that may be found to be useful. Only makes sense for clang." ON) @@ -577,9 +572,6 @@ target_include_directories (clickhouse_common_io PUBLIC ${DBMS_INCLUDE_DIR}) target_include_directories (clickhouse_common_io SYSTEM BEFORE PUBLIC ${DOUBLE_CONVERSION_INCLUDE_DIR}) -# also for copy_headers.sh: -target_include_directories (clickhouse_common_io BEFORE PRIVATE ${COMMON_INCLUDE_DIR}) - add_subdirectory (programs) add_subdirectory (tests) diff --git a/dbms/programs/CMakeLists.txt b/dbms/programs/CMakeLists.txt index 48fb30a8058..eea7a5f4fbe 100644 --- a/dbms/programs/CMakeLists.txt +++ b/dbms/programs/CMakeLists.txt @@ -112,7 +112,6 @@ if (CLICKHOUSE_SPLIT_BINARY) else () add_executable (clickhouse main.cpp) target_link_libraries (clickhouse PRIVATE clickhouse_common_io string_utils) - target_include_directories (clickhouse BEFORE PRIVATE ${COMMON_INCLUDE_DIR}) target_include_directories (clickhouse PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) if (ENABLE_CLICKHOUSE_SERVER) diff --git a/dbms/src/AggregateFunctions/CMakeLists.txt b/dbms/src/AggregateFunctions/CMakeLists.txt index dbbccc3bc7a..f0abc99811e 100644 --- a/dbms/src/AggregateFunctions/CMakeLists.txt +++ b/dbms/src/AggregateFunctions/CMakeLists.txt @@ -21,7 +21,6 @@ list(REMOVE_ITEM clickhouse_aggregate_functions_headers add_library(clickhouse_aggregate_functions ${clickhouse_aggregate_functions_sources}) target_link_libraries(clickhouse_aggregate_functions PRIVATE dbms PUBLIC ${CITYHASH_LIBRARIES}) -target_include_directories(clickhouse_aggregate_functions PRIVATE ${COMMON_INCLUDE_DIR}) if(ENABLE_TESTS) add_subdirectory(tests) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index fcf56e82b52..44ff7d6e828 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,8 +1,3 @@ -if (NOT NO_WERROR) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") -endif () - if(MAKE_STATIC_LIBRARIES) set(MAX_LINKER_MEMORY 3500) else()