小编roa*_*ter的帖子

CMake嵌套项目和目标

我在从CMake源代码树构建特定的Visual Studio项目时遇到问题。想象一下,我们在各个子目录中都有多个目标。在一个子目录中,我们启动一个新项目(和解决方案)。此项目目标中的项目应属于ALL_BUILD,但不能位于父ALL_BUILD中。

简而言之:

project(Main)

add_executable(MainApplication ...)
target_link_libraries(MainApplication PRIVATE Library_A)

add_subdirectory(Library_A)
   add_library(Library_A STATIC ...)

add_subdirectory(Other_Related_Stuff_Using_MainApplication)
   project(OtherRelatedStuff)
   add_custom_target(OtherTarget ... DEPENDS MainApplication)
Run Code Online (Sandbox Code Playgroud)

现在,使用Visual Studio生成器,我们将获得两个解决方案文件。那是正确的。在这两个解决方案中,我们都有这三个项目(因为OtherReleatedStuff取决于所构建的MainApplication beeing,而OtherRelatedStuff是Main-Project的一部分)。

现在:ALL_BUILD生成所有项目。

当我设定

set_target_properties(OtherTarget PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
Run Code Online (Sandbox Code Playgroud)

...在两种解决方案中,OtherTarget均已禁用

我想做的是:

解决方案1: 在Main.Sln中不应存在 OtherTarget。在 OtherRelatedStuff.sln中可能有MainApplication,但不应构建。也许也不应该有MainApplication。

解决方案2: 在Main.Sln中,永远不要构建OtherTarget(从构建中排除)。在OtherRelatedStuff.sln中,应该构建OtherTarget,但是依赖项不可见甚至不可见。

有解决方案吗?

c++ cmake visual-studio visual-studio-2012

5
推荐指数
1
解决办法
4839
查看次数

std :: string是一个对象吗?

只是想优化一些std::map代码.地图包含通过字符串标识符访问的对象.

例:

std::map<std::string, CVeryImportantObject> theMap;

...

theMap["second"] = new CVeryImportantObject();
Run Code Online (Sandbox Code Playgroud)

现在,当使用find-function as时theMap->find("second"),会转换为String std::string("second"),这会导致新的字符串分配(在使用IDL = 2时使用Visual Studio).

1.是否有可能使用仅字符串类来避免此类分配?

我故意试图使用另一个String-Class:

std::map<CString, CVeryImportantObject> theMap;
Run Code Online (Sandbox Code Playgroud)

这段代码也有效.但CString 确实是一个对象.

并且:如果你从地图中删除一个对象,我需要释放相关的对象和密钥,是吗?

有什么建议?

c++ string stdmap

1
推荐指数
1
解决办法
184
查看次数

标签 统计

c++ ×2

cmake ×1

stdmap ×1

string ×1

visual-studio ×1

visual-studio-2012 ×1