Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install(TARGETS ...) and add_subdirectory

Tags:

Is it possible to use install(TARGETS ...) with targets that are defined in directories added with add_subdirectory?

My use case is, that I want to build e.gg an rpm for gtest. the gtest project happens to have a CMakeLists.txt without any install statements. I want to build the package without adding those statements to the CMakeLists.txt of gtest.

I have this resulting directory structure:

+ gtest-1.5.0/... + CMakeLists.txt  

The CMakeLists of gtest-1.5.0 defines libraries like this:

cxx_static_library(gtest "${cxx_strict}" src/gtest-all.cc) cxx_static_library(gtest_main "${cxx_strict}" src/gtest_main.cc) target_link_libraries(gtest_main gtest) 

now i want to add something like this to my CMakeLists.txt:

add_subdirectory(gtest-1.5.0) install(TARGETS gtest gtest_main ARCHIVE DESTINATION lib) 

but cmake correctly states:

CMake Error at CMakeLists.txt:10 (install):   install TARGETS given target "gtest" which does not exist in this   directory. 

Is there a way to do this without patching gtest-1.5.0?

like image 508
Gizmomogwai Avatar asked Aug 23 '10 12:08

Gizmomogwai


People also ask

What does CMake Add_subdirectory do?

Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.

How do I install CMake files?

app into /Applications (or a custom location), run it and follow the “How to Install For Command Line Use” menu item for instructions to make the command-line tools (e.g. cmake) available in the PATH. Or, one may manually add the install directory (e.g. /Applications/CMake. app/Contents/bin) to the PATH.

What does CMake install mean?

CMake provides the install command to specify how a project is to be installed. This command is invoked by a project in the CMakeLists file and tells CMake how to generate installation scripts. The scripts are executed at install time to perform the actual installation of files.

How call CMake install?

Install Rules Now run the cmake executable or the cmake-gui to configure the project and then build it with your chosen build tool. Then run the install step by using the install option of the cmake command (introduced in 3.15, older versions of CMake must use make install ) from the command line.


1 Answers

You could try using file install rather than install targets. The downside is that you will have to handle shared and static builds.

install(FILES gtest-1.5.0/gtest_main.so DESTINATION lib)

like image 163
RobertJMaynard Avatar answered Sep 28 '22 06:09

RobertJMaynard