CMake構建學習筆記10-OsgQt庫的構建

charlee44發表於2024-08-28

筆者使用的OsgQt庫是Github上openscenegraph倉庫中託管的專案(地址),該庫的功能是將Osg嵌入到Qt窗體中。不過該庫的使用總是有點問題,具體的介紹筆者在之前的兩篇博文中論述過:

OSG嵌入QT的簡明總結
OSG嵌入QT的簡明總結2

因此,這裡筆者還是將這個庫分成了兩個版本進行構建。構建topic/Qt4分支的關鍵程式碼如下所示:

#配置CMake      
cmake .. -G "$Generator" -A x64 `
    -DCMAKE_BUILD_TYPE=RelWithDebInfo `
    -DCMAKE_PREFIX_PATH="$InstallDir" `
    -DCMAKE_INSTALL_PREFIX="$InstallDir" `
    -DOPENTHREADS_LIBRARY_RELEASE="$InstallDir/lib/OpenThreads.lib" `
    -DOSG_LIBRARY_RELEASE="$InstallDir/lib/osg.lib" `
    -DOSGDB_LIBRARY_RELEASE="$InstallDir/lib/osgDB.lib" `
    -DOSGGA_LIBRARY_RELEASE="$InstallDir/lib/osgGA.lib" `
    -DOSGUTIL_LIBRARY_RELEASE="$InstallDir/lib/osgUtil.lib" `
    -DOSGTEXT_LIBRARY_RELEASE="$InstallDir/lib/osgText.lib" `
    -DOSGVIEWER_LIBRARY_RELEASE="$InstallDir/lib/osgViewer.lib" `
    -DOSGWIDGET_LIBRARY_RELEASE="$InstallDir/lib/osgWidget.lib" `
    -DCMAKE_RELWITHDEBINFO_POSTFIX=""

# 構建階段,指定構建型別
cmake --build . --config RelWithDebInfo -- /m:8

# 安裝階段,指定構建型別和安裝目標
#cmake --build . --config RelWithDebInfo --target install

# 自定義安裝
# 複製include資料夾
Copy-Item -Path "../include/osgQt" -Destination "$InstallDir/include" -Recurse -Force
# 複製輸出檔案
Copy-Item -Path "./lib/osgQt5.lib" -Destination "$InstallDir/lib" -Force
Copy-Item -Path "./packaging/pkgconfig/openscenegraph-osgQt5.pc" -Destination "$InstallDir/lib/pkgconfig" -Force
Copy-Item -Path "./bin/osg145-osgQt5.dll" -Destination "$InstallDir/bin" -Force
Copy-Item -Path "./bin/osg145-osgQt5.pdb" -Destination "$SymbolDir" -Force

topic/Qt4是舊的版本,所以不能自動找到安裝好的OSG庫,因此需要手動指定OSG_LIBRARY_RELEASE等OSG庫檔案的路徑。另外,這個庫對於RelWithDebInfo型別的構建安裝有點問題,因此沒有使用CMake安裝的方式,而是採用自定義的指令碼進行安裝。如果是Debug或者Release型別,可以直接使用CMake安裝的方式。

最新的主分支構建的關鍵指令如下所示:

#配置CMake      
cmake .. -G "$Generator" -A x64 `
    -DCMAKE_BUILD_TYPE=RelWithDebInfo `
    -DCMAKE_PREFIX_PATH="$InstallDir" `
    -DCMAKE_INSTALL_PREFIX="$InstallDir" `
    -DCMAKE_RELWITHDEBINFO_POSTFIX="" `
    -DBUILD_OSG_EXAMPLES=OFF

# 構建階段,指定構建型別
cmake --build . --config RelWithDebInfo -- /m:8

# 安裝階段,指定構建型別和安裝目標
#cmake --build . --config RelWithDebInfo --target install

# 自定義安裝
# 複製include資料夾
Copy-Item -Path "../include/osgQOpenGL" -Destination "$InstallDir/include" -Recurse -Force
# # 複製輸出檔案
Copy-Item -Path "./lib/osgQOpenGL.lib" -Destination "$InstallDir/lib" -Force
Copy-Item -Path "./packaging/pkgconfig/openscenegraph-osgQt.pc" -Destination "$InstallDir/lib/pkgconfig" -Force
Copy-Item -Path "./bin/osg145-osgQOpenGL.dll" -Destination "$InstallDir/bin" -Force
Copy-Item -Path "./bin/osg145-osgQOpenGL.pdb" -Destination "$SymbolDir" -Force

新版本對OSG庫的查詢沒有問題。不過RelWithDebInfo型別的構建安裝還是有點問題,因此還是採用自定義指令碼的方式進行安裝。

相關文章