Skip to content

Commit

Permalink
Upgrade to 1.2.20
Browse files Browse the repository at this point in the history
- Added Wasm (WebAssembly) target.
- Fixed UI support technology for QtQuick.
- Fixed and added Qt 6.8 support.
- Fixed C++ 23/26 compiler support.
- Removed some extra config.
- Fixed some platform detection scripts.
- Some issue fixed.
  • Loading branch information
TheCompez committed Nov 25, 2024
1 parent 0a3c1a3 commit 5ccf861
Show file tree
Hide file tree
Showing 22 changed files with 1,677 additions and 234 deletions.
79 changes: 51 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
# -------------------- PROJECT TEMPLATE INFO ---------------------------------------------
# Title : Project Template
# Version : 1.1.430
# Author : Kambiz Asadzadeh
# Version : 1.2.20
# Author : Kambiz Asadzadeh (compez.eth)
# License : MIT
# Url : https://github.com/genyleap/Project-Template
# Organization : Genyleap
# ----------------------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.28)

if(${CMAKE_VERSION} VERSION_LESS 3.28)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.28)
endif()

cmake_minimum_required(VERSION 3.23)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0152 NEW)
cmake_policy(SET CMP0155 NEW)

# Add include path for cmake modules
# ------ PROJECT EXTRA CMAKE ------
Expand All @@ -28,11 +19,14 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config/")
include(ExternalProject)
include(FetchContent)

include(project)
if(project)
return()
endif()
set(project ON)
# ------ PROJECT INFO ------
# Options
set(PROJECT_NAME "PT" CACHE STRING "Project Name.") #You can change "ProjectTemplate" with your project name.
set(PROJECT_TARGET ${PROJECT_NAME} CACHE STRING "Project Target Name.")

set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 6)

# ---- Project settings ----
set_property(GLOBAL APPEND PROPERTY USE_FOLDERS ON)
Expand All @@ -42,29 +36,48 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS ON)
endif()

set(PROJECT_CREATOR "Kambiz Asadzadeh" CACHE STRING "Creator of your project.") #Your project creator.

set(PROJECT_LICENSE_TYPE "MIT" CACHE STRING "Project License Type.") #Your project license type.

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_VERSION_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

endif()
if(NOT PROJECT_VERSION_TAG)
set(PROJECT_VERSION_TAG 00000000)
endif()
set(PROJECT_VERSION_TAG_HEX 0x${PROJECT_VERSION_TAG})
set(PROJECT_VERSION_TYPE "final" CACHE STRING "Version type.")
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
set(PROJECT_VERSION_STRING ${PROJECT_VERSION}-${PROJECT_VERSION_TYPE})

# Supported languages include C, CXX (i.e. C++), CUDA, OBJC (i.e. Objective-C), OBJCXX, Fortran, HIP, ISPC, and ASM. By default C and CXX are enabled if no language options are given.
# Specify language NONE, or use the LANGUAGES keyword and list no languages, to skip enabling any languages.
set(PROJECT_LANGUAGES CXX)

#Use these keys [application, library]
set(PROJECT_USAGE_TYPE "application" CACHE STRING "Usage Type.")

#Use these keys [stl, qt, qtwidget, qtquick]
set(PROJECT_MAIN_TYPE "qtquick" CACHE STRING "Library System.")

set(DEVELOPER_BUNDLE_IDENTIFIER com.kambizasadzadeh.app.${PROJECT_NAME} CACHE STRING "Developer Bundle Identifier.")

#You can replace your project description with this string.
set(PROJECT_DESCRIPTION "A concept mobile app UI/UX prototype based on Qt Quick technology." CACHE STRING "Project Description")

#Your project website address.
set(PROJECT_HOMEPAGE_URL "https://kambizasadzadeh.com" CACHE STRING "Project URL.")

#Project pre-configuration system.
configure_file(
${PROJECT_SOURCE_DIR}config.hpp.in
Expand Down Expand Up @@ -142,10 +155,11 @@ file(GLOB HEADERS
)
file(GLOB SOURCES source/${SUFFIX_SOURCE})

file(GLOB EXAMPLES
source/examples/${SUFFIX_HPPHEADER}
source/examples/${SUFFIX_SOURCE}
)
#file(GLOB EXAMPLES
# source/examples/${SUFFIX_HPPHEADER}
# source/examples/${SUFFIX_SOURCE}
#)

file(GLOB UTILS
utilities/${SUFFIX_HPPHEADER}
utilities/${SUFFIX_SOURCE}
Expand Down Expand Up @@ -295,18 +309,21 @@ if(GUI_APPLICATION AND PROJECT_MAIN_TYPE STREQUAL "qt" OR PROJECT_MAIN_TYPE STRE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
elseif(${PROJECT_MAIN_TYPE} STREQUAL "qtquick")
list(APPEND QT_MODULES Core${SPACE_ARG})
list(APPEND QT_MODULES Quick${SPACE_ARG})
list(APPEND QT_MODULES_LINK
Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Quick
)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick)
endif()
endif()

qt_standard_project_setup(REQUIRES 6.5)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
if(PROJECT_USAGE_TYPE STREQUAL "library")
qt_add_library(${PROJECT_NAME}
Expand Down Expand Up @@ -442,3 +459,9 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/config/system-config.json DESTINATION ${CM

#Ignore unused files.
list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store)

include(InstallRequiredSystemLibraries)
set(CPACK_GENERATOR "TGZ;ZIP")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A brief description of your project")
include(CPack)
74 changes: 45 additions & 29 deletions cmake/compiler-options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_STANDARD_LIBRARIES "-lc++ -lc++abi")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_CXX_STANDARD_LIBRARIES "-lc++ -lc++abi")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("-- CMake run for msvc")
Expand Down Expand Up @@ -108,6 +105,23 @@ else()
endif()
endif()

# Enable optional features
option(ENABLE_MODULES "Enable C++20 modules" OFF)
if(ENABLE_MODULES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmodules")
add_definitions(-DENABLE_MODULES)
endif()

# Debug/Testing Modes
option(ENABLE_DEBUG_LOGGING "Enable debug logging" OFF)
option(ENABLE_TESTING "Enable testing mode" OFF)
if(ENABLE_DEBUG_LOGGING)
add_definitions(-DDEBUG_LOGGING)
endif()
if(ENABLE_TESTING)
add_definitions(-DENABLE_TESTING)
endif()

#########################
# --- Build Options --- #
#########################
Expand Down Expand Up @@ -148,12 +162,6 @@ if (SIMPLE_BUILD)
add_definitions(-DSIMPLE_BUILD)
endif()

# Enable address sanitizer
option(ENABLE_ASAN "Enable address sanitizer" OFF)
if (ENABLE_ASAN)
add_definitions(-DENABLE_ASAN)
endif()

# Build the project's documentation
option(BUILD_DOC "Build the project's documentation" OFF)
if (BUILD_DOC)
Expand Down Expand Up @@ -255,7 +263,7 @@ if (FORCE_LATEST_STANDARD_FEATURE)
endif()

# Sanitizers Options
option(ENABLE_SANITIZERS "Enable Sanitizers" ON)
option(ENABLE_SANITIZERS "Enable Sanitizers" OFF)
option(ENABLE_ADDRESS_SANITIZER "Enable AddressSanitizer (ASan)" OFF)
option(ENABLE_LEAK_SANITIZER "Enable LeakSanitizer (LSan)" OFF)
option(ENABLE_MEMORY_SANITIZER "Enable MemorySanitizer" OFF)
Expand All @@ -265,7 +273,11 @@ option(ENABLE_UNDEFINED_SANITIZER "Enable UndefinedBehaviorSanitizer" OFF)
if (ENABLE_SANITIZERS)
add_definitions(-DENABLE_SANITIZERS)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,leak,undefined")
if (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,leak,undefined")
endif()
if (ENABLE_MEMORY_SANITIZER AND NOT APPLE)
add_definitions(-DENABLE_MEMORY_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory")
Expand All @@ -289,22 +301,26 @@ if (ENABLE_SANITIZERS)
message(WARNING "Unsupported compiler. Sanitizers are disabled.")
endif()
else()
# Check and enable individual sanitizers
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
foreach(SANITIZER IN ITEMS ADDRESS LEAK MEMORY THREAD UNDEFINED)
if ("ENABLE_${SANITIZER}_SANITIZER")
add_definitions(-DENABLE_${SANITIZER}_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZER}")
endif()
endforeach()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT APPLE)
foreach(SANITIZER IN ITEMS ADDRESS LEAK MEMORY THREAD UNDEFINED)
if ("ENABLE_${SANITIZER}_SANITIZER")
add_definitions(-DENABLE_${SANITIZER}_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZER}")
endif()
endforeach()
else()
message(WARNING "Unsupported compiler. Sanitizers are disabled.")
endif()
# Check and enable individual sanitizers
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
foreach(SANITIZER IN ITEMS ADDRESS LEAK MEMORY THREAD UNDEFINED)
if ("ENABLE_${SANITIZER}_SANITIZER")
add_definitions(-DENABLE_${SANITIZER}_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZER}")
endif()
endforeach()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT APPLE)
foreach(SANITIZER IN ITEMS ADDRESS LEAK MEMORY THREAD UNDEFINED)
if ("ENABLE_${SANITIZER}_SANITIZER")
add_definitions(-DENABLE_${SANITIZER}_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZER}")
endif()
endforeach()
else()
message(WARNING "Unsupported compiler. Sanitizers are disabled.")
endif()
endif()


# Summary
message(STATUS "Final compiler flags: ${CMAKE_CXX_FLAGS}")
18 changes: 17 additions & 1 deletion cmake/cross-compile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/platforms-toolchain/")

# ------ CROSS-COMPILE CONFIG ------
if (EXISTS "${CMAKE_CXX_COMPILER}")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
OUTPUT_VARIABLE EMCC_VERSION
ERROR_VARIABLE EMCC_VERSION)
if (EMCC_VERSION MATCHES "Emscripten")
message(STATUS "Ready for Wasm...")
set(WASM TRUE)
set(PLATFORM_OS "Web")
set(OS_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR})
include(wasm-toolchain)
if(wasm-toolchain)
return()
endif()
set(wasm-toolchain ON)
endif()
endif()

#LINUX
if(LINUX AND NOT ANDROID AND NOT APPLE)
Expand Down Expand Up @@ -60,7 +76,7 @@ if(UNIX AND NOT ANDROID AND NOT LINUX AND APPLE)
endif()

#FREEBSD
if(UNIX AND NOT ANDROID AND NOT LINUX AND NOT APPLE)
if(UNIX AND NOT ANDROID AND NOT LINUX AND NOT APPLE AND NOT WASM)
message(STATUS "Ready for Unix, BSDs...")
set(UNIX TRUE)
set(PLATFORM_OS "Unix")
Expand Down
69 changes: 49 additions & 20 deletions cmake/platforms-toolchain/android-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# Standard settings
set (CMAKE_SYSTEM_NAME ANDROID)
set (CMAKE_SYSTEM_VERSION 1)
set (CMAKE_CROSSCOMPILING TRUE)
set (ANDROID TRUE)
set (PLATFORM_FOLDER "Android")
# Standard settings for Android
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21) # Android API level (can be changed to your target version)
set(CMAKE_CROSSCOMPILING TRUE)
set(ANDROID TRUE)
set(PLATFORM_FOLDER "Android")

#------ PROJECT DIRECTORIES ------
# Define base build directory for Android
set(dir ${CMAKE_CURRENT_SOURCE_DIR}/build/${PLATFORM_FOLDER})

# Set output directories for executables, libraries, and other build files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dir})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${dir}/lib)
set(CMAKE_BUILD_FILES_DIRECTORY ${dir})
set(CMAKE_BINARY_DIR ${dir})
set(CMAKE_CACHEFILE_DIR ${dir})

# Ensure all output paths are unified
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(LIBRARY_OUTPUT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

# Set NDK path (if it's not set globally, you can also set the NDK path here)
# set(ANDROID_NDK "/path/to/your/ndk") # Uncomment if needed

if(ANDROID_SDK_ROOT)
include(${ANDROID_SDK_ROOT}/android_openssl/CMakeLists.txt)
Expand All @@ -13,17 +31,28 @@ if(ANDROID_SDK)
include(${ANDROID_SDK}/android_openssl/CMakeLists.txt)
endif()

#------ PROJECT DIRECTORIES ------
set(dir ${CMAKE_CURRENT_SOURCE_DIR}/build/${PLATFORM_FOLDER})
message("Make sure that build/Android path is set manually.")
#Qt Creator cannot set android path as default base on dir.
#You shoud set custom as buid/android from QtCreator.
#set(EXECUTABLE_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
#set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dir})
#set(CMAKE_BUILD_FILES_DIRECTORY ${dir})
#set(CMAKE_BUILD_DIRECTORY ${dir})
#set(CMAKE_BINARY_DIR ${dir})
#SET(EXECUTABLE_OUTPUT_PATH ${dir})
#SET(LIBRARY_OUTPUT_PATH ${dir}/lib)
#SET(CMAKE_CACHEFILE_DIR ${dir})
# Specify the Android ABIs (Architectures) to target
set(ANDROID_ABI "arm64-v8a" CACHE STRING "Android ABI" FORCE) # You can use "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
set(ANDROID_NATIVE_API_LEVEL 21) # Android API level, the minimum required by your app

# Set Android toolchain file (you need to provide the correct path to the Android toolchain file)
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_NDK}/build/cmake/android.toolchain.cmake)

# Android-specific libraries (Android system libraries)
# You can add more libraries depending on your requirements (e.g., OpenGL, Vulkan, JNI, etc.)
set(OS_LIBS
"-landroid" # Basic Android library
"-lEGL" # OpenGL ES library
"-lGLESv2" # OpenGL ES 2.0
"-ljnigraphics" # JNI Graphics interface (useful for drawing)
"-llog" # Android log library (for logging in C++ code)
)

# Output information for debugging
message("Build directory: ${dir}")
message("CMAKE_RUNTIME_OUTPUT_DIRECTORY: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("CMAKE_LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
message("Android NDK path: ${ANDROID_NDK}")
message("Android ABI: ${ANDROID_ABI}")
message("Android API Level: ${ANDROID_NATIVE_API_LEVEL}")
message("Android Libraries: ${OS_LIBS}")
Loading

0 comments on commit 5ccf861

Please sign in to comment.