2021-09-03 16:56:57 +00:00
|
|
|
################################################################################
|
2022-03-06 16:54:05 +00:00
|
|
|
## Project for working with OpenGL and Qt6 widgets ##
|
2023-01-02 03:26:58 +00:00
|
|
|
## ##
|
|
|
|
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
|
|
|
|
## All Content (c) 2023 Shaun Reed, all rights reserved ##
|
2021-09-03 16:56:57 +00:00
|
|
|
################################################################################
|
2022-12-18 14:19:04 +00:00
|
|
|
cmake_minimum_required(VERSION 3.23)
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
################################################################################
|
|
|
|
# Includes
|
|
|
|
################################################################################
|
|
|
|
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake")
|
2023-01-03 03:18:53 +00:00
|
|
|
include(CMakePackageConfigHelpers)
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
################################################################################
|
|
|
|
# Constants
|
|
|
|
################################################################################
|
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-11-24 22:26:53 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-14 22:17:05 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
add_compile_options(/wd4131 /wd4127)
|
|
|
|
endif()
|
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
################################################################################
|
|
|
|
# Project
|
|
|
|
################################################################################
|
|
|
|
project(
|
|
|
|
#[[NAME]] Qtk
|
|
|
|
VERSION 1.0
|
|
|
|
DESCRIPTION "An example project using QT and OpenGL"
|
|
|
|
LANGUAGES CXX C
|
2022-08-21 19:37:42 +00:00
|
|
|
)
|
2022-08-14 22:08:06 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
################################################################################
|
|
|
|
# Options
|
|
|
|
################################################################################
|
|
|
|
option(QTK_DEBUG "Enable debugger" ON)
|
|
|
|
option(QTK_UPDATE_SUBMODULES "Update external project (assimp) submodule" OFF)
|
|
|
|
option(QTK_SHARED "Build shared libraries" ON)
|
|
|
|
option(QTK_BUILD_GUI "Build the Qtk desktop application" ON)
|
2022-08-14 22:08:06 +00:00
|
|
|
|
|
|
|
# Options for bringing your own assimp installation; Otherwise not needed
|
2022-08-21 19:37:42 +00:00
|
|
|
# + If assimp is available system-wide we can just set QTK_UPDATE_SUBMODULES OFF
|
2022-08-14 22:08:06 +00:00
|
|
|
option(ASSIMP_NEW_INTERFACE "Use the assimp::assimp interface (WIN / OSX)" OFF)
|
2023-01-03 03:18:53 +00:00
|
|
|
message(STATUS "[Qtk] ASSIMP_NEW_INTERFACE=${ASSIMP_NEW_INTERFACE}")
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/" CACHE PATH "Path to Qt6")
|
|
|
|
# Qt Designer will look in different locations if WIN / Unix.
|
|
|
|
# These paths are for using Qt Designer integrated within Qt Creator.
|
|
|
|
# Standalone Qt Designer may use different paths.
|
|
|
|
if (WIN32)
|
2023-01-03 03:18:53 +00:00
|
|
|
# These paths may be different on windows. I have not tested this.
|
|
|
|
set(QT_PLUGIN_INSTALL_DIR "${QT_DIR}/Tools/QtCreator/bin/plugins/designer")
|
|
|
|
set(QT_PLUGIN_LIBRARY_DIR "${QT_DIR}/Tools/QtCreator/lib/Qt/lib")
|
2022-12-18 14:19:04 +00:00
|
|
|
else()
|
2023-01-03 03:18:53 +00:00
|
|
|
set(QT_PLUGIN_INSTALL_DIR "${QT_DIR}/Tools/QtCreator/lib/Qt/plugins/designer")
|
|
|
|
set(QT_PLUGIN_LIBRARY_DIR "${QT_DIR}/Tools/QtCreator/lib/Qt/lib")
|
2022-12-18 14:19:04 +00:00
|
|
|
endif()
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
# This should be set to your Qt6 installation directory.
|
|
|
|
set(QT_INSTALL_DIR "${QT_DIR}/6.3.1/gcc_64/" CACHE PATH "Path to Qt6 install")
|
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
|
2022-12-18 14:19:04 +00:00
|
|
|
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
set(QTK_PLUGIN_LIBRARY_DIR "${QT_PLUGIN_LIBRARY_DIR}")
|
|
|
|
set(QTK_PLUGIN_INSTALL_DIR "${QT_PLUGIN_INSTALL_DIR}")
|
2023-01-03 03:18:53 +00:00
|
|
|
message(STATUS "[Qtk] CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
|
2022-12-18 14:19:04 +00:00
|
|
|
set(QTK_RESOURCES "${CMAKE_SOURCE_DIR}/resources")
|
|
|
|
|
|
|
|
# Print all QTK options and their values.
|
|
|
|
get_cmake_property(VAR_NAMES VARIABLES)
|
|
|
|
list(FILTER VAR_NAMES INCLUDE REGEX "^QTK_.*$")
|
|
|
|
list(SORT VAR_NAMES)
|
|
|
|
foreach(VAR_NAME ${VAR_NAMES})
|
|
|
|
message(STATUS "[Qtk] ${VAR_NAME}=${${VAR_NAME}}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# External Dependencies
|
|
|
|
################################################################################
|
2022-08-07 17:12:12 +00:00
|
|
|
# Find Qt
|
2022-12-18 14:19:04 +00:00
|
|
|
find_package(Qt6 COMPONENTS Core UiPlugin OpenGLWidgets)
|
2022-11-26 18:24:38 +00:00
|
|
|
if(NOT Qt6_FOUND)
|
2023-01-03 03:18:53 +00:00
|
|
|
message(
|
|
|
|
SEND_ERROR "[Qtk] Error: Unable to find Qt6 at CMAKE_PREFIX_PATH: "
|
2022-08-21 19:37:42 +00:00
|
|
|
"${CMAKE_PREFIX_PATH}"
|
|
|
|
)
|
2023-01-03 03:18:53 +00:00
|
|
|
message(
|
|
|
|
FATAL_ERROR "[Qtk] Error: Specify path to Qt6 with `cmake "
|
2022-08-21 19:37:42 +00:00
|
|
|
"-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)`"
|
|
|
|
)
|
2022-07-31 22:50:02 +00:00
|
|
|
endif()
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
# Find Assimp
|
2022-11-26 18:24:38 +00:00
|
|
|
if(QTK_UPDATE_SUBMODULES)
|
2022-08-21 19:37:42 +00:00
|
|
|
message(STATUS "[Qtk] Updating submodules...")
|
|
|
|
submodule_update("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/")
|
|
|
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/")
|
|
|
|
else()
|
|
|
|
find_package(assimp REQUIRED)
|
2022-08-14 21:02:50 +00:00
|
|
|
endif()
|
|
|
|
|
2022-08-02 02:33:33 +00:00
|
|
|
if(WIN32)
|
2022-08-07 17:12:12 +00:00
|
|
|
find_package(OpenGL REQUIRED)
|
2022-08-02 02:33:33 +00:00
|
|
|
endif()
|
2021-09-12 16:49:59 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
################################################################################
|
2022-12-18 14:19:04 +00:00
|
|
|
# Qtk
|
2022-08-07 17:12:12 +00:00
|
|
|
################################################################################
|
2022-12-18 14:19:04 +00:00
|
|
|
add_subdirectory(src)
|
2022-03-07 13:20:32 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
if(WIN32)
|
|
|
|
get_target_property(_qt6_qmake_location Qt6::qmake IMPORTED_LOCATION)
|
2023-01-03 03:18:53 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX
|
2022-12-18 14:19:04 +00:00
|
|
|
RESULT_VARIABLE return_code
|
|
|
|
OUTPUT_VARIABLE qt6_install_prefix
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2022-08-07 17:12:12 +00:00
|
|
|
file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
|
2022-12-18 14:19:04 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
if(TARGET Qt6::windeployqt)
|
2023-01-03 03:18:53 +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-11-26 18:24:38 +00:00
|
|
|
)
|
2022-08-07 17:12:12 +00:00
|
|
|
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
|
|
|
|
endif()
|
2022-12-18 14:19:04 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
if(MSVC AND TARGET Qt6::qmake)
|
2023-01-03 03:18:53 +00:00
|
|
|
set(VSUSER_FILE "${CMAKE_CURRENT_BINARY_DIR}/qtk-main.vcxproj.user")
|
2022-08-14 22:17:05 +00:00
|
|
|
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/extern/assimp/assimp/bin" assimp_bin)
|
2022-11-26 18:24:38 +00:00
|
|
|
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
2022-08-07 17:12:12 +00:00
|
|
|
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()
|
2022-12-18 14:19:04 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
endif()
|