Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor cmake: avoid flooding cmake includes namespace #761

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ option(USERVER_FEATURE_OTLP "Provide asynchronous OTLP exporters" "${USERVER_LIB

set(CMAKE_DEBUG_POSTFIX d)

include(cmake/UserverSetupEnvironment.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(UserverSetupEnvironment)
userver_setup_environment()

include(PrepareInstall)
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ userver_module(clickhouse

_userver_directory_install(COMPONENT clickhouse FILES
"${USERVER_ROOT_DIR}/cmake/modules/Findclickhouse-cpp.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)

if (USERVER_IS_THE_ROOT_PROJECT)
Expand Down
10 changes: 9 additions & 1 deletion cmake/ModuleHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,16 @@ macro(_userver_module_end)
return()
endif()

get_property(USERVER_CMAKE_DIR GLOBAL PROPERTY userver_cmake_dir)
if(NOT USERVER_CMAKE_DIR)
message(
FATAL_ERROR
"userver_setup_environment() should be run before trying to use any Find* from userver"
)
endif()

include(FindPackageHandleStandardArgs)
include(DetectVersion)
include("${USERVER_CMAKE_DIR}/DetectVersion.cmake")

set(name "${ARG_NAME}")
if(ARG_PACKAGE_NAME)
Expand Down
18 changes: 5 additions & 13 deletions cmake/UserverSetupEnvironment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ function(_userver_setup_environment_impl)
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER}")

cmake_policy(SET CMP0057 NEW)
if(NOT USERVER_CMAKE_DIR IN_LIST CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${USERVER_CMAKE_DIR}"
"${USERVER_CMAKE_DIR}/modules"
"${CMAKE_BINARY_DIR}"
PARENT_SCOPE
)
set(CMAKE_PREFIX_PATH
"${CMAKE_BINARY_DIR}/package_stubs"
${CMAKE_PREFIX_PATH}
PARENT_SCOPE
)
if(NOT "${USERVER_CMAKE_DIR}/modules" IN_LIST CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${USERVER_CMAKE_DIR}/modules" PARENT_SCOPE)
endif()
if(NOT "${CMAKE_BINARY_DIR}/package_stubs" IN_LIST CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/package_stubs" ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON PARENT_SCOPE)
Expand Down
3 changes: 2 additions & 1 deletion cmake/install/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ set(USERVER_TESTSUITE_DIR "${USERVER_CMAKE_DIR}/testsuite")
set(USERVER_IMPL_ORIGINAL_CXX_STANDARD @CMAKE_CXX_STANDARD@)
set(USERVER_IMPL_FEATURE_JEMALLOC @USERVER_FEATURE_JEMALLOC@)

list(APPEND CMAKE_MODULE_PATH "${USERVER_CMAKE_DIR}")
set_property(GLOBAL PROPERTY userver_cmake_dir "${USERVER_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${USERVER_CMAKE_DIR}/modules")

foreach(ITEM_COMPONENT IN LISTS userver_FIND_COMPONENTS)
include("${USERVER_CMAKE_DIR}/userver-${ITEM_COMPONENT}-config.cmake")
Expand Down
2 changes: 1 addition & 1 deletion cmake/install/userver-chaotic-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ find_package(userver REQUIRED COMPONENTS

set_property(GLOBAL PROPERTY userver_chaotic_extra_args "-I ${CMAKE_CURRENT_LIST_DIR}/../../../include")
set(USERVER_CHAOTIC_SCRIPTS_PATH "${USERVER_CMAKE_DIR}/chaotic")
include(ChaoticGen)
include("${USERVER_CMAKE_DIR}/ChaoticGen.cmake")

set(userver_chaotic_FOUND TRUE)
5 changes: 4 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,13 @@ _userver_install_targets(COMPONENT core TARGETS ${PROJECT_NAME})
_userver_directory_install(COMPONENT core FILES
"${USERVER_ROOT_DIR}/cmake/UserverTestsuite.cmake"
"${USERVER_ROOT_DIR}/cmake/install/userver-core-config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
)
_userver_directory_install(COMPONENT core FILES
"${USERVER_ROOT_DIR}/cmake/modules/Findc-ares.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindNghttp2.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindLibEv.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)

file(GLOB_RECURSE TESTSUITE_INSTALL_FILES
Expand Down
5 changes: 4 additions & 1 deletion grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ _userver_directory_install(COMPONENT grpc FILES
"${USERVER_ROOT_DIR}/cmake/SetupGrpc.cmake"
"${USERVER_ROOT_DIR}/cmake/UserverGrpcTargets.cmake"
"${USERVER_ROOT_DIR}/cmake/install/userver-grpc-config.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindUserverGrpc.cmake"
DIRECTORY
"${USERVER_ROOT_DIR}/scripts/grpc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
)
_userver_directory_install(COMPONENT grpc FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindUserverGrpc.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)
8 changes: 4 additions & 4 deletions kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ if(KAFKA_CPM)
endif()

_userver_directory_install(COMPONENT kafka
FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindRdKafka.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindLZ4.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindRdKafka.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindLZ4.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
)

if(USERVER_FEATURE_UTEST)
Expand Down
2 changes: 1 addition & 1 deletion libraries/s3api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ userver_module(s3api

_userver_directory_install(COMPONENT s3api FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindPugixml.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
)

if(USERVER_FEATURE_UTEST)
Expand Down
2 changes: 1 addition & 1 deletion mongo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ userver_module(mongo
_userver_directory_install(COMPONENT mongo FILES
"${USERVER_ROOT_DIR}/cmake/modules/Findmongoc.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findbson.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)

if (USERVER_IS_THE_ROOT_PROJECT)
Expand Down
2 changes: 1 addition & 1 deletion mysql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif()

_userver_directory_install(COMPONENT mysql FILES
"${USERVER_ROOT_DIR}/cmake/modules/Findlibmariadb.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
)

if (USERVER_IS_THE_ROOT_PROJECT)
Expand Down
5 changes: 4 additions & 1 deletion postgresql/pq-extra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ _userver_install_targets(COMPONENT postgres TARGETS ${PROJECT_NAME})

_userver_directory_install(COMPONENT postgres FILES
"${USERVER_ROOT_DIR}/cmake/SetupPostgresqlDeps.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
)
_userver_directory_install(COMPONENT postgres FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindPostgreSQLInternal.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindGssApi.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)
2 changes: 1 addition & 1 deletion redis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE

_userver_directory_install(COMPONENT redis FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindHiredis.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)

# Helper library for testing user code with redis. Provides mock_client_base.hpp
Expand Down
2 changes: 1 addition & 1 deletion rocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ userver_module(rocks
_userver_directory_install(COMPONENT rocks
FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindRocksDB.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
)
15 changes: 9 additions & 6 deletions universal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,6 @@ if (USERVER_IS_THE_ROOT_PROJECT)
endif()

_userver_directory_install(COMPONENT universal FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindCryptoPP.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibyamlcpp.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibzstd.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findcctz.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindJemalloc.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindUserverGBench.cmake"
"${USERVER_ROOT_DIR}/cmake/ModuleHelpers.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupGTest.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupGBench.cmake"
Expand All @@ -398,3 +392,12 @@ _userver_directory_install(COMPONENT universal FILES
"${USERVER_ROOT_DIR}/cmake/install/userver-universal-config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver
)
_userver_directory_install(COMPONENT universal FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindCryptoPP.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibyamlcpp.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibzstd.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findcctz.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindJemalloc.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindUserverGBench.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)
Loading