diff --git a/applications/Mapple/CMakeLists.txt b/applications/Mapple/CMakeLists.txt index b1dde626..13a66fae 100644 --- a/applications/Mapple/CMakeLists.txt +++ b/applications/Mapple/CMakeLists.txt @@ -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 () @@ -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) diff --git a/cmake/UseQt.cmake b/cmake/UseQt.cmake new file mode 100644 index 00000000..920af8c1 --- /dev/null +++ b/cmake/UseQt.cmake @@ -0,0 +1,75 @@ +# ************************************************************************* +# Copyright (C) 2015 Liangliang Nan +# 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 . +# ************************************************************************* + + +# ------------------------------------------------------------------------------ +# 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() \ No newline at end of file diff --git a/cmake/UseQt5.cmake b/cmake/UseQt5.cmake deleted file mode 100644 index 7a41adad..00000000 --- a/cmake/UseQt5.cmake +++ /dev/null @@ -1,99 +0,0 @@ -# ************************************************************************* -# Copyright (C) 2015 Liangliang Nan -# 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 . -# ************************************************************************* - - -# ------------------------------------------------------------------------------ -# This file sets up Qt5 for CMake. When Qt5 was setup successfuly, QT5_FOUND -# will be set. -# -# To use QT5_FOUND, you only need to include this file and specifying Qt libraries -# to link against, e.g., -# ------------------------------------------------------------------------ -# project(${PROJECT_NAME}) -# include( ../../cmake/UseQt5.cmake ) -# add_executable(${PROJECT_NAME}, main.cpp) -# target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL) -# ------------------------------------------------------------------------ -# NOTE: 'UseQt5.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. -# ------------------------------------------------------------------------------ - - -# we will use cmake autouic/automoc/autorcc features -set(CMAKE_AUTOUIC ON) -set(CMAKE_AUTOMOC ON) # Tell CMake to run moc when necessary -set(CMAKE_AUTORCC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) # As moc files are generated in the binary dir, tell CMake to always look for includes there - -set(QT5_ROOT_PATH CACHE PATH "Qt5 root directory (i.e. where the 'bin' folder lies)") -if (QT5_ROOT_PATH) - list(APPEND CMAKE_PREFIX_PATH ${QT5_ROOT_PATH}) -endif () - -# find qt5 components -find_package(Qt5 COMPONENTS Core Gui OpenGL Widgets) -# or -# find_package(Qt5Core QUIET) -# find_package(Qt5Gui QUIET) -# find_package(Qt5OpenGL QUIET) -# find_package(Qt5Widgets QUIET) - -# In the case no Qt5Config.cmake file could be found, cmake will explicitly ask the user for the QT5_DIR containing it! - -if (Qt5Core_FOUND AND Qt5Gui_FOUND AND Qt5OpenGL_FOUND AND Qt5Widgets_FOUND) - set(QT5_FOUND TRUE) -endif () - -if (QT5_FOUND) - # Starting with the QtCore lib, find the bin and root directories - get_target_property(QT5_LIB_LOCATION Qt5::Core LOCATION_${CMAKE_BUILD_TYPE}) - get_filename_component(QT_BINARY_DIR ${QT5_LIB_LOCATION} DIRECTORY) - - if (APPLE) - # Apple uses frameworks - move up until we get to the base directory to set the bin directory properly - get_filename_component(QT_BINARY_DIR ${QT_BINARY_DIR} DIRECTORY) - set(QT_BINARY_DIR ${QT_BINARY_DIR}/bin) - set(MACDEPLOYQT ${QT_BINARY_DIR}/macdeployqt) - message(STATUS "macdeployqt: ${MACDEPLOYQT}") - elseif(WIN32) - set(WINDEPLOYQT ${QT_BINARY_DIR}/windeployqt.exe) - message(STATUS "windeployqt: ${WINDEPLOYQT}") - endif () - - # set QT5_ROOT_PATH if it wasn't set by the user - if (NOT QT5_ROOT_PATH) - get_filename_component(QT5_ROOT_PATH ${QT_BINARY_DIR} DIRECTORY) - endif () - - # turn on QStringBuilder for more efficient string construction - # see https://doc.qt.io/qt-5/qstring.html#more-efficient-string-construction - add_definitions(-DQT_USE_QSTRINGBUILDER) -endif () diff --git a/easy3d/util/version.h b/easy3d/util/version.h index 18a0e654..58df98a6 100644 --- a/easy3d/util/version.h +++ b/easy3d/util/version.h @@ -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 diff --git a/tutorials/Tutorial_204_Viewer_Qt/CMakeLists.txt b/tutorials/Tutorial_204_Viewer_Qt/CMakeLists.txt index d526f45b..1f450f4b 100644 --- a/tutorials/Tutorial_204_Viewer_Qt/CMakeLists.txt +++ b/tutorials/Tutorial_204_Viewer_Qt/CMakeLists.txt @@ -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 () @@ -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")