Improve fake target for Qt Creator

This target is required so files for header-only libs
show up in Qt Creator. So far it was just a custom target.
However, this way include directories and build flags are
not correctly passed to the code model. So creating an
actual library now.
This commit is contained in:
Martchus 2018-06-24 20:43:08 +02:00
parent 27d5041e06
commit 79679c0f42
1 changed files with 17 additions and 1 deletions

View File

@ -230,7 +230,23 @@ endif()
# Qt Creator does not show INTERFACE_SOURCES in project tree, so create a custom target as workaround
if(META_HEADER_ONLY_LIB)
add_custom_target(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator EXCLUDE_FROM_ALL SOURCES ${HEADER_FILES})
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/headeronly.cpp" "// not belonging to a real target, only for header-only lib files showing up in Qt Creator")
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
EXCLUDE_FROM_ALL
"${CMAKE_CURRENT_BINARY_DIR}/headeronly.cpp" ${HEADER_FILES}
)
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
INTERFACE
$<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}>
${PUBLIC_SHARED_INCLUDE_DIRS}
)
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
INTERFACE "${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}" "${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}"
)
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
INTERFACE "${META_PUBLIC_SHARED_LIB_COMPILE_OPTIONS}" "${META_PRIVATE_SHARED_LIB_COMPILE_OPTIONS}"
)
endif()
# create the CMake package config file from template