cmake set_target_properties
时间: 2023-04-30 12:04:58 浏览: 85
cmake set_target_properties是CMake命令之一,用于设置目标的属性,例如编译选项、链接选项、操作系统特定的共享库属性等等。该命令可以用于指定生成的二进制文件的输出文件名、库的类型、库的版本等等。通过set_target_properties命令,可以使CMake更加灵活和可定制化。
相关问题
解释根据给出的代码,可以将其转化为以下CMake代码: 复制 cmake_minimum_required(VERSION 3.5) project(UavRectifyLoadLIb LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) find_package(Qt5Core REQUIRED) add_executable(UavRectifyLoadLIb main.cpp ) target_link_libraries(UavRectifyLoadLIb PRIVATE Qt5::Core UAVAutoRectifyMt UAVAutoRectify UAVAutoRectifyFi DEMDriver Projection IImage_gC opencv_core opencv_highgui opencv_imgproc opencv_features2d opencv_imgcodecs ) target_include_directories(UavRectifyLoadLIb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/gdal1101 ${CMAKE_CURRENT_SOURCE_DIR}/../include ${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/opencvf249 ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../usr/local/include ) if(UNIX AND NOT APPLE) target_link_directories(UavRectifyLoadLIb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32 ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../usr/local/lib ) endif() if(WIN32) if(CMAKE_BUILD_TYPE STREQUAL "Debug") set_target_properties(UavRectifyLoadLIb PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../../../../RasterManager/bin/Debug ) else() set_target_properties(UavRectifyLoadLIb PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../RasterManager/bin/release ) endif() else() if(CMAKE_BUILD_TYPE STREQUAL "Debug") set_target_properties(UavRectifyLoadLIb PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32 ) else() set_target_properties(UavRectifyLoadLIb PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32 ) endif() endif()
以下是将给出的代码转化为CMake代码的步骤:
1. 首先,在CMakeLists.txt文件中添加以下内容:
```
cmake_minimum_required(VERSION 3.5)
project(UavRectifyLoadLIb LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
```
这些命令设置了编译器版本、项目名称、C++标准、自动生成MOC文件、自动生成RCC文件和自动生成UI文件。
2. 接下来,添加以下代码以查找Qt5Core库:
```
find_package(Qt5Core REQUIRED)
```
这个命令告诉CMake查找Qt5Core库,并确保它被正确安装。
3. 然后,添加以下代码以创建可执行文件:
```
add_executable(UavRectifyLoadLIb
main.cpp
)
```
这个命令告诉CMake创建一个名为UavRectifyLoadLIb的可执行文件,并将main.cpp文件添加到该文件中。
4. 接下来,添加以下代码以链接所有必要的库:
```
target_link_libraries(UavRectifyLoadLIb
PRIVATE
Qt5::Core
UAVAutoRectifyMt
UAVAutoRectify
UAVAutoRectifyFi
DEMDriver
Projection
IImage_gC
opencv_core
opencv_highgui
opencv_imgproc
opencv_features2d
opencv_imgcodecs
)
```
这个命令告诉CMake链接所有必要的库,并将它们添加到可执行文件中。
5. 最后,添加以下代码以设置包含目录和链接目录:
```
target_include_directories(UavRectifyLoadLIb
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/gdal1101
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/opencvf249
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../usr/local/include
)
if(UNIX AND NOT APPLE)
target_link_directories(UavRectifyLoadLIb
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../usr/local/lib
)
endif()
if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../../../../RasterManager/bin/Debug
)
else()
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../RasterManager/bin/release
)
endif()
else()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32
)
else()
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32
)
endif()
endif()
```
这个命令告诉CMake设置包含目录和链接目录,并根据不同的操作系统设置输出目录。
cmake中set_target_properties
`set_target_properties` 是 CMake 中的一个命令,用于设置目标(target)的属性。一个目标可以是一个可执行文件、一个库文件或者一个自定义命令。通过使用 `set_target_properties`,开发者可以控制这些目标的各种属性,如编译选项、链接库、版本号等。
通常,使用 `set_target_properties` 命令时,需要指定目标的名称以及要设置的属性和对应的值。其基本语法如下:
```cmake
set_target_properties(target1 [target2...] PROPERTIES prop1 value1 prop2 value2 ...)
```
其中 `target1`、`target2` 是你要设置属性的目标名称,`prop1`、`prop2` 是属性名称,`value1`、`value2` 是对应的值。
例如,如果你想要设置库文件的输出名称,可以这样做:
```cmake
set_target_properties(MyLibrary PROPERTIES OUTPUT_NAME "my_custom_name")
```
这会使得名为 `MyLibrary` 的库文件在构建时被命名为 "my_custom_name"。
阅读全文