I use QtCreator to open CMake project. Some directories apart from CMakeLists.txt contains only headers files *.h and for those directories QtCreator in the project tree view shows only CMakeLists.txt. How to fix that ? I need to see all project files from QtCreator.
我使用QtCreator打开CMake项目。一些目录除了CMakeLists。txt只包含头文件*。在项目树视图中,对于那些目录QtCreator只显示CMakeLists.txt。如何解决这个问题?我需要从QtCreator看到所有的项目文件。
5 个解决方案
#1
23
Viewing project as a file system is not a solution at all cause your project editor settings for example would not apply. And I do not like to add headers to executable target, cause they do not actually belong there. You effectively cripple the project file to work nicely with one particular IDE... not good. The cleaner option IMHO would be:
查看项目作为一个文件系统不是一个解决方案,因为您的项目编辑器设置不适用。而且我不喜欢向可执行目标添加标题,因为它们实际上不属于那里。您有效地削弱了项目文件,以便与一个特定的IDE完美地工作……不好的。更清洁的选择是:
FILE(GLOB_RECURSE LibFiles "include/*.hpp")
add_custom_target(headers SOURCES ${LibFiles})
As a bonus you get your includes shown in a separate folder. (borrowed from https://cmake.org/pipermail/cmake/2012-August/051811.html)
作为奖励,你可以在一个单独的文件夹中显示你的内容。从https://cmake.org/pipermail/cmake/2012-August/051811.html(借)
#2
9
I would suggest you switching your project view to File System. This would display a view where you could view any file you want:
我建议您将项目视图切换到文件系统。这将显示一个视图,您可以查看您想要的任何文件:
You might want to split your project view into two by clicking the second to right button, if you still desire the Projects mode.
如果您仍然希望项目模式,您可能希望通过单击第二个按钮来将项目视图拆分为两个。
#3
7
You should add header files to the list of your source files: add_executable(${Executable} ${Sources} ${headers})
您应该将头文件添加到源文件的列表中:add_executable(${可执行${Sources} ${header})
You can use GLOB_RECURSE
if have many header files:
如果有许多头文件,可以使用GLOB_RECURSE:
FILE(GLOB_RECURSE INC_ALL "headers/*.h")
include_directories("headers")
add_executable(main "main.cpp" ${INC_ALL})
Don't forget to run CMake again (Build>Run Cmake).
不要忘记再次运行CMake(构建>运行CMake)。
#4
2
Based on another thread asking the same question, I found a generic solution to the problem, working for all IDE's (at least tested with QtCreator and Visual Studio).
基于另一个问题,我找到了一个通用的解决方案,为所有IDE工作(至少测试了QtCreator和Visual Studio)。
Can be found here : https://github.com/sauter-hq/cmake-ide-support
可以在这里找到:https://github.com/sauter- hq/c- support ?
# \brief adds for the given target a fake executable targets which allows all
# headers and symbols to be shown in IDEs.
# \param target_name Which target properties should be added to the IDE support target.
function(target_add_ide_support target_name)
if (NOT TARGET ${target_name})
message(FATAL_ERROR "No target defined with name ${target_name}, cannot target_add_ide_support it.")
endif()
set (target_for_ide "${target_name}_ide_support")
if (NOT TARGET ${target_for_ide})
file(GLOB_RECURSE target_for_ide_srcs "*.h" "*.hpp" "*.hxx" "*.c" "*.cpp" "*.cxx")
add_executable(${target_for_ide} ${target_for_ide_srcs})
set_target_properties(${target_for_ide} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
get_target_property(dirs ${target_name} INCLUDE_DIRECTORIES)
target_include_directories(${target_for_ide} PRIVATE ${dirs})
endfunction(target_add_ide_support)
Usage is then for any targets in the CMakeLists, add the following call (can be made in top-most CMakeLists.txt after all add_subdirectory :
然后在CMakeLists中使用任何目标,添加以下调用(可以在*的CMakeLists中进行)。txt后面的所有add_subdirectory:
include(add_ide_support.cmake)
target_add_ide_support(some-target)
#5
1
You can try CMakeProjectManager2. Code to display all files already propagated to upstream as a proof of concept. Concept applied but code can't be applied as-is for some reasons. So, simple wait feature in upstream.
你可以试试CMakeProjectManager2。代码显示已经传播到上游的所有文件作为概念的证明。概念应用,但代码不能按原样应用,这是有原因的。因此,在上游进行简单的等待功能。
#1
23
Viewing project as a file system is not a solution at all cause your project editor settings for example would not apply. And I do not like to add headers to executable target, cause they do not actually belong there. You effectively cripple the project file to work nicely with one particular IDE... not good. The cleaner option IMHO would be:
查看项目作为一个文件系统不是一个解决方案,因为您的项目编辑器设置不适用。而且我不喜欢向可执行目标添加标题,因为它们实际上不属于那里。您有效地削弱了项目文件,以便与一个特定的IDE完美地工作……不好的。更清洁的选择是:
FILE(GLOB_RECURSE LibFiles "include/*.hpp")
add_custom_target(headers SOURCES ${LibFiles})
As a bonus you get your includes shown in a separate folder. (borrowed from https://cmake.org/pipermail/cmake/2012-August/051811.html)
作为奖励,你可以在一个单独的文件夹中显示你的内容。从https://cmake.org/pipermail/cmake/2012-August/051811.html(借)
#2
9
I would suggest you switching your project view to File System. This would display a view where you could view any file you want:
我建议您将项目视图切换到文件系统。这将显示一个视图,您可以查看您想要的任何文件:
You might want to split your project view into two by clicking the second to right button, if you still desire the Projects mode.
如果您仍然希望项目模式,您可能希望通过单击第二个按钮来将项目视图拆分为两个。
#3
7
You should add header files to the list of your source files: add_executable(${Executable} ${Sources} ${headers})
您应该将头文件添加到源文件的列表中:add_executable(${可执行${Sources} ${header})
You can use GLOB_RECURSE
if have many header files:
如果有许多头文件,可以使用GLOB_RECURSE:
FILE(GLOB_RECURSE INC_ALL "headers/*.h")
include_directories("headers")
add_executable(main "main.cpp" ${INC_ALL})
Don't forget to run CMake again (Build>Run Cmake).
不要忘记再次运行CMake(构建>运行CMake)。
#4
2
Based on another thread asking the same question, I found a generic solution to the problem, working for all IDE's (at least tested with QtCreator and Visual Studio).
基于另一个问题,我找到了一个通用的解决方案,为所有IDE工作(至少测试了QtCreator和Visual Studio)。
Can be found here : https://github.com/sauter-hq/cmake-ide-support
可以在这里找到:https://github.com/sauter- hq/c- support ?
# \brief adds for the given target a fake executable targets which allows all
# headers and symbols to be shown in IDEs.
# \param target_name Which target properties should be added to the IDE support target.
function(target_add_ide_support target_name)
if (NOT TARGET ${target_name})
message(FATAL_ERROR "No target defined with name ${target_name}, cannot target_add_ide_support it.")
endif()
set (target_for_ide "${target_name}_ide_support")
if (NOT TARGET ${target_for_ide})
file(GLOB_RECURSE target_for_ide_srcs "*.h" "*.hpp" "*.hxx" "*.c" "*.cpp" "*.cxx")
add_executable(${target_for_ide} ${target_for_ide_srcs})
set_target_properties(${target_for_ide} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
get_target_property(dirs ${target_name} INCLUDE_DIRECTORIES)
target_include_directories(${target_for_ide} PRIVATE ${dirs})
endfunction(target_add_ide_support)
Usage is then for any targets in the CMakeLists, add the following call (can be made in top-most CMakeLists.txt after all add_subdirectory :
然后在CMakeLists中使用任何目标,添加以下调用(可以在*的CMakeLists中进行)。txt后面的所有add_subdirectory:
include(add_ide_support.cmake)
target_add_ide_support(some-target)
#5
1
You can try CMakeProjectManager2. Code to display all files already propagated to upstream as a proof of concept. Concept applied but code can't be applied as-is for some reasons. So, simple wait feature in upstream.
你可以试试CMakeProjectManager2。代码显示已经传播到上游的所有文件作为概念的证明。概念应用,但代码不能按原样应用,这是有原因的。因此,在上游进行简单的等待功能。