Skip to content

Commit

Permalink
Merge pull request #57 from oclero/feature/cmake-presets
Browse files Browse the repository at this point in the history
Add CMake presets
  • Loading branch information
oclero authored May 5, 2024
2 parents 59860af + 16bffc5 commit c11345a
Show file tree
Hide file tree
Showing 25 changed files with 346 additions and 226 deletions.
44 changes: 19 additions & 25 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@ name: Linux

on:
push:
branches: [ "master", "setup-ci" ]
branches:
- master
pull_request:
branches: [ "master" ]

env:
# CMake build type (Release, Debug, RelWithDebInfo, etc.).
BUILD_TYPE: Release
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check Out
# Checks out the repository.
uses: actions/checkout@v4
- name: Check Out
uses: actions/checkout@v4

- name: Install Qt
# Installs the Qt SDK.
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
host: 'linux'
target: 'desktop'
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
host: linux
target: desktop
arch: gcc_64

- name: Configure CMake
# Configures CMake in a 'build' subdirectory.
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Configure CMake
run: cmake --preset linux

- name: Builds the library.
# Builds with the given configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build the library.
run: cmake --build --preset linux

- name: Builds the Sandbox app.
# Builds the sandbox app with the given configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target sandbox
- name: Build the Sandbox app.
run: cmake --build --preset linux-sandbox
29 changes: 10 additions & 19 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,33 @@ name: MacOS

on:
push:
branches: ['master', 'setup-ci']
branches:
- master
pull_request:
branches: ['master']

env:
# CMake build type (Release, Debug, RelWithDebInfo, etc.).
BUILD_TYPE: Release
GENERATOR: Xcode
QT_VERSION: '5.15.2'
branches:
- master

jobs:
build:
runs-on: macos-13

steps:
- name: Check Out
# Checks out the repository.
uses: actions/checkout@v4

- name: Install Qt
# Installs the Qt SDK.
uses: jurplel/install-qt-action@v3
with:
version: ${{env.QT_VERSION}}
version: '5.15.2'
host: mac
target: desktop
arch: clang_64

- name: Configure CMake
# Configures CMake in a 'build' subdirectory.
run: cmake -B ${{github.workspace}}/build -G "${{env.GENERATOR}}" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=""
run: cmake --preset macos -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY="" -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE="Manual"

- name: Builds the library.
# Builds with the given configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build the library.
run: cmake --build --preset macos

- name: Builds the Sandbox app.
# Builds the sandbox app with the given configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target sandbox
- name: Build the Sandbox app.
run: cmake --build --preset macos-sandbox
46 changes: 19 additions & 27 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,33 @@ name: Windows

on:
push:
branches: [ "master", "setup-ci" ]
branches:
- master
pull_request:
branches: [ "master" ]

env:
# CMake build type (Release, Debug, RelWithDebInfo, etc.).
BUILD_TYPE: Release
GENERATOR: Visual Studio 17 2022
QT_VERSION: '5.15.2'
branches:
- master

jobs:
build:
runs-on: windows-latest

steps:
- name: Check Out
# Checks out the repository.
uses: actions/checkout@v4
- name: Check Out
uses: actions/checkout@v4

- name: Install Qt
# Installs the Qt SDK.
uses: jurplel/install-qt-action@v3
with:
version: ${{env.QT_VERSION}}
host: windows
target: desktop
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
host: windows
target: desktop
arch: win64_msvc2019_64

- name: Configure CMake
# Configures CMake in a 'build' subdirectory.
run: cmake -B ${{github.workspace}}/build -G "${{env.GENERATOR}}" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Configure CMake
run: cmake --preset windows

- name: Builds the library.
# Builds with the given configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build the library.
run: cmake --build --preset windows

- name: Builds the Sandbox app.
# Builds the sandbox app with the given configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target sandbox
- name: Build the Sandbox app.
run: cmake --build --preset windows-sandbox
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Testing/
.qt_for_python/

# Qt Creator files.
CMakeLists.txt.user
*creator.user*
*.qml.autosave
debug.log
Expand All @@ -56,3 +55,7 @@ __pycache__/

# MkDocs build files.
public/

# CMake files.
CMakeUserPresets.json
CMakeLists.txt.user
42 changes: 32 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
cmake_minimum_required(VERSION 3.17.5)

# Check for Qt version in given arguments. Fallback to Qt5.
if (NOT DEFINED QT_DEFAULT_MAJOR_VERSION)
set(QT_DEFAULT_MAJOR_VERSION 5)
endif()
message("-- Using Qt${QT_DEFAULT_MAJOR_VERSION}")
cmake_minimum_required(VERSION 3.21.0)

# Custom CMake modules.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(DeployQt)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Enable parallel build (not enabled by default on Windows).
set(CMAKE_BUILD_PARALLEL_LEVEL $ENV{NUMBER_OF_PROCESSORS})

# Set project information.
project("qlementine"
LANGUAGES CXX
VERSION 1.0.0.0
DESCRIPTION "Modern QStyle for desktop Qt applications."
)
set(PROJECT_COPYRIGHT "© Olivier Cléro, MIT License.")
set(PROJECT_NAMESPACE "oclero")

# Temporary hack to make it work with Qt6 <6.4.2 && >6.4.2
# With Qt5, it was "path/to/Qt/6.7.0/msvc2019_64/lib/cmake/Qt6",
# but with Qt6, it is now "path/to/Qt/6.7.0/msvc2019_64".
if(WIN32)
string(FIND ${CMAKE_PREFIX_PATH} "/lib/cmake/Qt6" USING_Qt6_INDEX)
if(NOT ${USING_Qt6_INDEX} EQUAL -1)
string(REPLACE "/lib/cmake/Qt6" "" ${CMAKE_PREFIX_PATH} ${CMAKE_PREFIX_PATH})
endif()
endif()

# Global flags.
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.6")

# Find Qt.
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Svg)

if(${QT_VERSION_MAJOR} STREQUAL "6")
qt_standard_project_setup()
endif()

include(DeployQt)

# The library.
add_subdirectory(lib)

# Sandbox.
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
if(${PROJECT_IS_TOP_LEVEL})
add_subdirectory(sandbox)
endif()
132 changes: 132 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "macos",
"displayName": "macOS",
"description": "Xcode project for macOS",
"generator": "Xcode",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"QT_DIR": "/opt/homebrew/opt/qt/lib/cmake/Qt5"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "windows",
"displayName": "Windows",
"description": "Visual Studio project for Windows",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"CMAKE_PREFIX_PATH": "C:/Qt/5.15.2/msvc2019_64/lib/cmake/Qt5"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "linux",
"displayName": "Linux",
"description": "Makefile for Linux",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/_build",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
}
],
"buildPresets": [
{
"name": "macos",
"displayName": "macOS",
"configurePreset": "macos",
"description": "Release build with Xcode for macOS",
"targets": ["qlementine"],
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "macos-sandbox",
"displayName": "Sandbox for macOS",
"configurePreset": "macos",
"description": "Sandbox - Release build with Xcode for macOS",
"targets": ["sandbox"],
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "windows",
"displayName": "Windows",
"configurePreset": "windows",
"description": "Release build with Visual Studio for Windows",
"targets": ["qlementine"],
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "windows-sandbox",
"displayName": "Sandbox for Windows",
"configurePreset": "windows",
"description": "Sandbox - Release build with Visual Studio for Windows",
"targets": ["sandbox"],
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "linux",
"displayName": "Linux",
"configurePreset": "linux",
"description": "Release build for Linux",
"targets": ["qlementine"],
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "linux-sandbox",
"displayName": "Sandbox for Linux",
"configurePreset": "linux",
"description": "Sandbox - Release build for Linux",
"targets": ["sandbox"],
"configuration": "Release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
}
]
}
Loading

0 comments on commit c11345a

Please sign in to comment.