Skip to content

Commit

Permalink
[Fix]Compile Ubuntu20.04
Browse files Browse the repository at this point in the history
  • Loading branch information
scially committed Apr 25, 2022
1 parent 8431c3b commit 4cade57
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 104 deletions.
114 changes: 96 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,127 @@
cmake_minimum_required (VERSION 3.8)
project(Cesium3DTilesConverter)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_RELEASE_POSTFIX "")

if(MSVC)
add_definitions(-DNOMINMAX)
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/binary/windows")
set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/binary/windows")
else()
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/binary/linux")
set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/binary/linux")
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/debug")
set(LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH}/debug")
else()
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/release")
set(LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH}/release")
endif()

option(ENABLE_TEST "Enable test" ON)

option(ENABLE_TEST "Enable Test" ON)

find_package(GDAL REQUIRED)
find_package(PROJ REQUIRED)
find_package(Qt5
REQUIRED
COMPONENTS Core Xml Test)

find_package(OpenSceneGraph
REQUIRED
COMPONENTS osgDB osgGA osgUtil osgViewer)
message(status ${OPENSCENEGRAPH_LIBRARIES})
message(status ${OPENSCENEGRAPH_INCLUDE_DIRS})
COMPONENTS osgDB osgUtil)

# 将源代码添加到此项目的可执行文件。
include_directories(
"include"
include
${OPENSCENEGRAPH_INCLUDE_DIRS}
${GDAL_INCLUDE_DIR})

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

add_subdirectory(src)
add_library(Core STATIC
"include/CoordinateConvert.h"
"include/OGRException.h"
"include/OSGBPageLodVisitor.h"
"include/OSGBLevel.h"
"include/BoundingVolume.h"
"include/BoundingVolumeBox.h"
"include/BoundingVolumeRegion.h"
"include/AssetProperties.h"
"include/BoundingVolumeSphere.h"
"include/TileMatrix.h"
"include/Refine.h"
"include/ContentTile.h"
"include/RootTile.h"
"include/BaseTile.h"
"include/OSGBuildState.h"
"include/stb_image.h"
"include/stb_image_write.h"
"include/tiny_gltf.h"
"include/TilesParseException.h"
"include/TilesConvertException.h"
"include/OSGBConvertJob.h"
"include/ShpConvertJob.h"
"include/ModelMetadata.h"
"include/QuadTree.h"
"include/ShpConvert.h"
"include/GeometryMesh.h"
"include/GDALWrapper.h"
"include/Batched3DModel.h"
"include/Utils.h"
"include/earcut.hpp"

"src/CoordinateConvert.cpp"
"src/OSGBPageLodVisitor.cpp"
"src/BoundingVolume.cpp"
"src/BoundingVolumeBox.cpp"
"src/BoundingVolumeRegion.cpp"
"src/BoundingVolumeSphere.cpp"
"src/AssetProperties.cpp"
"src/TileMatrix.cpp"
"src/Refine.cpp"
"src/ContentTile.cpp"
"src/RootTile.cpp"
"src/BaseTile.cpp"
"src/DxtImage.cpp"
"src/OSGBuildState.cpp"
"src/OSGBLevel.cpp"
"src/OSGBConvert.cpp"
"src/OSGBConvertJob.cpp"
"src/ModelMetadata.cpp"
"src/QuadTree.cpp"
"src/GeometryMesh.cpp"
"src/Batched3DModel.cpp"
"src/ShpConvert.cpp"
"src/ShpConvertJob.cpp")

target_link_libraries(Core
${GDAL_LIBRARIES}
${PROJ_LIBRARIES}
${OPENSCENEGRAPH_LIBRARIES}
Qt5::Xml
Qt5::Core)

if(UNIX)
target_link_libraries(Core -lGL)
endif()

add_executable(Converter src/main.cpp)
target_link_libraries(Converter
Core)

add_custom_command(TARGET Converter
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${EXECUTABLE_OUTPUT_PATH}/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${EXECUTABLE_OUTPUT_PATH}/gdal_data)

if(ENABLE_TEST)
message(status "open test")
enable_testing(true)
add_subdirectory(test)
add_custom_target(CopyResources ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${PROJECT_BINARY_DIR}/src/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${PROJECT_BINARY_DIR}/test/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${PROJECT_BINARY_DIR}/src/gdal_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${PROJECT_BINARY_DIR}/test/gdal_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/data ${PROJECT_BINARY_DIR}/test/data)
else()
add_custom_target(CopyResources ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${PROJECT_BINARY_DIR}/src/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${PROJECT_BINARY_DIR}/src/gdal_data)
endif()
96 changes: 96 additions & 0 deletions cmake/FindPROJ.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Find Proj
# ~~~~~~~~~
# Copyright (c) 2007, Martin Dobias <wonder.sk at gmail.com>
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
# CMake module to search for Proj library
#
# If it's found it sets PROJ_FOUND to TRUE
# and following variables are set:
# PROJ_INCLUDE_DIR
# PROJ_LIBRARIES

# FIND_PATH and PROJ_LIBRARIES normally search standard locations
# before the specified paths. To search non-standard paths first,
# FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
# and then again with no specified paths to search the default
# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
# searching for the same item do nothing.

# try to use framework on mac
# want clean framework path, not unix compatibility path
IF (APPLE)
IF (CMAKE_FIND_FRAMEWORK MATCHES "FIRST"
OR CMAKE_FRAMEWORK_PATH MATCHES "ONLY"
OR NOT CMAKE_FIND_FRAMEWORK)
SET (CMAKE_FIND_FRAMEWORK_save ${CMAKE_FIND_FRAMEWORK} CACHE STRING "" FORCE)
SET (CMAKE_FIND_FRAMEWORK "ONLY" CACHE STRING "" FORCE)
#FIND_PATH(PROJ_INCLUDE_DIR PROJ/proj_api.h)
FIND_LIBRARY(PROJ_LIBRARIES PROJ)
IF (PROJ_LIBRARIES)
# FIND_PATH doesn't add "Headers" for a framework
SET (PROJ_INCLUDE_DIR ${PROJ_LIBRARY}/Headers CACHE PATH "Path to a file.")
ENDIF (PROJ_LIBRARIES)
SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
ENDIF ()
ENDIF (APPLE)

FIND_PATH(PROJ_INCLUDE_DIR proj_api.h
"$ENV{INCLUDE}"
"$ENV{LIB_DIR}/include"
)
IF (NOT PROJ_INCLUDE_DIR)
FIND_PATH(PROJ_INCLUDE_DIR proj.h
"$ENV{INCLUDE}"
"$ENV{LIB_DIR}/include"
)
ENDIF (NOT PROJ_INCLUDE_DIR)

FIND_LIBRARY(PROJ_LIBRARIES NAMES proj_i proj PATHS
"$ENV{LIB}"
"$ENV{LIB_DIR}/lib"
)

IF (PROJ_INCLUDE_DIR AND PROJ_LIBRARIES)
SET(PROJ_FOUND TRUE)
ENDIF (PROJ_INCLUDE_DIR AND PROJ_LIBRARIES)

IF (PROJ_FOUND)
IF (EXISTS ${PROJ_INCLUDE_DIR}/proj.h AND EXISTS ${PROJ_INCLUDE_DIR}/proj_experimental.h)
FILE(READ ${PROJ_INCLUDE_DIR}/proj.h proj_version)
STRING(REGEX REPLACE "^.*PROJ_VERSION_MAJOR +([0-9]+).*$" "\\1" PROJ_VERSION_MAJOR "${proj_version}")
STRING(REGEX REPLACE "^.*PROJ_VERSION_MINOR +([0-9]+).*$" "\\1" PROJ_VERSION_MINOR "${proj_version}")
STRING(REGEX REPLACE "^.*PROJ_VERSION_PATCH +([0-9]+).*$" "\\1" PROJ_VERSION_PATCH "${proj_version}")
STRING(CONCAT PROJ_VERSION_STR "(" ${PROJ_VERSION_MAJOR} "." ${PROJ_VERSION_MINOR} "." ${PROJ_VERSION_PATCH} ")")
IF ((PROJ_VERSION_MAJOR EQUAL 6) AND ((PROJ_VERSION_MINOR LESS 3) OR (PROJ_VERSION_MINOR EQUAL 3 AND PROJ_VERSION_PATCH LESS 1)))
MESSAGE (FATAL_ERROR "Cannot build QGIS using Proj ${PROJ_VERSION_MAJOR}.${PROJ_VERSION_MINOR}.${PROJ_VERSION_PATCH} Use 6.3.1 or higher.")
ENDIF ((PROJ_VERSION_MAJOR EQUAL 6) AND ((PROJ_VERSION_MINOR LESS 3) OR (PROJ_VERSION_MINOR EQUAL 3 AND PROJ_VERSION_PATCH LESS 1)))
ELSE(EXISTS ${PROJ_INCLUDE_DIR}/proj.h AND EXISTS ${PROJ_INCLUDE_DIR}/proj_experimental.h)
FILE(READ ${PROJ_INCLUDE_DIR}/proj_api.h proj_version)
STRING(REGEX REPLACE "^.*PJ_VERSION ([0-9]+).*$" "\\1" PJ_VERSION "${proj_version}")

# This will break if 4.10.0 ever will be released (highly unlikely)
STRING(REGEX REPLACE "([0-9])([0-9])([0-9])" "\\1" PROJ_VERSION_MAJOR "${PJ_VERSION}")
STRING(REGEX REPLACE "([0-9])([0-9])([0-9])" "\\2" PROJ_VERSION_MINOR "${PJ_VERSION}")
STRING(REGEX REPLACE "([0-9])([0-9])([0-9])" "\\3" PROJ_VERSION_PATCH "${PJ_VERSION}")
STRING(CONCAT PROJ_VERSION_STR "(" ${PROJ_VERSION_MAJOR} "." ${PROJ_VERSION_MINOR} "." ${PROJ_VERSION_PATCH} ")")

# Minimum Proj version required is 4.9.3
IF ((PROJ_VERSION_MAJOR EQUAL 4) AND ((PROJ_VERSION_MINOR LESS 9) OR ((PROJ_VERSION_MINOR EQUAL 9) AND (PROJ_VERSION_PATCH LESS 3))))
MESSAGE(FATAL_ERROR "Found Proj: ${PROJ_VERSION_MAJOR}.${PROJ_VERSION_MINOR}.${PROJ_VERSION_PATCH}. Cannot build QGIS using Proj older than 4.9.3.")
ENDIF((PROJ_VERSION_MAJOR EQUAL 4) AND ((PROJ_VERSION_MINOR LESS 9) OR ((PROJ_VERSION_MINOR EQUAL 9) AND (PROJ_VERSION_PATCH LESS 3))))
ENDIF(EXISTS ${PROJ_INCLUDE_DIR}/proj.h AND EXISTS ${PROJ_INCLUDE_DIR}/proj_experimental.h)
IF (NOT PROJ_FIND_QUIETLY)
MESSAGE(STATUS "Found Proj: ${PROJ_LIBRARIES} version ${PROJ_VERSION_MAJOR} ${PROJ_VERSION_STR}")
ENDIF (NOT PROJ_FIND_QUIETLY)

INCLUDE_DIRECTORIES(BEFORE SYSTEM ${PROJ_INCLUDE_DIR})

ELSE (PROJ_FOUND)

IF (PROJ_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Proj")
ENDIF (PROJ_FIND_REQUIRED)

ENDIF (PROJ_FOUND)
7 changes: 7 additions & 0 deletions script/Converter.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Categories=Application;
Icon=default
Name=Converter
Type=Application
Exec=Converter

Binary file added script/Converter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions script/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash

cd ../
linuxdeploy-x86_64.AppImage --appdir AppDir -e ./binary/linux/release/Converter -i ./script/Converter.png --desktop-file ./script/Converter.desktop -o appimage

cp -r ./gdal_data ./proj_data ./AppDir/usr/bin
cp -r /usr/lib/x86_64-linux-gnu/osgPlugins-3.6.5 ./AppDir/usr/bin
72 changes: 0 additions & 72 deletions src/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions src/OSGBuildState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace scially {
}
default:
{
qCritical("Unsupport osg::PrimitiveSet::Type [%1]", t);
qCritical("Unsupport osg::PrimitiveSet::Type [%d]", t);
return false;
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ namespace scially {
primits.mode = TINYGLTF_MODE_TRIANGLE_FAN;
break;
default:
qWarning("Unsupport Primitive Mode: [%1]", ps->getMode());
qWarning("Unsupport Primitive Mode: [%d]", ps->getMode());
return false;
}
model->meshes.back().primitives.push_back(primits);
Expand Down
19 changes: 7 additions & 12 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# TestGDAL
add_executable(TestGDAL "TestGDAL.cpp")
target_link_libraries(TestGDAL Qt5::Test Core)
add_test(name TestGDAL command TestGDAL)

# Test3DTiles
add_executable(Test3DTiles "Test3DTiles.cpp")
target_link_libraries(Test3DTiles Qt5::Test Core)
add_test(name Test3DTiles command Test3DTiles)
FILE(GLOB TestUnits "Test*.cpp")

# TestOSGBConvert
add_executable(TestOSGBConvert "TestOSGBConvert.cpp")
target_link_libraries(TestOSGBConvert Qt5::Test Core)
add_test(name TestOSGBConvert command TestOSGBConvert)
foreach(TestUnit IN LISTS TestUnits)
get_filename_component(TestUnitName ${TestUnit} NAME_WE)
add_executable(${TestUnitName} ${TestUnit})
target_link_libraries(${TestUnitName}
Qt5::Test Core)
endforeach()

0 comments on commit 4cade57

Please sign in to comment.