![cmake install executable cmake install executable](https://programmer.ink/images/think/7cb1c74a8b7930153911f6dd721175c2.jpg)
If Qt was configured with the -release switch an imported target with the configuration RELEASE will be created. That is, if Qt was configured with the -debug switch, an imported target with the configuration DEBUG will be created. Imported targets are created with the configurations Qt was configured with.
Cmake install executable full#
Most CMake APIs are aware of imported targets and can automatically use them instead of the full path.Įach module in Qt 5 has a library target with the naming convention Qt5:: which can be used for this purpose. Note however that it is rare to require the full location to the library in CMake code. Get_target_property(QtCore_location Qt5::Core LOCATION) The actual path to the library can be obtained using the LOCATION property:įind_package(Qt5 COMPONENTS Core REQUIRED) Imported target names should be preferred instead of using a variable like Qt5 _LIBRARIES in CMake commands such as target_link_libraries. Imported targets are created for each Qt module. For more on this feature see the CMake AUTOMOC documentation Imported targets The CMAKE_AUTOMOC setting runs moc automatically when required. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5. In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5Config.cmake file. Target_link_libraries(helloworld Qt5::Widgets)
![cmake install executable cmake install executable](https://i.stack.imgur.com/5iZKk.png)
Our root CMakeLists.txt file simply calls include with that file.Find_package(Qt5 COMPONENTS Widgets REQUIRED) When we invoke cmake, we pass the name of the installer configuration CMake file as a command-line argument. That approach allows you to centralize installer configuration.Īlso: To support creation of multiple installers, we populate our global list along with other installer properties in separate. Within those functions check if the target is present in the global property, and invoke install accordingly. Wrap target creation functions ( add_executable, etc.) in your own custom functions.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.In our codebase, we have many targets defined in subdirectories and need to create an assortment of installers with different configurations and (potentially overlapping) combinations of targets. This still seems to be a pain point in CMake 3.11. 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. Otherwise, I strongly suggest you to post in your question also the content of the other files above mentioned. This should solve the problem, if my thoughts were right. Because of that, you should rather move your install statements within the CMakeLists.txt files within your subdirectories.
![cmake install executable cmake install executable](https://discourse.cmake.org/uploads/default/original/2X/5/54c5c5b7f34eea2ec711ddc57773aa2d13e1b340.png)
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. 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.Įven 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.Īlso, because of your example, I guess you are using the same name of your directories for your targets. Install(TARGETS) can install targets that were created in other directories. Since CMake 3.13 install(TARGETS) can work even with targets created in other directories. 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. According to this bugreport, install(TARGETS) command flow accepts only targets created within the same directory.