CMake構建OpenCV,GDAL專案

2021-08-17 03:52:10 字數 1813 閱讀 9814

本文舉例的開源庫是opencv和gdal,其他塊源庫類似

使用本篇方法的前提是make install,即開源庫是install的。

當然,沒有install的也是可以用的,只需要在findpage前找到dir即可。

如找opencv:

set(opencv_dir /home/jie/third_party/opencv-3.4.0/build)

另外,findpage所返回的變數如opencv_libs有什麼可以去對應的findxx.cmake檔案中找。

opencv:

cmakelists:

# cmake needs this line

cmake_minimum_required(version 2.8)

# define project name

project(opencvtest)

# find opencv, you may need to set opencv_dir variable

# to the absolute path to the directory containing opencvconfig.cmake file

# via the command line or gui

find_package(opencv required)

# if the package has been found, several variables will

# be set, you can find the full list with descriptions

# in the opencvconfig.cmake file.

# print some message showing some of them

message(status "opencv library status:")

message(status " version: $")

message(status " libraries: $")

message(status " include path: $")

# add opencv headers location to your include paths

include_directories($)

# declare the executable target built from your sources

add_executable(main main.cpp)

target_link_libraries(main $)

gdal:

cmakelist:

# cmake needs this line

cmake_minimum_required(version 2.8)

# define project name

project(gdaltest)

find_package(gdal required)

message(status "gdal library status:")

message(status " version: $")

message(status " libraries: $")

message(status " include path: $")

include_directories($)

add_executable(main test.cpp)

target_link_libraries(main $)

CMAKE自動構建

cmake 入門實戰 cmake 手冊詳解 兩個自己寫的cmakelists.txt用到了常用的編譯功能 cmake 最低版本號要求 cmake minimum required version 2.8 指定c編譯器 set cmake c compiler arm none linux gnuea...

Cmake 構建程式

cmake 是乙個跨平台的自動化建構系統,它使用乙個名為 cmakelists.txt 的檔案來描述構建程式,可以產生標準的構建檔案,如 unix 的 makefile。cmakelists.txt 需要手工編寫,也可以通過編寫指令碼進行半自動的生成。cmake 提供了比 autoconfig 更簡...

cmake構建qt工程

如何選擇?using cmake to build qt projects 一文中說 儘管如此,如果簡單qt的工程都不知道怎麼用 cmake 構建,複雜的工程,就更不知道如何使用 cmake 了。還是從簡單的學起吧 include include qdebug int main int argc,c...