diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QbsBuildConfig.cmake | 261 | ||||
-rw-r--r-- | cmake/QbsDocumentation.cmake | 301 |
2 files changed, 562 insertions, 0 deletions
diff --git a/cmake/QbsBuildConfig.cmake b/cmake/QbsBuildConfig.cmake new file mode 100644 index 000000000..e0a7d76d7 --- /dev/null +++ b/cmake/QbsBuildConfig.cmake @@ -0,0 +1,261 @@ +option(WITH_TESTS "Build Tests" ON) +option(WITH_UNIT_TESTS "Build Unit Tests" OFF) +option(INSTALL_PUBLIC_HEADERS "Whether to install public headers" ON) +option(QBS_ENABLE_RPATH "Whether to enable RPATH" ON) + +include(CMakeDependentOption) +cmake_dependent_option(QBS_QUICKJS_LEAK_CHECK "Whether to check for quickjs leaks at the end" ON "CMAKE_BUILD_TYPE STREQUAL Debug" OFF) + +set(QBS_APP_INSTALL_DIR "bin" CACHE STRING "Relative install location for Qbs binaries.") +# default paths +set(QBS_LIBDIR_NAME "lib") +if(WIN32) + set(_DEFAULT_LIB_INSTALL_DIR ${QBS_APP_INSTALL_DIR}) + set(_DEFAULT_LIBEXEC_INSTALL_DIR ${QBS_APP_INSTALL_DIR}) +else() + set(_DEFAULT_LIB_INSTALL_DIR ${QBS_LIBDIR_NAME}) + set(_DEFAULT_LIBEXEC_INSTALL_DIR "libexec/qbs") +endif() + +# path options +set(QBS_OUTPUT_PREFIX "" CACHE STRING "Qbs build output location relative to CMAKE_BINARY_DIR.") +set(QBS_LIB_INSTALL_DIR "${_DEFAULT_LIB_INSTALL_DIR}" CACHE STRING "Relative install location for Qbs libraries.") +set(QBS_DLL_INSTALL_DIR "${QBS_LIB_INSTALL_DIR}" CACHE STRING "Relative install location for Qbs DLLs.") +set(QBS_LIBEXEC_INSTALL_DIR "${_DEFAULT_LIBEXEC_INSTALL_DIR}" CACHE STRING "Relative install location for Qbs libexec.") +set(QBS_PLUGINS_INSTALL_BASE "${QBS_LIBDIR_NAME}" CACHE STRING "Relative install location for Qbs plugins.") +set(QBS_RESOURCES_INSTALL_BASE "." CACHE STRING "Relative install location for Qbs resources.") +set(QBS_HEADERS_INSTALL_DIR "include/qbs" CACHE STRING "Relative install location for Qbs headers.") +set(QBS_DOC_INSTALL_DIR "${QBS_RESOURCES_INSTALL_BASE}/share/doc/qbs" CACHE STRING "Relative install location for Qbs documentation.") +set(QBS_DOC_HTML_DIR_NAME "html" CACHE STRING "The name of the dir with HTML files, appended to QBS_DOC_INSTALL_DIR.") + +set(QBS_PLUGINS_INSTALL_DIR "${QBS_PLUGINS_INSTALL_BASE}/qbs/plugins") +set(QBS_RESOURCES_INSTALL_DIR "${QBS_RESOURCES_INSTALL_BASE}/share") + +# rpaths +file(RELATIVE_PATH QBS_RELATIVE_LIBEXEC_RPATH "/${QBS_LIBEXEC_INSTALL_DIR}" "/${QBS_LIB_INSTALL_DIR}") +file(RELATIVE_PATH QBS_RELATIVE_APP_RPATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_LIB_INSTALL_DIR}") +file(RELATIVE_PATH QBS_RELATIVE_PLUGINS_RPATH "/${QBS_PLUGINS_INSTALL_DIR}" "/${QBS_LIB_INSTALL_DIR}") + +if(WIN32 OR NOT QBS_ENABLE_RPATH) + set(QBS_MACOSX_RPATH OFF) + set(QBS_LIB_RPATH "") + set(QBS_LIBEXEC_RPATH "") + set(QBS_APP_RPATH "") + set(QBS_PLUGINS_RPATH "") +elseif(APPLE) + set(QBS_MACOSX_RPATH ON) + set(QBS_LIB_RPATH "@loader_path") + set(QBS_LIBEXEC_RPATH "@loader_path/${QBS_RELATIVE_LIBEXEC_RPATH}") + set(QBS_APP_RPATH "@loader_path/${QBS_RELATIVE_APP_RPATH}") + set(QBS_PLUGINS_RPATH "@loader_path/${QBS_RELATIVE_PLUGINS_RPATH}") +else() + set(QBS_MACOSX_RPATH OFF) + set(QBS_LIB_RPATH "\$ORIGIN") + set(QBS_LIBEXEC_RPATH "\$ORIGIN/${QBS_RELATIVE_LIBEXEC_RPATH}") + set(QBS_APP_RPATH "\$ORIGIN/${QBS_RELATIVE_APP_RPATH}") + set(QBS_PLUGINS_RPATH "\$ORIGIN/${QBS_RELATIVE_PLUGINS_RPATH}") +endif() + +function(get_update_path_command var) + if(WIN32) + get_target_property(_QTCORE_LIBRARY Qt${QT_VERSION_MAJOR}::Core IMPORTED_LOCATION_RELEASE) + if(NOT _QTCORE_LIBRARY) + get_target_property(_QTCORE_LIBRARY Qt${QT_VERSION_MAJOR}::Core IMPORTED_LOCATION_DEBUG) + endif() + get_filename_component(_QT_LIBRARY_PATH "${_QTCORE_LIBRARY}" DIRECTORY) + get_target_property(_QBS_LIBRARY_PATH qbscore LIBRARY_OUTPUT_DIRECTORY) + file(TO_NATIVE_PATH "${_QT_LIBRARY_PATH}\;${_QBS_LIBRARY_PATH}\;$ENV{PATH}" _NEW_PATH) + set(${var} "PATH=${_NEW_PATH}" PARENT_SCOPE) + else() + set(${var} "") + endif() +endfunction() + +if(WITH_UNIT_TESTS) + set(QBS_UNIT_TESTS_DEFINES "QBS_ENABLE_UNIT_TESTS") +else() + set(QBS_UNIT_TESTS_DEFINES "") +endif() + +file(RELATIVE_PATH QBS_RELATIVE_LIBEXEC_PATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_LIBEXEC_INSTALL_DIR}") +file(RELATIVE_PATH QBS_RELATIVE_SEARCH_PATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_RESOURCES_INSTALL_BASE}") +file(RELATIVE_PATH QBS_RELATIVE_PLUGINS_PATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_PLUGINS_INSTALL_BASE}") + +set(DEFAULT_DEFINES "") +if(WIN32) + list(APPEND DEFAULT_DEFINES UNICODE _UNICODE _SCL_SECURE_NO_WARNINGS) +endif() +if(WITH_TESTS) + list(APPEND DEFAULT_DEFINES QBS_WITH_TESTS) +endif() + +# CMake 3.10 doesn't have list(TRANSFORM) +function(list_transform_prepend var prefix) + set(temp "") + foreach(f ${${var}}) + list(APPEND temp "${prefix}${f}") + endforeach() + set(${var} "${temp}" PARENT_SCOPE) +endfunction() + +function(add_qbs_app target_name) + cmake_parse_arguments(_arg + "" + "DESTINATION" + "DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;" + ${ARGN} + ) + + if (${_arg_UNPARSED_ARGUMENTS}) + message(FATAL_ERROR "add_qbs_app had unparsed arguments") + endif() + + set(_DESTINATION "${QBS_APP_INSTALL_DIR}") + if(_arg_DESTINATION) + set(_DESTINATION "${_arg_DESTINATION}") + endif() + + add_executable(${target_name} ${_arg_SOURCES}) + target_compile_definitions( + ${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES}) + target_include_directories( + ${target_name} PRIVATE ${_arg_INCLUDES} PUBLIC ${_arg_PUBLIC_INCLUDES}) + target_link_libraries(${target_name} PRIVATE ${_arg_DEPENDS} PUBLIC ${_arg_PUBLIC_DEPENDS}) + + set_target_properties(${target_name} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${_DESTINATION} + BUILD_RPATH "${QBS_APP_RPATH}" + INSTALL_RPATH "${QBS_APP_RPATH}" + MACOSX_RPATH ${QBS_MACOSX_RPATH} + ) + install(TARGETS ${target_name} RUNTIME DESTINATION ${_DESTINATION}) +endfunction() + +function(add_qbs_library target_name) + cmake_parse_arguments(_arg + "STATIC" + "" + "DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;" + ${ARGN} + ) + + if (${_arg_UNPARSED_ARGUMENTS}) + message(FATAL_ERROR "add_qbs_library had unparsed arguments") + endif() + + set(library_type SHARED) + if (_arg_STATIC) + set(library_type STATIC) + endif() + + string(REGEX REPLACE "\\.[0-9]+$" "" _SOVERSION ${QBS_VERSION}) + + add_library(${target_name} ${library_type} ${_arg_SOURCES}) + target_compile_definitions( + ${target_name} + PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} + PUBLIC ${_arg_PUBLIC_DEFINES}) + target_include_directories( + ${target_name} + PRIVATE ${_arg_INCLUDES} + PUBLIC ${_arg_PUBLIC_INCLUDES} + INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>) + target_link_libraries(${target_name} PRIVATE ${_arg_DEPENDS} PUBLIC ${_arg_PUBLIC_DEPENDS}) + + set_target_properties(${target_name} PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_LIB_INSTALL_DIR} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_LIB_INSTALL_DIR} + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_DLL_INSTALL_DIR} + BUILD_RPATH "${QBS_LIB_RPATH}" + INSTALL_RPATH "${QBS_LIB_RPATH}" + MACOSX_RPATH ${QBS_MACOSX_RPATH} + SOVERSION ${_SOVERSION} + VERSION ${QBS_VERSION} + ) + if (NOT _arg_STATIC) + install(TARGETS ${target_name} + LIBRARY DESTINATION ${QBS_LIB_INSTALL_DIR} + RUNTIME DESTINATION ${QBS_DLL_INSTALL_DIR} + ) + endif() + if(MSVC) + target_compile_options(${target_name} PUBLIC /EHsc) + endif() +endfunction() + +function(add_qbs_plugin target_name) + cmake_parse_arguments(_arg + "" + "" + "DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;" + ${ARGN} + ) + + if (${_arg_UNPARSED_ARGUMENTS}) + message(FATAL_ERROR "add_qbs_plugin had unparsed arguments") + endif() + + add_library(${target_name} SHARED ${_arg_SOURCES}) + target_compile_definitions( + ${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES}) + target_include_directories( + ${target_name} PRIVATE ${_arg_INCLUDES} PUBLIC ${_arg_PUBLIC_INCLUDES}) + target_link_libraries(${target_name} PRIVATE ${_arg_DEPENDS} PUBLIC ${_arg_PUBLIC_DEPENDS}) + + set_target_properties(${target_name} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_PLUGINS_INSTALL_DIR} + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_PLUGINS_INSTALL_DIR} + BUILD_RPATH "${QBS_PLUGINS_RPATH}" + INSTALL_RPATH "${QBS_PLUGINS_RPATH}" + MACOSX_RPATH ${QBS_MACOSX_RPATH} + ) + install(TARGETS ${target_name} + LIBRARY DESTINATION ${QBS_PLUGINS_INSTALL_DIR} + RUNTIME DESTINATION ${QBS_PLUGINS_INSTALL_DIR} + ) +endfunction() + +function(add_qbs_test test_name) + cmake_parse_arguments(_arg + "" + "" + "DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;" + ${ARGN} + ) + + if (${_arg_UNPARSED_ARGUMENTS}) + message(FATAL_ERROR "add_qbs_test had unparsed arguments") + endif() + + set(target_name "tst_${test_name}") + + string(TOUPPER ${test_name} suite_name) # cmake is beatiful, here we have <input, output> + string(REPLACE - _ suite_name ${suite_name}) # and here we have <output, input> + + add_executable(${target_name} ${_arg_SOURCES}) + target_compile_definitions(${target_name} PRIVATE + "QBS_TEST_SUITE_NAME=\"${suite_name}\"" + "SRCDIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" + ) + target_compile_definitions( + ${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES}) + target_include_directories( + ${target_name} + PRIVATE ${_arg_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}/../../../src" + PUBLIC ${_arg_PUBLIC_INCLUDES} + ) + target_link_libraries( + ${target_name} + PRIVATE ${_arg_DEPENDS} qbscore qbsconsolelogger Qt${QT_VERSION_MAJOR}::Test + PUBLIC ${_arg_PUBLIC_DEPENDS} + ) + + set_target_properties(${target_name} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_APP_INSTALL_DIR} + BUILD_RPATH "${QBS_APP_RPATH}" + INSTALL_RPATH "${QBS_APP_RPATH}" + MACOSX_RPATH ${QBS_MACOSX_RPATH} + ) + install(TARGETS ${target_name} RUNTIME DESTINATION ${QBS_APP_INSTALL_DIR}) + add_test(NAME ${target_name} COMMAND ${target_name}) +endfunction() diff --git a/cmake/QbsDocumentation.cmake b/cmake/QbsDocumentation.cmake new file mode 100644 index 000000000..bdcec664f --- /dev/null +++ b/cmake/QbsDocumentation.cmake @@ -0,0 +1,301 @@ +# Options: +option(QBS_INSTALL_HTML_DOCS "Whether to install Qbs HTML Documentation" OFF) +option(QBS_INSTALL_QCH_DOCS "Whether to install Qbs QCH Documentation" OFF) +option(QBS_INSTALL_MAN_PAGE "Whether to install Qbs man page" OFF) + +# Get information on directories from qmake +# as this is not yet exported by cmake. +# Used for QT_INSTALL_DOCS +function(qt_query_qmake) + if (NOT TARGET Qt${QT_VERSION_MAJOR}::qmake) + message(FATAL_ERROR "Qmake was not found. Add find_package(Qt5 COMPONENTS Core) to CMake to enable.") + endif() + # dummy check for if we already queried qmake + if (QT_INSTALL_BINS) + return() + endif() + + get_target_property(_qmake_binary Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION) + execute_process(COMMAND "${_qmake_binary}" "-query" + TIMEOUT 10 + RESULT_VARIABLE _qmake_result + OUTPUT_VARIABLE _qmake_stdout + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (NOT "${_qmake_result}" STREQUAL "0") + message(FATAL_ERROR "Qmake did not execute successfully: ${_qmake_result}.") + endif() + + # split into lines: + string(REPLACE "\n" ";" _lines "${_qmake_stdout}") + + foreach(_line ${_lines}) + # split line into key/value pairs + string(REPLACE ":" ";" _parts "${_line}") + list(GET _parts 0 _key) + list(REMOVE_AT _parts 0) + string(REPLACE ";" ":" _value "${_parts}") + + set("${_key}" "${_value}" CACHE PATH "qmake import of ${_key}" FORCE) + endforeach() +endfunction() + +function(_qbs_setup_doc_targets) + # Set up important targets: + if (NOT TARGET qbs_html_docs) + add_custom_target(qbs_html_docs COMMENT "Build HTML documentation") + endif() + if (NOT TARGET qbs_qch_docs) + add_custom_target(qbs_qch_docs COMMENT "Build QCH documentation") + endif() + if (NOT TARGET BuildQbsDocumentation) + add_custom_target( + BuildQbsDocumentation ALL COMMENT "Build Qbs documentation") + add_dependencies(BuildQbsDocumentation qbs_html_docs qbs_qch_docs) + endif() + if (NOT TARGET qbs_docs) + add_custom_target( + qbs_docs ALL COMMENT "Build Qbs documentation") + add_dependencies(qbs_docs BuildQbsDocumentation) + endif() +endfunction() + +function(_find_python_module module) + string(TOUPPER ${module} module_upper) + if (NOT PY_${module_upper}) + if (ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED") + set(${module}_FIND_REQUIRED TRUE) + endif() + # A module's location is usually a directory, but for binary modules + # it's a .so file. + execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" + "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))" + RESULT_VARIABLE _${module}_status + OUTPUT_VARIABLE _${module}_location + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT _${module}_status) + set(PY_${module_upper} ${_${module}_location} CACHE STRING + "Location of Python module ${module}") + endif() + endif() + find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper}) +endfunction() + +function(_qbs_setup_qdoc_targets _qdocconf_file _retval) + cmake_parse_arguments(_arg "" "HTML_DIR;INSTALL_DIR;POSTFIX" + "INDEXES;INCLUDE_DIRECTORIES;FRAMEWORK_PATHS;ENVIRONMENT_EXPORTS;SOURCES" ${ARGN}) + + foreach(_index ${_arg_INDEXES}) + list(APPEND _qdoc_index_args "-indexdir;${_index}") + endforeach() + + set(_env "") + foreach(_export ${_arg_ENVIRONMENT_EXPORTS}) + if (NOT DEFINED "${_export}") + message(FATAL_ERROR "${_export} is not known when trying to export it to qdoc.") + endif() + list(APPEND _env "${_export}=${${_export}}") + endforeach() + + get_target_property(_qdoc Qt${QT_VERSION_MAJOR}::qdoc IMPORTED_LOCATION) + + set(_full_qdoc_command "${_qdoc}") + if (_env) + set(_full_qdoc_command "${CMAKE_COMMAND}" "-E" "env" ${_env} "${_qdoc}") + endif() + + if (_arg_HTML_DIR STREQUAL "") + set(_arg_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc") + endif() + + get_filename_component(_target "${_qdocconf_file}" NAME_WE) + + set(_html_outputdir "${_arg_HTML_DIR}") + file(MAKE_DIRECTORY "${_html_outputdir}") + + set(_qdoc_include_args "") + if (_arg_INCLUDE_DIRECTORIES OR _arg_FRAMEWORK_PATHS) + # pass include directories to qdoc via hidden @ option, since we need to generate a file + # to be able to resolve the generators inside the include paths + set(_qdoc_includes "${CMAKE_CURRENT_BINARY_DIR}/cmake/qdoc_${_target}.inc") + set(_qdoc_include_args "@${_qdoc_includes}") + set(_includes "") + if (_arg_INCLUDE_DIRECTORIES) + set(_includes "-I$<JOIN:${_arg_INCLUDE_DIRECTORIES},\n-I>\n") + endif() + set(_frameworks "") + if (_arg_FRAMEWORK_PATHS) + set(_frameworks "-F$<JOIN:${_arg_FRAMEWORK_PATHS},\n-F>\n") + endif() + file(GENERATE + OUTPUT "${_qdoc_includes}" + CONTENT "${_includes}${_frameworks}" + ) + endif() + + set(_html_artifact "${_html_outputdir}/index.html") + add_custom_command( + OUTPUT "${_html_artifact}" + COMMAND cmake -E remove_directory "${_html_outputdir}" + COMMAND ${_full_qdoc_command} -outputdir "${_html_outputdir}" "${_qdocconf_file}" + ${_qdoc_index_args} ${_qdoc_include_args} + DEPENDS "${_qdocconf_file}" ${_arg_SOURCES} + COMMENT "Build HTML documentation from ${_qdocconf_file}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM + ) + + if (NOT Python3_Interpreter_FOUND) + message(WARNING "Cannot find python3 binary. Qbs documentation will not be built.") + return() + endif() + _find_python_module(lxml) + _find_python_module(bs4) + if (NOT PY_LXML OR NOT PY_BS4) + message(WARNING "Cannot import lxml and bs4 python modules. Qbs documentation will not be built.") + return() + endif() + + set(_fixed_html_artifact "${CMAKE_CURRENT_BINARY_DIR}/qbsdoc.dummy") + set(_fix_qml_imports_script ${Qbs_SOURCE_DIR}/doc/fix-qmlimports.py) + add_custom_command( + OUTPUT "${_fixed_html_artifact}" + COMMAND ${Python3_EXECUTABLE} "${_fix_qml_imports_script}" ${_html_outputdir} + COMMAND cmake -E touch ${_fixed_html_artifact} + DEPENDS "${_html_artifact}" "${_fix_qml_imports_script}" + COMMENT "Fixing bogus QML import statements" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM + ) + + set(_html_target "qbs_html_docs_${_target}") + add_custom_target(${_html_target} DEPENDS "${_fixed_html_artifact}") + add_dependencies(qbs_html_docs "${_html_target}") + + # artifacts might be required for QCH-only installation, so we build them + # always, and skip HTML docs installation here + if (QBS_INSTALL_HTML_DOCS) + install(DIRECTORY "${_html_outputdir}" DESTINATION "${_arg_INSTALL_DIR}" + COMPONENT qbs_docs) + endif() + + set("${_retval}" "${_html_outputdir}" PARENT_SCOPE) +endfunction() + +function(_qbs_setup_qhelpgenerator_targets _qdocconf_file _html_outputdir) + cmake_parse_arguments(_arg "" "QCH_DIR;INSTALL_DIR" "" ${ARGN}) + if (_arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "qdoc_build_qdocconf_file has unknown arguments: ${_arg_UNPARSED_ARGUMENTS}.") + endif() + + if (NOT _arg_QCH_DIR) + set(_arg_QCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc") + endif() + + if (NOT TARGET Qt${QT_VERSION_MAJOR}::qhelpgenerator) + message(WARNING "qhelpgenerator missing: No QCH documentation targets were generated. Add find_package(Qt5 COMPONENTS Help) to CMake to enable.") + return() + endif() + + get_filename_component(_target "${_qdocconf_file}" NAME_WE) + + set(_html_target "qbs_html_docs_${_target}") + if (NOT TARGET ${_html_target}) + return() + endif() + + set(_qch_outputdir "${_arg_QCH_DIR}") + file(MAKE_DIRECTORY "${_qch_outputdir}") + + set(_fixed_html_artifact "${CMAKE_CURRENT_BINARY_DIR}/qbsdoc.dummy") + set(_qhp_artifact "${_html_outputdir}/${_target}.qhp") + set(_qch_artifact "${_qch_outputdir}/${_target}.qch") + add_custom_command( + OUTPUT "${_qch_artifact}" + COMMAND Qt${QT_VERSION_MAJOR}::qhelpgenerator "${_qhp_artifact}" -o "${_qch_artifact}" + DEPENDS "${_fixed_html_artifact}" + COMMENT "Build QCH documentation from ${_qdocconf_file}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM + ) + + set(_qch_target "qbs_qch_docs_${_target}") + add_custom_target("${_qch_target}" DEPENDS "${_qch_artifact}") + add_dependencies(qbs_qch_docs "${_qch_target}") + + install(FILES "${_qch_outputdir}/${_target}.qch" DESTINATION "${_arg_INSTALL_DIR}" + COMPONENT qbs_docs) +endfunction() + +# Helper functions: +function(_qbs_qdoc_build_qdocconf_file _qdocconf_file) + _qbs_setup_doc_targets() + + if (NOT TARGET Qt${QT_VERSION_MAJOR}::qdoc) + message(WARNING "No qdoc binary found: No documentation targets were generated") + return() + endif() + + cmake_parse_arguments(_arg "QCH" "HTML_DIR;QCH_DIR;INSTALL_DIR;POSTFIX" + "INDEXES;INCLUDE_DIRECTORIES;FRAMEWORK_PATHS;ENVIRONMENT_EXPORTS;SOURCES" ${ARGN}) + if (_arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "qdoc_build_qdocconf_file has unknown arguments: ${_arg_UNPARSED_ARGUMENTS}.") + endif() + + if (NOT _arg_INSTALL_DIR) + message(FATAL_ERROR "No INSTALL_DIR set when calling qdoc_build_qdocconf_file") + endif() + + _qbs_setup_qdoc_targets("${_qdocconf_file}" _html_outputdir + HTML_DIR "${_arg_HTML_DIR}" INSTALL_DIR "${_arg_INSTALL_DIR}" + INDEXES ${_arg_INDEXES} ENVIRONMENT_EXPORTS ${_arg_ENVIRONMENT_EXPORTS} + POSTFIX "${_arg_POSTFIX}" + INCLUDE_DIRECTORIES ${_arg_INCLUDE_DIRECTORIES} + FRAMEWORK_PATHS ${_arg_FRAMEWORK_PATHS} + SOURCES ${_arg_SOURCES} + ) + + if (_arg_QCH) + _qbs_setup_qhelpgenerator_targets("${_qdocconf_file}" "${_html_outputdir}" + QCH_DIR "${_arg_QCH_DIR}" INSTALL_DIR "${_arg_INSTALL_DIR}") + endif() + +endfunction() + +function(add_qbs_documentation qdocconf_file) + cmake_parse_arguments(_arg "" "" + "INCLUDE_DIRECTORIES;FRAMEWORK_PATHS;SOURCES" ${ARGN}) + if (_arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "add_qbs_documentation has unknown arguments: ${_arg_UNPARSED_ARGUMENTS}.") + endif() + + ### Skip docs setup if that is not needed! + if (NOT QBS_INSTALL_HTML_DOCS AND NOT QBS_INSTALL_QCH_DOCS) + return() + endif() + + qt_query_qmake() + set(SRCDIR "${Qbs_SOURCE_DIR}/doc") + + set(_qch_params) + # if QBS_INSTALL_QCH_DOCS is No, qch generation will be skipped entirely + if (QBS_INSTALL_QCH_DOCS) + set(_qch_params QCH QCH_DIR "${CMAKE_CURRENT_BINARY_DIR}") + endif() + set(_qdoc_params HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/${QBS_DOC_HTML_DIR_NAME}") + list(APPEND _qdoc_params INSTALL_DIR "${QBS_DOC_INSTALL_DIR}") + + # Set up environment for qdoc: + string(REPLACE "." "" QBS_VERSION_TAG "${QBS_VERSION}") + + list(APPEND _qdoc_params ENVIRONMENT_EXPORTS + SRCDIR QBS_VERSION QBS_VERSION_TAG + QT_INSTALL_DOCS + ) + + _qbs_qdoc_build_qdocconf_file(${qdocconf_file} ${_qch_params} ${_qdoc_params} + INCLUDE_DIRECTORIES ${_arg_INCLUDE_DIRECTORIES} + FRAMEWORK_PATHS ${_arg_FRAMEWORK_PATHS} + SOURCES ${_arg_SOURCES} + ) +endfunction() |