Cmake生成的Eclipse项目——没有源代码。

时间:2021-05-05 22:48:49

I am attempting to use CMake to generate eclipse project files. Although I am able to build successfully, I am unable to browse or edit the source in eclipse. This is an out of tree build, where my build directory is at the same level as my source directory. I am using the following command to generate the eclipse files:

我正在尝试使用CMake来生成eclipse项目文件。虽然我能够成功构建,但是我不能在eclipse中浏览或编辑源代码。这是一个树外构建,其中我的构建目录与源目录处于同一级别。我正在使用以下命令生成eclipse文件:

cmake -G"Eclipse CDT4 - Unix Makefiles" -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT=/usr/local/lib -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE ../proc

cmake - g“Eclipse CDT4 - Unix makefile”- dboost_no_boost_boost_cmake =ON - dboost_root =/usr/local/lib - dcmake_eclipse_generate_source_project =TRUE ./proc

The source directory has many different modules, but the top level CMakeLists file is essentially a bunch of add_subdirectory commands adding each module. Is this incorrect?

源目录有许多不同的模块,但是顶层CMakeLists文件本质上是一堆添加每个模块的add_subdirectory命令。这是不正确的吗?

2 个解决方案

#1


2  

I create the eclipse project with the following command

我使用以下命令创建eclipse项目

cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_BUILD_TYPE=Debug $PROJECT_SRC_DIR
// $PROJECT_SRC_DIR is where my highest level CMakeLists.txt is

My CMakeLists.txt does basically look like this

我的CMakeLists。txt基本上是这样的

cmake_minimum_required (VERSION 3.5.0)
cmake_policy(VERSION 3.5.0)
project(myproject VERSION 0.0.0)
# definition, find packages, compiler settings
add_subdirectory(src) # where my code is
# src contains further subdirectories with CMakeLists.txt and subproject definition therein.

This creates an eclipse project with a virtual directory [Source Directory] which points to the directory where Eclipse shows the content of the highest level CMakeLists.txt file with a project(...) command. Furthermore it shows [Subprojects] and [Targets] where the sources are shown for cmake subprojects (the directory content from the level of CMakeLists.txt where the subproject is defined) or targets (the list of file which are combined to an executable with the add_executable() command.

这将创建一个带有虚拟目录[源目录]的eclipse项目,该目录指向eclipse显示*CMakeLists内容的目录。带有project(…)命令的txt文件。此外,它还显示了[子项目]和[目标],其中显示了cmake子项目的源(CMakeLists级别的目录内容)。定义子项目的txt)或目标(与add_execution()命令组合为可执行文件的文件列表)。

Do you have a project defined?

您是否定义了一个项目?

#2


0  

I've made the same experience, both for Eclipse and KDevelop. CMake prepares the configuration such that you can compile and debug from within those IDEs, but it doesn't actually add any information that would help the IDE to list source files for browsing them.

我对Eclipse和KDevelop都有相同的体验。CMake准备了这样的配置,这样您就可以从这些IDE中编译和调试,但是它实际上并没有添加任何有助于IDE列出用于浏览它们的源文件的信息。

#1


2  

I create the eclipse project with the following command

我使用以下命令创建eclipse项目

cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_BUILD_TYPE=Debug $PROJECT_SRC_DIR
// $PROJECT_SRC_DIR is where my highest level CMakeLists.txt is

My CMakeLists.txt does basically look like this

我的CMakeLists。txt基本上是这样的

cmake_minimum_required (VERSION 3.5.0)
cmake_policy(VERSION 3.5.0)
project(myproject VERSION 0.0.0)
# definition, find packages, compiler settings
add_subdirectory(src) # where my code is
# src contains further subdirectories with CMakeLists.txt and subproject definition therein.

This creates an eclipse project with a virtual directory [Source Directory] which points to the directory where Eclipse shows the content of the highest level CMakeLists.txt file with a project(...) command. Furthermore it shows [Subprojects] and [Targets] where the sources are shown for cmake subprojects (the directory content from the level of CMakeLists.txt where the subproject is defined) or targets (the list of file which are combined to an executable with the add_executable() command.

这将创建一个带有虚拟目录[源目录]的eclipse项目,该目录指向eclipse显示*CMakeLists内容的目录。带有project(…)命令的txt文件。此外,它还显示了[子项目]和[目标],其中显示了cmake子项目的源(CMakeLists级别的目录内容)。定义子项目的txt)或目标(与add_execution()命令组合为可执行文件的文件列表)。

Do you have a project defined?

您是否定义了一个项目?

#2


0  

I've made the same experience, both for Eclipse and KDevelop. CMake prepares the configuration such that you can compile and debug from within those IDEs, but it doesn't actually add any information that would help the IDE to list source files for browsing them.

我对Eclipse和KDevelop都有相同的体验。CMake准备了这样的配置,这样您就可以从这些IDE中编译和调试,但是它实际上并没有添加任何有助于IDE列出用于浏览它们的源文件的信息。