From 79679c0f42146b3c56dec497a71d406500a587a7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 24 Jun 2018 20:43:08 +0200 Subject: [PATCH] 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. --- cmake/modules/LibraryTarget.cmake | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmake/modules/LibraryTarget.cmake b/cmake/modules/LibraryTarget.cmake index 53c9f5b..9607f52 100644 --- a/cmake/modules/LibraryTarget.cmake +++ b/cmake/modules/LibraryTarget.cmake @@ -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 + $ + $ + ${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