2021-09-03 16:56:57 +00:00
|
|
|
################################################################################
|
|
|
|
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
|
|
|
|
## ##
|
2022-03-06 16:54:05 +00:00
|
|
|
## Project for working with OpenGL and Qt6 widgets ##
|
2021-09-03 16:56:57 +00:00
|
|
|
################################################################################
|
2022-08-07 17:12:12 +00:00
|
|
|
cmake_minimum_required(VERSION 3.2)
|
2021-09-03 16:56:57 +00:00
|
|
|
|
|
|
|
project(
|
|
|
|
#[[NAME]] Qtk
|
|
|
|
VERSION 1.0
|
|
|
|
DESCRIPTION "An example project using QT and OpenGL"
|
2021-09-12 16:49:59 +00:00
|
|
|
LANGUAGES CXX C
|
2021-09-03 16:56:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
set(CMAKE_AUTORCC ON)
|
2022-08-07 17:12:12 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2021-09-03 16:56:57 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
2022-08-14 22:17:05 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
add_compile_options(/WX-)
|
|
|
|
endif()
|
|
|
|
|
2022-08-14 22:08:06 +00:00
|
|
|
# Qtk build options
|
2022-08-07 17:12:12 +00:00
|
|
|
option(QTK_DEBUG "Enable debugger" ON)
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
2022-08-14 22:08:06 +00:00
|
|
|
|
|
|
|
# Qt options
|
|
|
|
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
|
|
|
|
|
|
|
|
# Options for bringing your own assimp installation; Otherwise not needed
|
2022-08-14 22:17:05 +00:00
|
|
|
# + If assimp is available system-wide we can just set UPDATE_SUBMODULES OFF
|
|
|
|
option(UPDATE_SUBMODULES "Update external project (assimp) git submodule" ON)
|
2022-08-14 22:08:06 +00:00
|
|
|
option(ASSIMP_NEW_INTERFACE "Use the assimp::assimp interface (WIN / OSX)" OFF)
|
2022-08-07 17:12:12 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# External Libraries
|
|
|
|
################################################################################
|
|
|
|
|
2022-07-17 00:11:07 +00:00
|
|
|
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
|
2022-08-14 22:08:06 +00:00
|
|
|
# + QtCreator will handle this for you if that is used instead
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
|
2022-08-07 17:12:12 +00:00
|
|
|
|
|
|
|
# Find Qt
|
2022-07-31 22:50:02 +00:00
|
|
|
find_package(Qt6 COMPONENTS OpenGLWidgets)
|
|
|
|
if (NOT Qt6_FOUND)
|
|
|
|
message(SEND_ERROR "Unable to find Qt6 at CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
|
|
|
|
message(FATAL_ERROR "Specify path to Qt6 with `cmake -DCMAKE_PREFIX_PATH=/path/to/Qt/6.x.x/gcc_64 -S /path/to/qtk -B /path/to/qtk/build && cmake --build /path/to/qtk/build -j $(nprocs)`")
|
|
|
|
endif()
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-14 22:08:06 +00:00
|
|
|
if (UPDATE_SUBMODULES)
|
|
|
|
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake")
|
|
|
|
submodule_update(extern/assimp/assimp/)
|
|
|
|
add_subdirectory(extern/assimp/assimp)
|
2022-08-14 22:17:05 +00:00
|
|
|
set(ASSIMP_DIR "${CMAKE_SOURCE_DIR}/extern/assimp/assimp/include/")
|
2022-08-14 21:02:50 +00:00
|
|
|
endif()
|
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2021-09-03 16:56:57 +00:00
|
|
|
################################################################################
|
2022-08-07 17:12:12 +00:00
|
|
|
# Qtk
|
2021-09-03 16:56:57 +00:00
|
|
|
################################################################################
|
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
set(PUBLIC_HEADERS
|
|
|
|
src/mainwidget.h
|
|
|
|
src/abstractscene.h
|
|
|
|
src/camera3d.h
|
|
|
|
src/mesh.h
|
|
|
|
src/meshrenderer.h
|
|
|
|
src/model.h
|
|
|
|
src/object.h
|
|
|
|
src/skybox.h
|
|
|
|
src/texture.h
|
|
|
|
src/transform3D.h
|
2022-03-13 22:00:00 +00:00
|
|
|
)
|
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
set(SOURCE_FILES
|
|
|
|
src/mainwidget.cpp
|
|
|
|
src/abstractscene.cpp
|
|
|
|
src/camera3d.cpp
|
|
|
|
src/input.cpp
|
|
|
|
src/input.h
|
|
|
|
src/mesh.cpp
|
|
|
|
src/meshrenderer.cpp
|
|
|
|
src/model.cpp
|
|
|
|
src/object.cpp
|
|
|
|
src/qtkapi.h
|
|
|
|
src/skybox.cpp
|
|
|
|
src/texture.cpp
|
|
|
|
src/transform3D.cpp
|
|
|
|
)
|
2022-08-14 21:02:50 +00:00
|
|
|
|
|
|
|
include(GenerateExportHeader)
|
2022-08-07 17:12:12 +00:00
|
|
|
qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES})
|
|
|
|
target_include_directories(qtk-widget PRIVATE src/ app/)
|
|
|
|
|
|
|
|
set_target_properties(qtk-widget PROPERTIES
|
|
|
|
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
)
|
|
|
|
|
2022-08-14 21:02:50 +00:00
|
|
|
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets)
|
2022-08-14 22:08:06 +00:00
|
|
|
|
2022-08-14 22:17:05 +00:00
|
|
|
if (UPDATE_SUBMODULES OR NOT ASSIMP_NEW_INTERFACE)
|
2022-08-14 22:08:06 +00:00
|
|
|
target_link_libraries(qtk-widget PRIVATE assimp)
|
|
|
|
elseif(ASSIMP_NEW_INTERFACE)
|
|
|
|
target_link_libraries(qtk-widget PRIVATE assimp::assimp)
|
|
|
|
endif()
|
2022-08-07 17:12:12 +00:00
|
|
|
|
|
|
|
if(QTK_DEBUG)
|
|
|
|
target_compile_definitions(qtk-widget PUBLIC QTK_DEBUG)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2022-08-02 02:33:33 +00:00
|
|
|
if(WIN32)
|
2022-08-07 17:12:12 +00:00
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
target_link_libraries(qtk-widget PUBLIC OpenGL::GL)
|
2022-08-02 02:33:33 +00:00
|
|
|
endif()
|
2021-09-12 16:49:59 +00:00
|
|
|
|
2022-08-14 22:17:05 +00:00
|
|
|
generate_export_header(qtk-widget)
|
2022-08-07 17:12:12 +00:00
|
|
|
# Install files
|
|
|
|
install(TARGETS qtk-widget
|
|
|
|
# Associate qtk-widget target with qtk-export
|
|
|
|
EXPORT qtk-export
|
|
|
|
# <prefix>/bin on DLL systems and <prefix>/lib on non-dll systems
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib/static
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
PUBLIC_HEADER DESTINATION include
|
|
|
|
)
|
|
|
|
|
|
|
|
# Install export
|
|
|
|
# qtkTargets.cmake will only be installed when one of the CONFIGURATIONS is installed
|
|
|
|
# + The generated import will only reference that qtk configuration
|
|
|
|
install(EXPORT qtk-export
|
|
|
|
FILE qtkTargets.cmake
|
|
|
|
CONFIGURATIONS Debug|Release
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake
|
|
|
|
)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Final Application
|
|
|
|
################################################################################
|
2022-03-07 13:20:32 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources.h "#ifndef QTK_RESOURCES_H\n#define QTK_RESOURCES_H\n#define QTK_RESOURCES_DIR \"${CMAKE_SOURCE_DIR}/resources\"\n#endif\n")
|
|
|
|
|
|
|
|
# Add our Qt resources.qrc file to our application
|
|
|
|
set(QTK_APP_SOURCES app/main.cpp
|
|
|
|
app/mainwindow.cpp app/mainwindow.h app/mainwindow.ui
|
|
|
|
app/scene.cpp app/scene.h
|
|
|
|
app/resourcemanager.cpp app/resourcemanager.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/resources.h
|
|
|
|
)
|
|
|
|
qt6_add_big_resources(QTK_APP_SOURCES resources.qrc)
|
|
|
|
|
2022-08-14 21:02:50 +00:00
|
|
|
qt_add_executable(qtk-main ${QTK_APP_SOURCES})
|
|
|
|
target_include_directories(qtk-main PRIVATE src/ app/)
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-08-14 21:02:50 +00:00
|
|
|
# Link qtk-main executable to main qtk-widget library
|
|
|
|
target_link_libraries(qtk-main PRIVATE qtk-widget)
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-08-14 21:02:50 +00:00
|
|
|
set_target_properties(qtk-main PROPERTIES
|
2022-03-07 13:20:32 +00:00
|
|
|
WIN32_EXECUTABLE TRUE
|
|
|
|
MACOSX_BUNDLE TRUE
|
2022-08-06 19:09:59 +00:00
|
|
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
|
|
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
2022-03-07 13:20:32 +00:00
|
|
|
)
|
2022-08-14 21:02:50 +00:00
|
|
|
install(TARGETS qtk-main
|
2022-08-07 17:12:12 +00:00
|
|
|
BUNDLE DESTINATION .
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
)
|
2022-03-13 22:00:00 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
if(WIN32)
|
|
|
|
get_target_property(_qt6_qmake_location Qt6::qmake IMPORTED_LOCATION)
|
|
|
|
execute_process(COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
|
|
|
|
if(TARGET Qt6::windeployqt)
|
2022-08-14 21:02:50 +00:00
|
|
|
add_custom_command(TARGET qtk-main
|
2022-08-07 17:12:12 +00:00
|
|
|
POST_BUILD
|
|
|
|
COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix}
|
2022-08-14 21:02:50 +00:00
|
|
|
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-main>/$<TARGET_FILE_NAME:qtk-main>"
|
2022-08-07 17:12:12 +00:00
|
|
|
)
|
|
|
|
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
|
|
|
|
endif()
|
|
|
|
if(MSVC AND TARGET Qt6::qmake)
|
2022-08-14 21:02:50 +00:00
|
|
|
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-main.vcxproj.user)
|
|
|
|
file(TO_NATIVE_PATH "${ASSIMP_INSTALL_DIR}/bin" assimp_bin)
|
2022-08-07 17:12:12 +00:00
|
|
|
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} " <LocalDebuggerEnvironment>Path=$(SolutionDir)\\lib\\$(Configuration);${qt6_install_prefix};${assimp_bin};$(Path)\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} "$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} " <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} " </PropertyGroup>\n")
|
|
|
|
file(APPEND ${VSUSER_FILE} "</Project>\n")
|
|
|
|
endif()
|
|
|
|
endif()
|