Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to CMake and Qt6 #5

Merged
merged 11 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*
*.txt.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc

# Binaries
# --------
*.dll
*.exe

176 changes: 176 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#================= Project Setup ==========================

# CMake
cmake_minimum_required(VERSION 3.21.1)

# Project
# NOTE: DON'T USE TRAILING ZEROS IN VERSIONS
project(Stex
VERSION 0.2.0.2
LANGUAGES CXX
DESCRIPTION "A tool to pack/unpack Klei TEX format atlases"
)
set(FORMAL_NAME "Stexatlaser")
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LC)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC)

# C++
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Build augmentation
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
enable_language("RC")
endif()

# Add local modules
set(PROJ_SCRIPTS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${PROJ_SCRIPTS_PATH}/module")

# Get helper scripts
include(Stex/FetchOBCMake)
fetch_ob_cmake("9ccddf78d5eaa0d776cc55e9baabd294577808b1")

# Architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TARGET_ARCH x64)
else()
set(TARGET_ARCH x86)
endif()

#--------------Top Level Project Setup-------------

if(${PROJECT_IS_TOP_LEVEL})
message(STATUS "NOTE: ${PROJECT_NAME} is being configured as a top-level project")

# Install (override the CMake default, but not a user set value)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/out/install"
CACHE PATH "Project install path" FORCE
)
endif()

# Clean install when clean target is ran
set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES "${CMAKE_INSTALL_PREFIX}")
else()
message(STATUS "NOTE: ${PROJECT_NAME} is being configured as a sub-project")

# Keep install components out of 'all' target
set(SUB_PROJ_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()

#--------------------Setup Paths-------------------

# Cmake scripts
set(FILE_TEMPLATES_PATH "${PROJ_SCRIPTS_PATH}/file_templates")

# Package
set(PACKAGE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/out/dist")

#------------Set Global Build Rules----------------

# Versioning
include(OB/VerboseVersioning)
setup_verbose_versioning(PROJECT_VERSION_VERBOSE)

#================= Build =========================

# Import Qt
find_package(Qt6 REQUIRED COMPONENTS
Core
Gui
)

# Disable deprecated code
add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x060000)

# Fetch Qx
include(OB/FetchQx)
fetch_qx(
REF "e2053af327e27c3f5a304539c4b1243fa3c44669"
COMPONENTS
Core
Io
Xml
)

# Fetch libsquish
include(OB/FetchLibSquish)
fetch_libsquish("104") # v1.15 (tag)

# Set main target name
# Name here needs to be as unique as possible for when this project is inlcuded
# in another via FetchContent or add_subdirectory (prevent target clashes)
set(MAIN_TARGET_NAME ${PROJECT_NAME_LC}_${PROJECT_NAME_LC})

# Process source files and create target
add_subdirectory(src)

#--------------------Package Config-----------------------

# Create config file
configure_file("${FILE_TEMPLATES_PATH}/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
@ONLY
)

# Create version config file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)

#================= Install ==========================

set(TOP_LEVEL_INSTALL_COMPONENT ${PROJECT_NAME_LC})

# Install package target export
install(EXPORT ${PROJECT_NAME}Targets
CONFIGURATIONS Release
COMPONENT ${MAIN_TARGET_NAME}
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
DESTINATION cmake
${SUB_PROJ_EXCLUDE_FROM_ALL} # "EXCLUDE_FROM_ALL" if project is not top-level
)

# Install package config
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
CONFIGURATIONS Release
COMPONENT ${MAIN_TARGET_NAME}
DESTINATION cmake
${SUB_PROJ_EXCLUDE_FROM_ALL} # "EXCLUDE_FROM_ALL" if project is not top-level
)

# Install README and LICENSE
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/README.md"
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
COMPONENT ${TOP_LEVEL_INSTALL_COMPONENT}
DESTINATION .
${SUB_PROJ_EXCLUDE_FROM_ALL} # "EXCLUDE_FROM_ALL" if project is not top-level
)

#========Export For In-tree Builds =================
# For in source builds
export(EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)

#====================== CPack ==============================

set(CPACK_PACKAGE_VENDOR "oblivioncth")
set(CPACK_PACKAGE_DIRECTORY "${PACKAGE_PREFIX}")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${PROJECT_VERSION_VERBOSE}_${CMAKE_SYSTEM_NAME}_${TARGET_ARCH}")
set(CPACK_GENERATOR "ZIP")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
include(CPack)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Still, for this reason it is recommended to keep original copies of your texture
## Exit Codes
Once stex has finished executing an exit code is reported that indicates the "error status" of the program, which can be useful for recording/determining issues. The exit code can be obtained by running the application in the following manner:

start /wait CLIFp.exe [parameters]
start /wait Stex [parameters]
echo %errorlevel%

| Value | Code | Description |
Expand Down Expand Up @@ -164,9 +164,9 @@ This extension will be removed during filename assignment when unpacking an atla
This tool was written in C++ 17 targeting Windows/Debian and has the following dependencies:

**Common:**
- Qt 5.15.2
- Qxtended (my own personal Qt based library, see below)
- libsquish 1.15
- Qt6
- Qx
- libsquish

**Windows:**
- Windows 10 SDK 10.0.19041.0 or later
Expand Down
109 changes: 0 additions & 109 deletions Stexatlaser.pro

This file was deleted.

1 change: 1 addition & 0 deletions cmake/file_templates/StexConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
13 changes: 13 additions & 0 deletions cmake/module/Stex/FetchOBCMake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sets up OBCMake to be imported via git

# git_ref - Tag, branch name, or commit hash to retrieve. According to CMake docs,
# a commit hash is preferred for speed and reliability

macro(fetch_ob_cmake git_ref)
include(FetchContent)
FetchContent_Declare(OBCMake
GIT_REPOSITORY "https://github.com/oblivioncth/OBCMake"
GIT_TAG ${git_ref}
)
FetchContent_MakeAvailable(OBCMake)
endmacro()
Loading