Skip to content

Commit

Permalink
CMake: Split qt_repo_build() into reusable macros
Browse files Browse the repository at this point in the history
Sometimes projects don't follow the standard directory layout, so they
end up copy-pasting the guts of qt_build_repo and adapting that.

Split the macro into smaller ones so it's easier to reuse.

Change-Id: I8cc72ba2a2eaf58afd44950b3ac78378b7b1fdfd
Reviewed-by: Joerg Bornemann <[email protected]>
  • Loading branch information
alcroito committed May 10, 2021
1 parent e830a8c commit 326c7ec
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -432,32 +432,51 @@ endmacro()
macro(qt_build_repo)
qt_build_repo_begin(${ARGN})

qt_build_repo_impl_find_package_tests()
qt_build_repo_impl_src()
qt_build_repo_impl_tools()
qt_build_repo_impl_tests()

qt_build_repo_end()

qt_build_repo_impl_examples()
endmacro()

macro(qt_build_repo_impl_find_package_tests)
# If testing is enabled, try to find the qtbase Test package.
# Do this before adding src, because there might be test related conditions
# in source.
if (QT_BUILD_TESTS AND NOT QT_BUILD_STANDALONE_TESTS)
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Test)
endif()
endmacro()

macro(qt_build_repo_impl_src)
if(NOT QT_BUILD_STANDALONE_TESTS)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists.txt")
add_subdirectory(src)
endif()
endif()
endmacro()

macro(qt_build_repo_impl_tools)
if(NOT QT_BUILD_STANDALONE_TESTS)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tools/CMakeLists.txt")
add_subdirectory(tools)
endif()
endif()
endmacro()

macro(qt_build_repo_impl_tests)
if (QT_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt")
add_subdirectory(tests)
if(NOT QT_BUILD_TESTS_BY_DEFAULT)
set_property(DIRECTORY tests PROPERTY EXCLUDE_FROM_ALL TRUE)
endif()
endif()
endmacro()

qt_build_repo_end()

macro(qt_build_repo_impl_examples)
if(QT_BUILD_EXAMPLES AND BUILD_SHARED_LIBS
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt"
AND NOT QT_BUILD_STANDALONE_TESTS)
Expand Down

0 comments on commit 326c7ec

Please sign in to comment.