Skip to content

Commit

Permalink
Add parse custom cmake functions
Browse files Browse the repository at this point in the history
  • Loading branch information
idzm committed Feb 8, 2025
1 parent b2784e4 commit ad4c606
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 343 deletions.
51 changes: 51 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
# ----------------------------------
# Options affecting listfile parsing
# ----------------------------------
with section("parse"):

# Specify structure for custom cmake functions
additional_commands = {
"userver_module": {
"flags": ["NO_INSTALL"],
"kwargs": {
"SOURCE_DIR": "*",
"LINK_LIBRARIES": "*",
"LINK_LIBRARIES_PRIVATE": "*",
"UTEST_SOURCES": "*",
"UTEST_DIRS": "*",
"UTEST_LINK_LIBRARIES": "*",
"INCLUDE_DIRS": "*",
"DBTEST_SOURCES": "*",
"DBTEST_DATABASES": "*",
"UBENCH_DIRS": "*",
"UBENCH_DATABASES": "*",
},
"pargs": 1,
},
"_userver_directory_install": {
"kwargs": {
"COMPONENT": "*",
"DIRECTORY": "*",
"FILES": "*",
"DESTINATION": "*",
},
},
"userver_target_generate_openapi_client": {
"kwargs": {
"NAME": "*",
"OUTPUT_DIR": "*",
"SCHEMAS": "*",
"UTEST_LINK_LIBRARIES": "*",
},
"pargs": 1,
},
"userver_venv_setup": {
"kwargs": {
"NAME": "*",
"PYTHON_OUTPUT_VAR": "*",
"REQUIREMENTS": "*",
},
"flags": ["UNIQUE"],
}
}

# -----------------------------
# Options affecting formatting.
# -----------------------------
Expand Down
19 changes: 7 additions & 12 deletions chaotic-openapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ include(ChaoticGen)

userver_module(
chaotic-openapi
SOURCE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES
userver-core
userver-chaotic
UTEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
UTEST_LINK_LIBRARIES
userver-core
userver-chaotic
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES userver-core userver-chaotic
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
UTEST_LINK_LIBRARIES userver-core userver-chaotic
)

if(USERVER_BUILD_TESTS)
Expand All @@ -27,6 +21,7 @@ if(USERVER_BUILD_TESTS)
endif()

_userver_directory_install(
COMPONENT chaotic-openapi DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/chaotic_openapi" DESTINATION
"${CMAKE_INSTALL_LIBDIR}/userver"
COMPONENT chaotic-openapi
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/chaotic_openapi"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/userver"
)
9 changes: 3 additions & 6 deletions chaotic-openapi/golden_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ include(ChaoticGen)
file(GLOB_RECURSE SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/schemas/*.yaml")
userver_target_generate_openapi_client(
${PROJECT_NAME}-chgen
NAME
test
OUTPUT_DIR
"${CMAKE_CURRENT_BINARY_DIR}/src"
SCHEMAS
${SCHEMAS}
NAME test
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/src"
SCHEMAS ${SCHEMAS}
)

add_test(NAME chaotic-openapi-golden
Expand Down
34 changes: 16 additions & 18 deletions chaotic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ project(userver-chaotic CXX)
include(ChaoticGen)

userver_module(
chaotic SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
chaotic
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
)

if(USERVER_BUILD_TESTS)
userver_venv_setup(
NAME
userver-chaotic-tests
PYTHON_OUTPUT_VAR
USERVER_CHAOTIC_PYTEST_PYTHON_BINARY
REQUIREMENTS
"${USERVER_ROOT_DIR}/scripts/chaotic/requirements.txt"
"${USERVER_ROOT_DIR}/testsuite/requirements.txt"
NAME userver-chaotic-tests
PYTHON_OUTPUT_VAR USERVER_CHAOTIC_PYTEST_PYTHON_BINARY
REQUIREMENTS "${USERVER_ROOT_DIR}/scripts/chaotic/requirements.txt"
"${USERVER_ROOT_DIR}/testsuite/requirements.txt"
UNIQUE
)
add_test(NAME chaotic-tests-pytest
Expand All @@ -27,21 +26,20 @@ if(USERVER_BUILD_TESTS)
endif()

_userver_directory_install(
COMPONENT chaotic DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/chaotic" DESTINATION "${CMAKE_INSTALL_LIBDIR}/userver"
COMPONENT chaotic
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/chaotic"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/userver"
)
_userver_directory_install(
COMPONENT chaotic PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/bin/chaotic-gen" DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
_userver_directory_install(
COMPONENT
chaotic
FILES
"${USERVER_ROOT_DIR}/cmake/ChaoticGen.cmake"
"${USERVER_ROOT_DIR}/cmake/install/userver-chaotic-config.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/userver"
COMPONENT chaotic
FILES "${USERVER_ROOT_DIR}/cmake/ChaoticGen.cmake" "${USERVER_ROOT_DIR}/cmake/install/userver-chaotic-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
)
_userver_directory_install(
COMPONENT chaotic DIRECTORY "${USERVER_ROOT_DIR}/scripts/chaotic" DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/userver"
COMPONENT chaotic
DIRECTORY "${USERVER_ROOT_DIR}/scripts/chaotic"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
)
23 changes: 10 additions & 13 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@ endif()

userver_module(
clickhouse
SOURCE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES_PRIVATE
clickhouse-cpp-lib::clickhouse-cpp-lib
UTEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES_PRIVATE clickhouse-cpp-lib::clickhouse-cpp-lib
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
DBTEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*_chtest.cpp"
# HACK: common source between unittest and dbtest targets.
"${CMAKE_CURRENT_SOURCE_DIR}/src/storages/tests/utils_test.cpp"
DBTEST_DATABASES
clickhouse
"${CMAKE_CURRENT_SOURCE_DIR}/src/*_chtest.cpp"
# HACK: common source between unittest and dbtest targets.
"${CMAKE_CURRENT_SOURCE_DIR}/src/storages/tests/utils_test.cpp"
DBTEST_DATABASES clickhouse
)

target_compile_options(${PROJECT_NAME} PUBLIC "-Wno-error=pedantic")

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

if(USERVER_BUILD_TESTS)
Expand Down
60 changes: 28 additions & 32 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ else()
${PROJECT_NAME} SYSTEM PUBLIC $<BUILD_INTERFACE:${USERVER_THIRD_PARTY_DIRS}/moodycamel/include>
)
_userver_directory_install(
COMPONENT core DIRECTORY ${USERVER_THIRD_PARTY_DIRS}/moodycamel/include/moodycamel DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/userver/third_party
COMPONENT core
DIRECTORY ${USERVER_THIRD_PARTY_DIRS}/moodycamel/include/moodycamel
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/userver/third_party
)
endif()

Expand All @@ -164,11 +165,14 @@ target_include_directories(
$<BUILD_INTERFACE:${USERVER_THIRD_PARTY_DIRS}/pfr/include>
)
_userver_directory_install(
COMPONENT core DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
COMPONENT core
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
)
_userver_directory_install(
COMPONENT core DIRECTORY ${USERVER_THIRD_PARTY_DIRS}/pfr/include/boost DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/userver/third_party
COMPONENT core
DIRECTORY ${USERVER_THIRD_PARTY_DIRS}/pfr/include/boost
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/userver/third_party
)

target_include_directories(
Expand Down Expand Up @@ -201,13 +205,9 @@ if(USERVER_FEATURE_UTEST)
)
target_link_libraries(userver-core-internal PUBLIC ${PROJECT_NAME})
_userver_directory_install(
COMPONENT
core
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/internal/include
${CMAKE_CURRENT_SOURCE_DIR}/../universal/internal/include
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/..
COMPONENT core
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/internal/include ${CMAKE_CURRENT_SOURCE_DIR}/../universal/internal/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
)
_userver_install_targets(COMPONENT core TARGETS userver-core-internal)
endif()
Expand Down Expand Up @@ -250,37 +250,33 @@ endif()

_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
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/Findlibnghttp2.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibev.cmake"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
COMPONENT core
FILES "${USERVER_ROOT_DIR}/cmake/modules/Findc-ares.cmake" "${USERVER_ROOT_DIR}/cmake/modules/Findlibnghttp2.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibev.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)

file(GLOB_RECURSE TESTSUITE_INSTALL_FILES "${USERVER_ROOT_DIR}/testsuite/*.txt" "${USERVER_ROOT_DIR}/testsuite/*.py")

_userver_directory_install(
COMPONENT core FILES ${TESTSUITE_INSTALL_FILES} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/testsuite
COMPONENT core
FILES ${TESTSUITE_INSTALL_FILES}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/testsuite
)

_userver_directory_install(
COMPONENT core PROGRAMS "${USERVER_ROOT_DIR}/testsuite/env.in" DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/userver/testsuite
COMPONENT core PROGRAMS "${USERVER_ROOT_DIR}/testsuite/env.in"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/testsuite
)

_userver_directory_install(
COMPONENT core DIRECTORY "${USERVER_ROOT_DIR}/testsuite/pytest_plugins/" DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/userver/testsuite/pytest_plugins/
COMPONENT core
DIRECTORY "${USERVER_ROOT_DIR}/testsuite/pytest_plugins/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/testsuite/pytest_plugins/
)
4 changes: 3 additions & 1 deletion core/utest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ target_include_directories(
PRIVATE $<TARGET_PROPERTY:userver-core,INCLUDE_DIRECTORIES> ${CMAKE_CURRENT_SOURCE_DIR}/src
)
_userver_directory_install(
COMPONENT core DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
COMPONENT core
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
)
_userver_install_targets(COMPONENT core TARGETS userver-utest)

Expand Down
30 changes: 15 additions & 15 deletions grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ target_include_directories(
)

_userver_directory_install(
COMPONENT grpc DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
COMPONENT grpc
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
)
if(DEFINED api-common-proto_LIBRARY)
target_link_libraries(${PROJECT_NAME}-internal PUBLIC ${api-common-proto_LIBRARY})
Expand Down Expand Up @@ -130,7 +132,9 @@ if(USERVER_FEATURE_UTEST)
)
_userver_install_targets(COMPONENT grpc TARGETS ${PROJECT_NAME}-utest)
_userver_directory_install(
COMPONENT grpc DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utest/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
COMPONENT grpc
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utest/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
)
endif()

Expand Down Expand Up @@ -183,19 +187,15 @@ target_link_libraries(${PROJECT_NAME} INTERFACE ${PROJECT_NAME}-internal)
_userver_install_targets(COMPONENT grpc TARGETS ${PROJECT_NAME})

_userver_directory_install(
COMPONENT
grpc
FILES
"${USERVER_ROOT_DIR}/cmake/SetupProtobuf.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupGrpc.cmake"
"${USERVER_ROOT_DIR}/cmake/UserverGrpcTargets.cmake"
"${USERVER_ROOT_DIR}/cmake/install/userver-grpc-config.cmake"
DIRECTORY
"${USERVER_ROOT_DIR}/scripts/grpc"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/userver
COMPONENT grpc
FILES "${USERVER_ROOT_DIR}/cmake/SetupProtobuf.cmake" "${USERVER_ROOT_DIR}/cmake/SetupGrpc.cmake"
"${USERVER_ROOT_DIR}/cmake/UserverGrpcTargets.cmake"
"${USERVER_ROOT_DIR}/cmake/install/userver-grpc-config.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
COMPONENT grpc
FILES "${USERVER_ROOT_DIR}/cmake/modules/FindUserverGrpc.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)
4 changes: 3 additions & 1 deletion grpc/handlers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ if(USERVER_BUILD_TESTS)
endif()
_userver_install_targets(COMPONENT grpc TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-proto)
_userver_directory_install(
COMPONENT grpc DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
COMPONENT grpc
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/..
)
Loading

0 comments on commit ad4c606

Please sign in to comment.