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-03-12 02:02:26 +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
|
|
|
################################################################################
|
2023-03-12 02:02:26 +00:00
|
|
|
cmake_minimum_required(VERSION 3.23)
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2023-03-12 02:02:26 +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)
|
2023-03-12 02:02:26 +00:00
|
|
|
set(CMAKE_MACOSX_BUNDLE ON)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
if(WIN32)
|
|
|
|
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
|
2022-08-14 22:17:05 +00:00
|
|
|
add_compile_options(/wd4131 /wd4127)
|
|
|
|
endif()
|
2023-03-12 02:02:26 +00:00
|
|
|
add_compile_options(-fPIC)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Project
|
|
|
|
################################################################################
|
|
|
|
project(
|
|
|
|
#[[NAME]] Qtk
|
|
|
|
VERSION 0.2
|
|
|
|
DESCRIPTION "Qt OpenGL library and desktop application."
|
|
|
|
LANGUAGES CXX C
|
2022-08-21 19:37:42 +00:00
|
|
|
)
|
2022-08-14 22:08:06 +00:00
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
################################################################################
|
|
|
|
# Includes
|
|
|
|
################################################################################
|
|
|
|
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake")
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Options
|
|
|
|
################################################################################
|
|
|
|
option(QTK_DEBUG "Enable debugger" OFF)
|
2023-12-27 19:36:47 +00:00
|
|
|
option(QTK_SUBMODULES "Update external project (assimp) submodule" OFF)
|
|
|
|
option(QTK_GUI "Build the Qtk desktop application" ON)
|
|
|
|
option(QTK_PLUGINS "Install Qtk plugins to Qt Creator path." OFF)
|
|
|
|
option(QTK_EXAMPLE "Build the Qtk example desktop application" ON)
|
|
|
|
option(QTK_CCACHE "Enable ccache" ON)
|
|
|
|
|
|
|
|
if (QTK_CCACHE)
|
2023-03-12 02:02:26 +00:00
|
|
|
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Install Qtk for use within Qt Creator projects only, instead of system-wide.
|
|
|
|
option(QTK_PREFIX_QTCREATOR "Install Qtk to Qt Creator. Untested." OFF)
|
2022-08-14 22:08:06 +00:00
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
# Option for bringing your own assimp installation; Otherwise not needed
|
2023-12-27 19:36:47 +00:00
|
|
|
# + If assimp is available system-wide we can just set QTK_SUBMODULES OFF
|
2023-03-12 02:02:26 +00:00
|
|
|
option(
|
|
|
|
QTK_ASSIMP_NEW_INTERFACE
|
|
|
|
"Use the assimp::assimp interface (WIN / OSX)"
|
|
|
|
OFF
|
2022-08-21 19:37:42 +00:00
|
|
|
)
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2023-12-27 19:36:47 +00:00
|
|
|
if(QTK_DEBUG OR CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$")
|
|
|
|
set(QTK_DEBUG ON)
|
2023-03-12 02:02:26 +00:00
|
|
|
set(CMAKE_BUILD_TYPE Debug)
|
2023-12-27 19:36:47 +00:00
|
|
|
else()
|
|
|
|
set(QTK_DEBUG OFF)
|
|
|
|
set(CMAKE_BUILD_TYPE Release)
|
2023-03-12 02:02:26 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# This should be set to your Qt6 installation directory.
|
2023-12-27 19:36:47 +00:00
|
|
|
set(QT_INSTALL_DIR "$ENV{HOME}/Qt/6.5.0/gcc_64/lib/cmake" CACHE PATH "Path to Qt6 install.")
|
|
|
|
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|
|
|
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
set(QTK_RESOURCES "${CMAKE_SOURCE_DIR}/resources")
|
|
|
|
set(QTK_OSX_ICONS ${CMAKE_SOURCE_DIR}/resources/icons/osx/kilroy.icns)
|
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
# Point CMAKE_PREFIX_PATH to Qt6 install directory
|
|
|
|
# If Qtk is built within Qt Creator this is not required.
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
|
|
|
|
if (QTK_PREFIX_QTCREATOR)
|
|
|
|
# TODO: This might be a bit strange and needs more testing.
|
|
|
|
set(CMAKE_INSTALL_PREFIX "${QT_INSTALL_DIR}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(
|
|
|
|
QT_CREATOR_DIR
|
|
|
|
"${QT_INSTALL_DIR}/../../Tools/QtCreator"
|
|
|
|
CACHE PATH "Qt Creator path used to install Qtk plugins for Qt Designer."
|
|
|
|
)
|
|
|
|
|
2023-12-27 19:36:47 +00:00
|
|
|
# Print all QTK options and their values at the end of configuration.
|
|
|
|
# We initialize this list here so that we can append to it as needed.
|
|
|
|
# All variables in this list will be printed at the end of configuration.
|
2023-03-12 02:02:26 +00:00
|
|
|
get_cmake_property(VAR_NAMES VARIABLES)
|
2023-12-27 19:36:47 +00:00
|
|
|
list(FILTER VAR_NAMES INCLUDE REGEX "^[qQ][tT][kK]_.*$")
|
2023-03-12 02:02:26 +00:00
|
|
|
list(SORT VAR_NAMES)
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
################################################################################
|
|
|
|
# External Dependencies
|
|
|
|
################################################################################
|
2022-08-07 17:12:12 +00:00
|
|
|
# Find Qt
|
2023-03-12 02:02:26 +00:00
|
|
|
find_package(Qt6 COMPONENTS Core UiPlugin OpenGLWidgets)
|
|
|
|
qt_standard_project_setup()
|
2022-11-26 18:24:38 +00:00
|
|
|
if(NOT Qt6_FOUND)
|
2022-08-21 19:37:42 +00:00
|
|
|
message(
|
|
|
|
SEND_ERROR "[Qtk] Error: Unable to find Qt6 at CMAKE_PREFIX_PATH: "
|
|
|
|
"${CMAKE_PREFIX_PATH}"
|
|
|
|
)
|
|
|
|
message(
|
2023-03-12 02:02:26 +00:00
|
|
|
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
|
|
|
|
2023-12-27 19:36:47 +00:00
|
|
|
#
|
|
|
|
# To use custom plugins, set QT_PLUGIN_PATH environment variable before running designer
|
|
|
|
# Or, we can install plugins to the designer for use across all projects.
|
|
|
|
# Qt Creator on linux will look here for widget plugins in the integrated designer
|
|
|
|
# /home/shaun/Qt/Tools/QtCreator/lib/Qt/lib
|
|
|
|
# Qt Designer will use the following path on linux
|
|
|
|
# /home/shaun/Qt/6.5.0/gcc_64/plugins/designer/
|
|
|
|
# We can use this path after find_package(Qt6) to install our plugins on all systems
|
|
|
|
# ${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}/designer
|
|
|
|
# And run designer at ${QT6_INSTALL_PREFIX}/bin/designer
|
|
|
|
# Use cmake -DQTK_PLUGIN_INSTALL_DIR=/some/path to override this install path
|
|
|
|
set(
|
|
|
|
QTK_PLUGIN_INSTALL_DIR
|
|
|
|
"${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}/designer" CACHE PATH
|
|
|
|
"Path to install Qtk plugin collection."
|
|
|
|
)
|
|
|
|
# See cmake configure output for values of these variables on your system
|
|
|
|
set(
|
|
|
|
VAR_PATHS
|
|
|
|
CMAKE_PREFIX_PATH CMAKE_INSTALL_PREFIX QTK_PLUGIN_INSTALL_DIR QT6_INSTALL_PREFIX
|
|
|
|
QT_INSTALL_DIR
|
|
|
|
)
|
|
|
|
# Add QT6_INSTALL_PLUGINS to VAR_NAMES so it is printed at end of configuration.
|
|
|
|
list(APPEND VAR_NAMES QT6_INSTALL_PLUGINS)
|
|
|
|
|
2023-03-12 02:02:26 +00:00
|
|
|
# Find Assimp.
|
2023-12-27 19:36:47 +00:00
|
|
|
if(QTK_SUBMODULES)
|
2023-03-12 02:02:26 +00:00
|
|
|
# Required to statically link.
|
|
|
|
add_compile_options(-fPIC)
|
|
|
|
set(BUILD_SHARED_LIBS OFF CACHE STRING "Build static assimp libs" FORCE)
|
|
|
|
set(ASSIMP_BUILD_ZLIB ON CACHE STRING "Build Zlib with assimp." FORCE)
|
|
|
|
set(
|
|
|
|
ASSIMP_INSTALL
|
|
|
|
OFF CACHE STRING "Disable to use assimp as a submodule."
|
|
|
|
FORCE
|
|
|
|
)
|
|
|
|
set(ASSIMP_NO_EXPORT ON CACHE STRING "Disable to export assimp." FORCE)
|
|
|
|
set(ASSIMP_WARNINGS_AS_ERRORS OFF CACHE STRING "No warnings as errors." FORCE)
|
|
|
|
set(ASSIMP_BUILD_TESTS OFF CACHE STRING "Do not build assimp tests." FORCE)
|
2022-08-21 19:37:42 +00:00
|
|
|
message(STATUS "[Qtk] Updating submodules...")
|
|
|
|
submodule_update("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/")
|
2023-03-12 02:02:26 +00:00
|
|
|
add_subdirectory(
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/"
|
|
|
|
EXCLUDE_FROM_ALL
|
|
|
|
)
|
2022-08-21 19:37:42 +00:00
|
|
|
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
|
|
|
################################################################################
|
2023-03-12 02:02:26 +00:00
|
|
|
# Qtk
|
2022-08-07 17:12:12 +00:00
|
|
|
################################################################################
|
2023-03-12 02:02:26 +00:00
|
|
|
add_subdirectory(src)
|
2022-03-07 13:20:32 +00:00
|
|
|
|
2023-12-27 19:36:47 +00:00
|
|
|
if(QTK_EXAMPLE)
|
2023-03-12 02:02:26 +00:00
|
|
|
# Create a namespaced alias for linking with qtk_library in the example.
|
|
|
|
add_library(${PROJECT_NAME}::qtk_library ALIAS qtk_library)
|
2023-12-27 19:36:47 +00:00
|
|
|
add_subdirectory(example-app EXCLUDE_FROM_ALL)
|
2022-08-07 17:12:12 +00:00
|
|
|
endif()
|
2023-12-27 19:36:47 +00:00
|
|
|
|
|
|
|
# Print all QTK options and their values at the end of configuration. This also
|
|
|
|
# prints any additional variables that we have added to VAR_NAMES and VAR_PATHS.
|
|
|
|
foreach(VAR_NAME IN LISTS VAR_NAMES VAR_PATHS)
|
|
|
|
if(VAR_NAME IN_LIST VAR_PATHS)
|
|
|
|
# Print absolute if variable is path
|
|
|
|
get_filename_component(VAR_REALPATH "${${VAR_NAME}}" REALPATH)
|
|
|
|
message(STATUS "[Qtk] ${VAR_NAME}=${VAR_REALPATH}")
|
|
|
|
else()
|
|
|
|
message(STATUS "[Qtk] ${VAR_NAME}=${${VAR_NAME}}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|