Skip to content

Commit

Permalink
Mapple can be built with Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Dec 14, 2024
1 parent 5156f4e commit 8d5541c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 114 deletions.
12 changes: 5 additions & 7 deletions applications/Mapple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
project(${PROJECT_NAME})


include(../../cmake/UseQt5.cmake)
if (NOT QT5_FOUND)
message(WARNING "${PROJECT_NAME} requires Qt but Qt was not found. You can set 'Qt5_DIR' to the "
"directory containing 'Qt5Config.cmake' or 'qt5-config.cmake'. "
"Optionally, you can set the Qt5 root directory 'QT5_ROOT_PATH' to the directory "
"containing the 'bin' folder.")
include(../../cmake/UseQt.cmake)
if (NOT Qt6_FOUND AND NOT Qt5_FOUND)
message(WARNING "${PROJECT_NAME} requires Qt (Qt6 or Qt5), but Qt was not found. You can set 'Qt*_DIR' to the "
"directory containing 'Qt*Config.cmake' or 'qt*-config.cmake' (* is 5 or 6) to specify the location of Qt.")
return()
endif ()

Expand Down Expand Up @@ -212,7 +210,7 @@ if (MSVC)
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_DEPRECATE)
endif ()

target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL)
target_link_libraries(${PROJECT_NAME} PRIVATE ${QtLibs})

target_link_libraries(${PROJECT_NAME} PRIVATE easy3d::renderer easy3d::algo easy3d::gui)
if (Easy3D_HAS_CGAL)
Expand Down
75 changes: 75 additions & 0 deletions cmake/UseQt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# *************************************************************************
# Copyright (C) 2015 Liangliang Nan <[email protected]>
# https://3d.bk.tudelft.nl/liangliang/
#
# This file is part of Easy3D. If it is useful in your research/work,
# I would be grateful if you show your appreciation by citing it:
# ------------------------------------------------------------------
# Liangliang Nan.
# Easy3D: a lightweight, easy-to-use, and efficient C++ library
# for processing and rendering 3D data.
# Journal of Open Source Software, 6(64), 3255, 2021.
# ------------------------------------------------------------------
#
# Easy3D is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 3
# as published by the Free Software Foundation.
#
# Easy3D is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# *************************************************************************


# ------------------------------------------------------------------------------
# This file sets up Qt for CMake. When Qt6 was setup successfully, 'Qt6_FOUND'
# will be set. If Qt6 is not found, it will try to find Qt5. If Qt5 is found,
# 'Qt5_FOUND' will be set. If both Qt6 and Qt5 are not found, it will stop the
# configuration and show an error message.
# If either Qt6 or Qt5 is found, it will set QtLibs to the corresponding Qt
# libraries, e.g., Qt5Core, Qt5Gui, Qt5Widgets, Qt5OpenGL, Qt5Xml, etc.
#
# To use Qt in your program, you only need to include this file and specifying
# Qt libraries to link against, e.g.,
# ------------------------------------------------------------------------
# project(${PROJECT_NAME})
# include( ../cmake/UseQt.cmake )
# add_executable(${PROJECT_NAME}, main.cpp)
# target_link_libraries(${PROJECT_NAME} ${QtLibs})
# ------------------------------------------------------------------------
# NOTE: 'UseQt.cmake' must be included after you define your project but before
# 'add_executable()' or 'add_library()'.
#
# The recommended way to specify libraries and headers with CMake is to use the
# target_link_libraries command. This command automatically adds appropriate
# include directories, compile definitions, the position-independent-code flag,
# and links to the qtmain.lib library on Windows.
# ------------------------------------------------------------------------------

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Instruct CMake to run uic automatically when needed.
set(CMAKE_AUTOUIC ON)
# Instruct CMake to run rcc automatically when needed.
set(CMAKE_AUTORCC ON)

# This will find the Qt files.
find_package(Qt6 COMPONENTS Core Widgets OpenGL OpenGLWidgets QUIET)
if (Qt6_FOUND)
message(STATUS "Found Qt6 version: ${Qt6Core_VERSION}")
set(QtLibs Qt::Core Qt::Widgets Qt::OpenGL Qt::OpenGLWidgets)
else()
find_package(Qt5 COMPONENTS Core Widgets OpenGL QUIET)
if (Qt5_FOUND)
message(STATUS "Found Qt5 version: ${Qt5Core_VERSION}")
set(QtLibs Qt5::Core Qt5::Widgets Qt5::OpenGL)
else()
message(FATAL_ERROR "Qt is required, either Qt6 or Qt5, but both cannot be found")
endif()
endif()
99 changes: 0 additions & 99 deletions cmake/UseQt5.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion easy3d/util/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace easy3d {
#define EASY3D_VERSION_NR 1020504

/// Easy3D release date, in the format YYYYMMDD.
#define EASY3D_RELEASE_DATE 20241129
#define EASY3D_RELEASE_DATE 20241214


#endif // EASY3D_UTIL_VERSION_H
12 changes: 5 additions & 7 deletions tutorials/Tutorial_204_Viewer_Qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ cmake_minimum_required(VERSION 3.12)
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PROJECT_NAME})

include(../../cmake/UseQt5.cmake)
if (NOT QT5_FOUND)
message(WARNING "${PROJECT_NAME} requires Qt but Qt was not found. You can set 'Qt5_DIR' to the "
"directory containing 'Qt5Config.cmake' or 'qt5-config.cmake'. "
"Optionally, you can set the Qt5 root directory 'QT5_ROOT_PATH' to the directory "
"containing the 'bin' folder.")
include(../../cmake/UseQt.cmake)
if (NOT Qt6_FOUND AND NOT Qt5_FOUND)
message(WARNING "${PROJECT_NAME} requires Qt (Qt6 or Qt5), but Qt was not found. You can set 'Qt*_DIR' to the "
"directory containing 'Qt*Config.cmake' or 'qt*-config.cmake' (* is 5 or 6) to specify the location of Qt.")
return()
endif ()

Expand Down Expand Up @@ -83,5 +81,5 @@ endif ()
target_compile_definitions(${PROJECT_NAME} PRIVATE "EXAMPLE_TITLE=\"${PROJECT_NAME}\"")

target_include_directories(${PROJECT_NAME} PRIVATE ${Easy3D_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL easy3d::renderer)
target_link_libraries(${PROJECT_NAME} PRIVATE ${QtLibs} easy3d::renderer)
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "tutorials")

0 comments on commit 8d5541c

Please sign in to comment.