From b3762f829d0813548f6399a43d145c17bb8235a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20L=C3=BCbke?= Date: Tue, 3 Oct 2023 00:42:26 +0200 Subject: [PATCH 1/6] - Updated CMakeLists for Windows build on VS2019 (vc 142 or so...). --- CMakeLists.txt | 140 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 108 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 034e560c..cf4d13ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,40 +27,116 @@ else() set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL) endif() - find_package(OpenGL REQUIRED) -# QGLViewer target. -set(QGLViewer_SRC - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/BackFaceCullingOptimizer.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/BSPSortMethod.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/EPSExporter.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/Exporter.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/FIGExporter.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/gpc.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/NVector3.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/ParserGL.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/Primitive.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/PrimitivePositioning.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/TopologicalSortMethod.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/Vector2.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/Vector3.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/VisibilityOptimizer.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/VRender/VRender.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/camera.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/constraint.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/frame.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/keyFrameInterpolator.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/manipulatedCameraFrame.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/manipulatedFrame.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/mouseGrabber.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/qglviewer.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/quaternion.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/saveSnapshot.cpp" - "${PROJECT_SOURCE_DIR}/QGLViewer/vec.cpp") -add_library(QGLViewer SHARED ${QGLViewer_SRC}) -target_include_directories(QGLViewer INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(QGLViewer PRIVATE ${QtLibs} OpenGL::GL OpenGL::GLU) +include_directories( + "${PROJECT_SOURCE_DIR}/QGLViewer/" + ${Qt5Core_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5Xml_INCLUDE_DIRS} + ${Qt5OpenGL_INCLUDE_DIRS} +) + +set(MOC_HEADER_FILES + QGLViewer/camera.h + QGLViewer/frame.h + QGLViewer/keyFrameInterpolator.h + QGLViewer/manipulatedCameraFrame.h + QGLViewer/manipulatedFrame.h + QGLViewer/qglviewer.h + ) +# These header files don't need to be processed by the moc. +set(HEADER_FILES + QGLViewer/VRender/AxisAlignedBox.h + QGLViewer/VRender/Exporter.h + QGLViewer/VRender/NVector3.h + QGLViewer/VRender/Optimizer.h + QGLViewer/VRender/ParserGL.h + QGLViewer/VRender/Primitive.h + QGLViewer/VRender/PrimitivePositioning.h + QGLViewer/VRender/SortMethod.h + QGLViewer/VRender/Types.h + QGLViewer/VRender/VRender.h + QGLViewer/VRender/Vector2.h + QGLViewer/VRender/Vector3.h + QGLViewer/VRender/gpc.h + QGLViewer/config.h + QGLViewer/constraint.h + QGLViewer/domUtils.h + QGLViewer/mouseGrabber.h + QGLViewer/quaternion.h + QGLViewer/vec.h + ) +set(SOURCE_FILES + QGLViewer/VRender/BSPSortMethod.cpp + QGLViewer/VRender/BackFaceCullingOptimizer.cpp + QGLViewer/VRender/EPSExporter.cpp + QGLViewer/VRender/Exporter.cpp + QGLViewer/VRender/FIGExporter.cpp + QGLViewer/VRender/NVector3.cpp + QGLViewer/VRender/ParserGL.cpp + QGLViewer/VRender/Primitive.cpp + QGLViewer/VRender/PrimitivePositioning.cpp + QGLViewer/VRender/TopologicalSortMethod.cpp + QGLViewer/VRender/VRender.cpp + QGLViewer/VRender/Vector2.cpp + QGLViewer/VRender/Vector3.cpp + QGLViewer/VRender/VisibilityOptimizer.cpp + QGLViewer/VRender/gpc.cpp + QGLViewer/camera.cpp + QGLViewer/constraint.cpp + QGLViewer/frame.cpp + QGLViewer/keyFrameInterpolator.cpp + QGLViewer/manipulatedCameraFrame.cpp + QGLViewer/manipulatedFrame.cpp + QGLViewer/mouseGrabber.cpp + QGLViewer/qglviewer.cpp + QGLViewer/quaternion.cpp + QGLViewer/saveSnapshot.cpp + QGLViewer/vec.cpp + ) +set(UI_FILES + QGLViewer/ImageInterface.ui + QGLViewer/VRenderInterface.ui + ) + +qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES}) +qt5_wrap_ui(FORM_FILES ${UI_FILES}) + +add_library(QGLViewer SHARED ${HEADER_FILES} ${MOC_FILES} ${FORM_FILES} ${SOURCE_FILES}) + +# WIN32 and UNIX/LINUX use different names for the OpenGL lib +if (WIN32) + set(OPENGL_LIB OpenGL32) +else() + set(OPENGL_LIB OpenGL) +endif() + +target_link_libraries(QGLViewer + PUBLIC + Qt5::Core + Qt5::Widgets + Qt5::OpenGL + Qt5::Xml + ${GLUT_LIBRARY} + ${OPENGL_LIB} + OpenGL::GLU +) + +if(WIN32) + add_compile_definitions(NOMINMAX) + target_compile_options(QGLViewer PRIVATE "-DCREATE_QGLVIEWER_DLL") + # remove warnings about deprecation (CRT,etc) + target_compile_options(QGLViewer PRIVATE "/wd4996") +endif() + +add_custom_command( + TARGET QGLViewer + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_BINARY_DIR}" +) # Example: animation. set(animation_SRC From f9f1f410ad69546c710dc9fc8661e68be0d04021 Mon Sep 17 00:00:00 2001 From: Dennis Luebke Date: Tue, 3 Oct 2023 01:36:29 +0200 Subject: [PATCH 2/6] - mostly finished... --- CMakeLists.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf4d13ca..c00f99dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ if(POLICY CMP0048) cmake_policy(SET CMP0048 NEW) endif() -project(libQGLViewer LANGUAGES CXX VERSION 2.9.1) cmake_minimum_required(VERSION 3.16) +project(libQGLViewer LANGUAGES CXX VERSION 2.9.1) # Qt6 minimum compiler version set(CMAKE_CXX_STANDARD 17) @@ -17,13 +17,14 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) # This will find the Qt files. -find_package(Qt6 COMPONENTS Core Widgets Xml OpenGL OpenGLWidgets) -if (Qt6_FOUND) - message("Building with Qt6") - set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) -else() - find_package(Qt5 5.15 REQUIRED COMPONENTS Core Widgets Xml OpenGL) - message("Building with Qt5") +#find_package(Qt6 COMPONENTS Core Widgets Xml OpenGL OpenGLWidgets) +#if (Qt6_FOUND) +# message("Qt6 found!") +# set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) +#endif() +find_package(Qt5 REQUIRED COMPONENTS Core Widgets Xml OpenGL) +if(Qt5_FOUND) + message("Qt5 found! Preferring Qt5 for now.") set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL) endif() @@ -100,8 +101,8 @@ set(UI_FILES QGLViewer/VRenderInterface.ui ) -qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES}) -qt5_wrap_ui(FORM_FILES ${UI_FILES}) +#qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES}) +#qt5_wrap_ui(FORM_FILES ${UI_FILES}) add_library(QGLViewer SHARED ${HEADER_FILES} ${MOC_FILES} ${FORM_FILES} ${SOURCE_FILES}) From 9e27aba75000f10ed39880848e22d76f9147d51f Mon Sep 17 00:00:00 2001 From: Dennis Luebke Date: Tue, 3 Oct 2023 01:57:27 +0200 Subject: [PATCH 3/6] - added comments for WIN32 specific lines --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c00f99dd..f2811a3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,7 @@ target_link_libraries(QGLViewer ) if(WIN32) + # ignore minwindef.h to use std::min/max add_compile_definitions(NOMINMAX) target_compile_options(QGLViewer PRIVATE "-DCREATE_QGLVIEWER_DLL") # remove warnings about deprecation (CRT,etc) From b4daf5f10ab72fea52f340cf280c8d95e6c4d785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20L=C3=BCbke?= Date: Tue, 3 Oct 2023 12:07:56 +0200 Subject: [PATCH 4/6] - CMake Windows build now for Qt5 and Qt6 (depending on what folder you choose in CMake Gui - added forward declaration already PR'd here https://github.com/GillesDebunne/libQGLViewer/pull/71/files to fix the Qt6 build on Windows (this was not a problem with Qt5...) --- CMakeLists.txt | 32 +++++++++++--------------------- QGLViewer/VRender/Primitive.h | 1 + QGLViewer/VRender/Vector3.h | 2 ++ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2811a3a..8f4aa647 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,25 +17,22 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) # This will find the Qt files. -#find_package(Qt6 COMPONENTS Core Widgets Xml OpenGL OpenGLWidgets) -#if (Qt6_FOUND) -# message("Qt6 found!") -# set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) -#endif() -find_package(Qt5 REQUIRED COMPONENTS Core Widgets Xml OpenGL) -if(Qt5_FOUND) - message("Qt5 found! Preferring Qt5 for now.") - set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL) +find_package(Qt6 COMPONENTS Core Widgets Xml OpenGL OpenGLWidgets) +if (Qt6_FOUND) + message("Qt6 found!") + set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) +else() + find_package(Qt5 REQUIRED COMPONENTS Core Widgets Xml OpenGL) + if(Qt5_FOUND) + message("Qt5 found! Preferring Qt5 for now.") + set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL) + endif() endif() find_package(OpenGL REQUIRED) include_directories( "${PROJECT_SOURCE_DIR}/QGLViewer/" - ${Qt5Core_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} - ${Qt5Xml_INCLUDE_DIRS} - ${Qt5OpenGL_INCLUDE_DIRS} ) set(MOC_HEADER_FILES @@ -101,9 +98,6 @@ set(UI_FILES QGLViewer/VRenderInterface.ui ) -#qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES}) -#qt5_wrap_ui(FORM_FILES ${UI_FILES}) - add_library(QGLViewer SHARED ${HEADER_FILES} ${MOC_FILES} ${FORM_FILES} ${SOURCE_FILES}) # WIN32 and UNIX/LINUX use different names for the OpenGL lib @@ -115,11 +109,7 @@ endif() target_link_libraries(QGLViewer PUBLIC - Qt5::Core - Qt5::Widgets - Qt5::OpenGL - Qt5::Xml - ${GLUT_LIBRARY} + ${QtLibs} ${OPENGL_LIB} OpenGL::GLU ) diff --git a/QGLViewer/VRender/Primitive.h b/QGLViewer/VRender/Primitive.h index 88ab11d0..a088f4ed 100644 --- a/QGLViewer/VRender/Primitive.h +++ b/QGLViewer/VRender/Primitive.h @@ -21,6 +21,7 @@ namespace vrender { class Feedback3DColor ; class Primitive ; + std::ostream& operator<<(std::ostream&, const Feedback3DColor&); #define EPS_SMOOTH_LINE_FACTOR 0.06 /* Lower for better smooth lines. */ diff --git a/QGLViewer/VRender/Vector3.h b/QGLViewer/VRender/Vector3.h index 32597e8c..464bff6d 100644 --- a/QGLViewer/VRender/Vector3.h +++ b/QGLViewer/VRender/Vector3.h @@ -10,6 +10,8 @@ namespace vrender { class NVector3; + class Vector3; + std::ostream& operator<< (std::ostream&, const Vector3&); class Vector3 { From e8e421ea7dce01f7b0b55e4c8bd428b6f1fd1608 Mon Sep 17 00:00:00 2001 From: Dennis Luebke Date: Tue, 3 Oct 2023 12:29:19 +0200 Subject: [PATCH 5/6] - replaced tabs with spaces --- CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f4aa647..16f2cce6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,11 +22,11 @@ if (Qt6_FOUND) message("Qt6 found!") set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) else() - find_package(Qt5 REQUIRED COMPONENTS Core Widgets Xml OpenGL) - if(Qt5_FOUND) - message("Qt5 found! Preferring Qt5 for now.") - set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL) - endif() + find_package(Qt5 REQUIRED COMPONENTS Core Widgets Xml OpenGL) + if(Qt5_FOUND) + message("Qt5 found! Preferring Qt5 for now.") + set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL) + endif() endif() find_package(OpenGL REQUIRED) @@ -108,10 +108,10 @@ else() endif() target_link_libraries(QGLViewer - PUBLIC - ${QtLibs} - ${OPENGL_LIB} - OpenGL::GLU + PUBLIC + ${QtLibs} + ${OPENGL_LIB} + OpenGL::GLU ) if(WIN32) From d0eabe685aa93e60faaaf66c41929f230d8f9bc7 Mon Sep 17 00:00:00 2001 From: Dennis Luebke Date: Tue, 3 Oct 2023 13:59:18 +0200 Subject: [PATCH 6/6] - use the platform independent OpenGL::GL library name instead of the manual distinction --- CMakeLists.txt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16f2cce6..82b0b802 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,17 +100,10 @@ set(UI_FILES add_library(QGLViewer SHARED ${HEADER_FILES} ${MOC_FILES} ${FORM_FILES} ${SOURCE_FILES}) -# WIN32 and UNIX/LINUX use different names for the OpenGL lib -if (WIN32) - set(OPENGL_LIB OpenGL32) -else() - set(OPENGL_LIB OpenGL) -endif() - target_link_libraries(QGLViewer PUBLIC ${QtLibs} - ${OPENGL_LIB} + OpenGL::GL OpenGL::GLU )