English 中文(简体)
CMake装置 (TARGETS in subdirectories)
原标题:CMake install (TARGETS in subdirectories)

审议以下<代码>CMakeLists.txt文档:

add_subdirectory(execA)
add_subdirectory(libB)

install(TARGETS execA libB
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

我有以下错误:

install TARGETS given target "execA" which does not exist in this
  directory

www.un.org/Depts/DGACM/index_spanish.htm 有自己的<代码>CMakeList.txt文档,并位于> 项目目录以及建筑名录Im 每天cmake/code>(cmake .):

project
  |------ CMakeList.txt (the one with the code)
  |----execA
  |      - .cpp, .hpp and CMakelist.txt
  |----libB
  |      - .cpp, .hpp and CMakelist.txt
  |---- lib
  |---- bin
  ---- build (where I´m commanding: $ cmake ..

我如何纠正这一错误?

最佳回答
问题回答

Even though it would help seeing the CMakeLists.txt files contained in the subdirectories, I guess they contain add_executable and/or add_library statements to create your stuff.
Also, because of your example, I guess you are using the same name of your directories for your targets.
That said, you should know that symbols defined in a CMakeLists.txt file in a subdirectory are not visible by default within the context of the CMakeLists.txt file in the parent directory. Because of that, you should rather move your install statements within the CMakeLists.txt files within your subdirectories.
This should solve the problem, if my thoughts were right. Otherwise, I strongly suggest you to post in your question also the content of the other files above mentioned.

Anyway, the error is quite clear.
The file that contains the install statement for the target named X does not contain a target creation statement (add_executable and the others) that gives birth to that target, so it goes on saying that that target does not exist in that directory.

这似乎仍然是CMake 3.11的痛苦点。

在我们的代码基中,我们有许多目标被分局界定,需要建立配置不同和(可能重叠)目标组合的安装器的配置。

我的解决办法是:

  • Before calling add_subdirectory in your root CMakeLists.txt file, create a GLOBAL property with the names of the target(s) you want to include in your installer.
  • Wrap target creation functions (add_executable, etc.) in your own custom functions. Within those functions check if the target is present in the global property, and invoke install accordingly.

这种做法使你能够集中配置安装装置。

此外,为了支持多台安装装置的建立,我们把我们的全球清单和其他安装物放在单独的剪辑档案中。 当我们援引<代码>cmake时,我们把安装装置组合CMake文档的名称当作一条指挥线。 我们的根源是CMakeList。 txt文档仅打电话include

我认为你可以这样做:


add_subdirectory(execA)
add_subdirectory(libB)

function(install_all_targets DIR)
    get_property(TGTS DIRECTORY "${DIR}" PROPERTY BUILDSYSTEM_TARGETS)
    foreach(TGT IN LISTS TGTS)
        message(STATUS "Target: ${TGT}")
        install(TARGETS ${TGT}
                RUNTIME DESTINATION bin
                LIBRARY DESTINATION lib
                ARCHIVE DESTINATION lib)
    endforeach()

    get_property(SUBDIRS DIRECTORY "${DIR}" PROPERTY SUBDIRECTORIES)
    foreach(SUBDIR IN LISTS SUBDIRS)
    install_all_targets("${SUBDIR}")
    endforeach()
endfunction()

install_all_targets(.)





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?