简体   繁体   English

Visual Studio 中的 CMake 项目可以引用父文件夹中的源文件吗?

[英]Can a CMake project in Visual Studio reference source files in a parent folder?

I newbye with Visual Studio / CMake solution that I would like to use to compile on remote Linux OS from a Windows platform.我不熟悉 Visual Studio/CMake 解决方案,我想用它来从 Windows 平台在远程 Linux 操作系统上进行编译。

I have a complex source structure that use C++ file through different folders.我有一个复杂的源结构,它通过不同的文件夹使用 C++ 文件。

/trunk
/trunk/projects/cmake-project1/
/trunk/projects/cmake-project2/
/trunk/src1/
/trunk/src2/
/trunk/src.../
/trunk/external-libs/

My cmake projects are located at /trunk/projects/.我的 cmake 项目位于 /trunk/projects/。 The first project uses some files from src1 and src2 and external-libs, the second project uses different files from src1 and src2 and external-libs...第一个项目使用来自 src1 和 src2 以及外部库的一些文件,第二个项目使用来自 src1 和 src2 以及外部库的不同文件...

  • Is it possible to target files that are in a parent folder of the cmake project?是否可以定位 cmake 项目的父文件夹中的文件? It seems that source can only be on the cmake project folder/subfolder.似乎源只能在 cmake 项目文件夹/子文件夹中。 Please confirm!请确认!
  • If it is possible how such reference to can be done to these files in the CMakeLists.txt and how Visual Studio will synchronize these files on the linux remote folder?如果有可能如何对 CMakeLists.txt 中的这些文件进行这样的引用,以及 Visual Studio 将如何在 linux 远程文件夹上同步这些文件?
  • One pratical way to do this would be to specify the source root folder (/trunk) through the CMakeSettings.json which is created by Visual Studio.一种实用的方法是通过 Visual Studio 创建的 CMakeSettings.json 指定源根文件夹 (/trunk)。 Unfortunately this setting does not seems to exists.不幸的是,此设置似乎不存在。 Am I wrong?我错了吗? It would be very useful so the solution would operate as if it is located at /trunk and we can then operate through specific CMakeList dedicated to project1, project2.这将非常有用,因此该解决方案将像位于 /trunk 一样运行,然后我们可以通过专用于 project1、project2 的特定 CMakeList 进行操作。

Actually it seems that the only way to operate is to copy the required source from src1, src2 to the cmake-project1 and cmake-project2, which is not particularly convenient for the structure lisibility.实际上好像只能把需要的source从src1、src2拷贝到cmake-project1和cmake-project2中,这样对于结构的可读性来说不是特别方便。

But I may be completely wrong about the right approach for this kind of problem!但是对于此类问题的正确方法,我可能完全错了!

Thanks for your suggestion!谢谢你的建议!

Overriding CMAKE_SRC_DIR seems to work for me:覆盖CMAKE_SRC_DIR似乎对我CMAKE_SRC_DIR

cmake -D CMAKE_SRC_DIR=/path/to/trunk /path/to/trunk/projects/project1

Source file references are by default relative to the CMakeLists.txt;默认情况下,源文件引用相对于 CMakeLists.txt; if this sits within the tree defined by CMAKE_SRC_DIR it may just work with visual studio.如果它位于CMAKE_SRC_DIR定义的树中,它可能只适用于 Visual Studio。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM