From 48719412f2de84d6356ec6a1f12a1d856fa95d7c Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Mon, 16 Jan 2023 19:34:50 -0500 Subject: [PATCH] CMake updates --- CMakeLists.txt | 9 ++++++++- cmake/templates/Config.cmake.in | 2 +- example-app/CMakeLists.txt | 15 ++++++++------- src/CMakeLists.txt | 31 ++++++++++++++++++------------- src/app/CMakeLists.txt | 21 +++++++++++++++------ src/qtk/CMakeLists.txt | 10 ++++------ 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed50387..5fae330 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ project( ################################################################################ option(QTK_DEBUG "Enable debugger" ON) option(QTK_BUILD_GUI "Build the Qtk desktop application" ON) -option(QTK_BUILD_EXAMPLE "Build the Qtk example desktop application" OFF) +option(QTK_BUILD_EXAMPLE "Build the Qtk example desktop application" ON) option(QTK_UPDATE_SUBMODULES "Update external project (assimp) submodule" OFF) # Install Qtk for use within Qt Creator projects only, instead of system-wide. option(QTK_PREFIX_QTCREATOR "Install Qtk to Qt Creator." OFF) @@ -119,6 +119,7 @@ endif() set(ASSIMP_BUILD_TESTS OFF) if(QTK_UPDATE_SUBMODULES) message(STATUS "[Qtk] Updating submodules...") + set(ASSIMP_INSTALL OFF) submodule_update("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/") else() @@ -133,3 +134,9 @@ endif() # Qtk ################################################################################ add_subdirectory(src) + +if(QTK_BUILD_EXAMPLE) + # Create a namespaced alias for linking with qtk_library in the example. + add_library(${PROJECT_NAME}::qtk_library ALIAS qtk_library) + add_subdirectory(example-app) +endif() diff --git a/cmake/templates/Config.cmake.in b/cmake/templates/Config.cmake.in index 28d9c72..4440982 100644 --- a/cmake/templates/Config.cmake.in +++ b/cmake/templates/Config.cmake.in @@ -2,7 +2,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/QtkTargets.cmake") -set_and_check(QTK_EXECUTABLE "${PACKAGE_PREFIX_DIR}/bin/qtk-main") +set_and_check(QTK_EXECUTABLE "${PACKAGE_PREFIX_DIR}/bin/qtk_main") set_and_check(QTK_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") set_and_check(QTK_LIBRARIES "${PACKAGE_PREFIX_DIR}/lib") diff --git a/example-app/CMakeLists.txt b/example-app/CMakeLists.txt index 7f97138..f708792 100644 --- a/example-app/CMakeLists.txt +++ b/example-app/CMakeLists.txt @@ -25,11 +25,7 @@ endif() set(QTK_PATH /usr/local CACHE PATH "Path to installation of Qtk") # If you did not install Qt6 on a system path, point cmake to installation. -set( - QT_INSTALL_DIR - "/home/kapper/Code/Clones/Qt/6.3.1/gcc_64/" - CACHE PATH "Path to Qt6 install" -) +set(QT_INSTALL_DIR "$ENV{HOME}/Qt/6.5.0/gcc_64/" CACHE PATH "Path to Qt6") ################################################################################ # Project @@ -43,7 +39,12 @@ project( list(APPEND CMAKE_PREFIX_PATH "${QTK_PATH}") list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}") -find_package(Qtk 0.2 REQUIRED) + +# Allow add_subdirectory on this project to use target ALIAS if available. +# If this example project is opened standalone we will use find_package. +if(NOT TARGET Qtk::qtk_library) + find_package(Qtk 0.2 REQUIRED) +endif() # Print all QTK variables get_cmake_property(VAR_NAMES VARIABLES) @@ -64,4 +65,4 @@ set( add_executable(example ${EXAMPLE_SOURCES}) target_link_libraries(example PUBLIC Qt6::Widgets Qt6::OpenGLWidgets Qt6::Core) -target_link_libraries(example PUBLIC Qtk::qtk-library) +target_link_libraries(example PUBLIC Qtk::qtk_library) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1f4b93..50fa8ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,25 +14,25 @@ if (QTK_BUILD_GUI) endif() write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/QtkConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY AnyNewerVersion ) configure_package_config_file( "${CMAKE_SOURCE_DIR}/cmake/templates/Config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/QtkConfig.cmake" - INSTALL_DESTINATION lib/cmake/Qtk + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION lib/cmake/${PROJECT_NAME} ) install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/QtkConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/QtkConfigVersion.cmake" - DESTINATION lib/cmake/Qtk + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION lib/cmake/${PROJECT_NAME} ) install( EXPORT qtk_export - FILE QtkTargets.cmake - NAMESPACE Qtk:: - DESTINATION lib/cmake/Qtk + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION lib/cmake/${PROJECT_NAME} ) set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") @@ -41,19 +41,24 @@ set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_VENDOR "Shaun Reed") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Qt OpenGL 3D graphics library.") set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/shaunrd0/qtk") -set(CPACK_SOURCE_IGNORE_FILES build;install;\.git;\.github;\.idea) +set(CPACK_SOURCE_IGNORE_FILES build*;install;\.git;\.github;\.idea) set(CPACK_PACKAGE_DIRECTORY packages/) set(CPACK_PACKAGE_CONTACT "shaunreed.com") -# TODO: This works for debian packages but the script installs to the wrong dir. +set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/resources/icon.png") +set(CPACK_THREADS 0) + +# Debian +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PACKAGE_HOMEPAGE_URL}) set(CPACK_INSTALL_SCRIPTS ${QTK_DEPLOY_SCRIPT}) # OSX -set(CPACK_BUNDLE_NAME Qtk) -set(CPACK_BUNDLE_PLIST ${CMAKE_BINARY_DIR}/bin/qtk_main.app/Contents/Info.plist) +set(CPACK_BUNDLE_NAME ${PROJECT_NAME}) +set(CPACK_BUNDLE_PLIST $/Info.plist) set(CPACK_BUNDLE_ICON ${QTK_OSX_ICONS}) if(WIN32) set(CPACK_SOURCE_GENERATOR ZIP) else() set(CPACK_SOURCE_GENERATOR TGZ) endif() + include(CPack) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 82661d5..caa2da4 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -33,18 +33,18 @@ target_link_libraries(qtk_plugin_library PUBLIC Qt6::UiPlugin qtk_library) install( TARGETS qtk_plugin_library - BUNDLE DESTINATION lib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static RUNTIME DESTINATION bin ) +# Install plugin library to Qt Creator for Designer plugin integration. install( TARGETS qtk_plugin_library - BUNDLE DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" + EXCLUDE_FROM_ALL LIBRARY DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" - RUNTIME DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" ARCHIVE DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" + RUNTIME DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" ) ################################################################################ @@ -61,9 +61,17 @@ target_link_libraries(qtk_collection PUBLIC qtk_plugin_library) install( TARGETS qtk_collection - RUNTIME DESTINATION "${QTK_PLUGIN_INSTALL_DIR}" - BUNDLE DESTINATION "${QTK_PLUGIN_INSTALL_DIR}" + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static + RUNTIME DESTINATION bin +) + +install( + TARGETS qtk_collection + EXCLUDE_FROM_ALL LIBRARY DESTINATION "${QTK_PLUGIN_INSTALL_DIR}" + ARCHIVE DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" + RUNTIME DESTINATION "${QTK_PLUGIN_INSTALL_DIR}" ) ################################################################################ @@ -103,8 +111,9 @@ set_target_properties( install( TARGETS qtk_main BUNDLE DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static RUNTIME DESTINATION bin - LIBRARY DESTINATION bin/lib ) qt_generate_deploy_app_script( diff --git a/src/qtk/CMakeLists.txt b/src/qtk/CMakeLists.txt index e3f42ac..e9558c5 100644 --- a/src/qtk/CMakeLists.txt +++ b/src/qtk/CMakeLists.txt @@ -49,7 +49,8 @@ target_sources(qtk_library PRIVATE ${QTK_LIBRARY_SOURCES}) target_sources( qtk_library PUBLIC FILE_SET HEADERS - BASE_DIRS "${CMAKE_SOURCE_DIR}/src" + BASE_DIRS $ + BASE_DIRS $ FILES ${QTK_LIBRARY_PUBLIC_HEADERS} ) @@ -59,8 +60,6 @@ endif() set_target_properties( qtk_library PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE VERSION ${PROJECT_VERSION} ) @@ -85,17 +84,16 @@ install( # Associate qtk_library target with qtk-export EXPORT qtk_export FILE_SET HEADERS DESTINATION include - BUNDLE DESTINATION lib + INCLUDES DESTINATION include LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static RUNTIME DESTINATION bin - INCLUDES DESTINATION include ) ## Install qtk_library to Qt Designer to support widget plugins. install( TARGETS qtk_library - BUNDLE DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" + EXCLUDE_FROM_ALL LIBRARY DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" ARCHIVE DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}" RUNTIME DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}"