Skip to content

Commit

Permalink
Merge pull request #3 from bialger/dev
Browse files Browse the repository at this point in the history
Update version
  • Loading branch information
bialger authored Sep 16, 2024
2 parents 065c72d + dbd112c commit de97cef
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)

project(
QtCMake
VERSION 0.1.0
VERSION 0.9.0
DESCRIPTION "CMake project for easy Qt connection to other CMake projects"
LANGUAGES CXX
)
Expand All @@ -29,6 +29,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
else ()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
if (WIN32)
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
endif ()
endif ()

add_subdirectory(lib)
Expand Down
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# QtCMake
A CMake project for easy Qt connection to other CMake projects
A C++ project template with Qt6 and CMake that downloads and compiles Qt.
The resulting app is an executable that can be run on a system without Qt.

The main Qt6 configuration is found in the [correspondent](lib/qt/CMakeLists.txt) CMakeLists.txt file.

> Note: Although the project has CI compilation tests, they somehow only succeed on macOS.
> I don't know why.
> I tested manually on Windows and Linux, and it works perfectly.
> Note that statically compiled Qt6 weights more than 5 GB.
> The good thing is that user does not need whole compiled Qt6 with this configuration.
## Prerequisites

* CMake
* Ninja
* Git

On Linux: most of the libraries that match `*xcb*` and `*xkb*` are required.

## How to build and run

Run the following commands from the project directory.

1. Create CMake cache

This step may take a lot of time because it downloads and compiles Qt.

```shell
cmake -S . -B cmake-build -G "Ninja" -DCMAKE_BUILD_TYPE=Release
```

2. Build executable target

```shell
cmake --build cmake-build --target QtCMake
```

3. Run executable target

* On Windows:

```shell
.\cmake-build\bin\QtCMake.exe
```

* On *nix:

```shell
./cmake-build/bin/QtCMake
```
12 changes: 9 additions & 3 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
message(STATUS "Qt6 directory: $ENV{QTDIR}")
set(QT_BIN_DIR "$ENV{QTDIR}/bin")

add_executable(${PROJECT_NAME}
main.cpp
)
if (WIN32)
add_executable(${PROJECT_NAME} WIN32
main.cpp
)
else ()
add_executable(${PROJECT_NAME}
main.cpp
)
endif ()

target_link_libraries(${PROJECT_NAME} PRIVATE qt)

0 comments on commit de97cef

Please sign in to comment.