Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

c++ - CMake install (TARGETS in subdirectories)

Consider the following CMakeLists.txt file:

add_subdirectory(execA)
add_subdirectory(libB)

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

I get the following error:

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

execA and libB have their own CMakeList.txt files and are located under project directory, as well as the build directory I'm running cmake (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 ..

How do I fix this error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to this bugreport, install(TARGETS) command flow accepts only targets created within the same directory.

So you need either move the add_library() call into the top-level directory, or split install(TARGETS) call into per-target ones, and move each of them into the corresponding subdirectory.

Since CMake 3.13 install(TARGETS) can work even with targets created in other directories.

install(TARGETS) can install targets that were created in other directories. When using such cross-directory install rules, running make install (or similar) from a subdirectory will not guarantee that targets from other directories are up-to-date.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...