windows11用Qt6自带的mingw编译OSGEarth(自用记录)
- 依赖库
- 与cmke的find_package斗志斗勇
我习惯把第三方库分为include、lib、和bin
把 find_package 变成变量、include_directories
# find_package(OpenSceneGraph REQUIRED COMPONENTS osgManipulator osgShadow osgSim osgViewer osgGA osgUtil osgText osgDB osg OpenThreads)set(OPENSCENEGRAPH_ROOT "${PROJECT_SOURCE_DIR}/src/third_party/OpenSceneGraph")
include_directories("${OPENSCENEGRAPH_ROOT}/include")
set(OPENSCENEGRAPH_LIBRARIES"${OPENSCENEGRAPH_ROOT}/lib/libosg.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgDB.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgUtil.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgGA.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgText.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgSim.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgShadow.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgManipulator.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libOpenThreads.dll.a""${OPENSCENEGRAPH_ROOT}/lib/libosgViewer.dll.a")# 从头文件解析 OSG 版本
if(EXISTS "${OPENSCENEGRAPH_INCLUDE_DIR}/osg/Version")file(READ "${OPENSCENEGRAPH_INCLUDE_DIR}/osg/Version" _osg_version)string(REGEX MATCH "OSG_VERSION_MAJOR ([0-9]+)" _ ${_osg_version})set(_osg_major ${CMAKE_MATCH_1})string(REGEX MATCH "OSG_VERSION_MINOR ([0-9]+)" _ ${_osg_version})set(_osg_minor ${CMAKE_MATCH_1})set(OPENSCENEGRAPH_VERSION "${_osg_major}.${_osg_minor}.0")
else()set(OPENSCENEGRAPH_VERSION "3.6.5") # 默认版本号,根据实际情况修改
endif()message(STATUS "Using prebuilt OpenSceneGraph from ${OPENSCENEGRAPH_ROOT}")
message(STATUS "Found OSG version ${OPENSCENEGRAPH_VERSION}")
osgEarth下面的CMakeList.txt
# osgEarth Core Libraryif(OSGEARTH_BUILD_SHARED_LIBS)add_definitions(-DOSGEARTH_LIBRARY)
endif()# Dependencies ...................................................# # required
# find_package(CURL REQUIRED)
# find_package(GDAL REQUIRED)
# find_package(SQLite3 REQUIRED)# # optional
# find_package(geos QUIET)
# find_package(blend2d QUIET)
# find_package(spdlog QUIET)
# find_package(meshoptimizer QUIET)# 直接设置第三方库路径(替换原 find_package 部分)
set(THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/src/third_party")# 必需库:CURL
include_directories("${THIRD_PARTY_ROOT}/curl/include")
set(CURL_LIBRARIES "${THIRD_PARTY_ROOT}/curl/lib/libcurl.dll.a")
link_directories("${THIRD_PARTY_ROOT}/curl/lib/")
# 必需库:GDAL
include_directories("${THIRD_PARTY_ROOT}/gdal/include")
set(GDAL_LIBRARIES "${THIRD_PARTY_ROOT}/gdal/lib/libgdal.dll.a")
link_directories("${THIRD_PARTY_ROOT}/gdal/lib/")# 必需库:SQLite3set(SQLite3_INCLUDE_DIR "${THIRD_PARTY_ROOT}/sqlite/include")
include_directories(SQLite3_INCLUDE_DIR)
set(SQLite3_LIBRARIES "${THIRD_PARTY_ROOT}/sqlite/lib/sqlite3.lib")
link_directories("${THIRD_PARTY_ROOT}/sqlite/lib/")
set(SQLite3_FOUND TRUE)
# 可选库:GEOS
include_directories("${THIRD_PARTY_ROOT}/geos/include")
set(GEOS_LIBRARIES "${THIRD_PARTY_ROOT}/geos/lib/libgeos_c.dll.a")
link_directories("${THIRD_PARTY_ROOT}/geos/lib/")
set(GEOS_FOUND TRUE)
#PROJ
include_directories("${THIRD_PARTY_ROOT}/proj/include")
set(GDAL_LIBRARIES "${THIRD_PARTY_ROOT}/proj/lib/libproj.dll.a")
link_directories("${THIRD_PARTY_ROOT}/proj/lib/")
- lerc需要重新配置,命名空间Lerc-> LercNS
include_directories(BEFORE ../../third_party/lerc/include )
include_directories(BEFORE ../../third_party/lerc )add_osgearth_plugin(TARGET osgdb_lercSOURCESReaderWriterLERC.cpp../../third_party/lerc/src/LercLib/BitMask.cpp../../third_party/lerc/src/LercLib/BitStuffer2.cpp../../third_party/lerc/src/LercLib/Huffman.cpp../../third_party/lerc/src/LercLib/Lerc.cpp../../third_party/lerc/src/LercLib/Lerc_c_api_impl.cpp../../third_party/lerc/src/LercLib/Lerc2.cpp../../third_party/lerc/src/LercLib/RLE.cpp../../third_party/lerc/src/LercLib/Lerc1Decode/BitStuffer.cpp../../third_party/lerc/src/LercLib/Lerc1Decode/CntZImage.cpp../../third_party/lerc/src/LercLib/fpl_Lerc2Ext.cpp../../third_party/lerc/src/LercLib/fpl_UnitTypes.cpp../../third_party/lerc/src/LercLib/fpl_Predictor.cpp../../third_party/lerc/src/LercLib/fpl_Compression.cpp../../third_party/lerc/src/LercLib/fpl_EsriHuffman.cpp)
- 依赖库主要是GDAL难
#gdal_target_link_libraries(alg PRIVATE PROJ::proj)
target_link_libraries(alg PRIVATE D:/gdal/third_party/proj/lib/libproj.dll.a)
FindPROJ.cmake开头添加
set(PROJ_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/third_party/proj/include")
set(PROJ_LIBRARY "${CMAKE_SOURCE_DIR}/third_party/proj/lib/libproj.dll.a")
include_directories(${PROJ_INCLUDE_DIR})
link_directories(${PROJ_LIBRARY})
4.运行结果
osgearth_map.exe