Skip to content

Commit

Permalink
Improve CMakeLists files: enable to pass QT_SDK_DIR from commandline
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Nov 18, 2023
1 parent d8d1349 commit e2c901a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 37 deletions.
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ option(BUILD_STATIC "Build QCefView as static library" OFF)
option(USE_SANDBOX "Enable CEF Sandbox" OFF)
option(STATIC_CRT "Use MultiThreaded linkage for MSVC" OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

get_directory_property(QCefView_HAS_PARENT_DIRECTORY PARENT_DIRECTORY)

# Only generate Debug and Release configuration types.
Expand Down Expand Up @@ -84,11 +86,8 @@ endif()

# Config the QT package
# ##############################################################
include(QtConfig.cmake)
message(STATUS "Qt SDK dir: " ${QT_SDK_DIR})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_SDK_DIR})
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED)
set(QT_SDK_DIR "" CACHE PATH "Qt build toolchain path")
include(QtConfig)
set(Qt_VERSION ${Qt${QT_VERSION_MAJOR}Core_VERSION})

# ##############################################################
Expand Down
24 changes: 0 additions & 24 deletions QtConfig.cmake

This file was deleted.

33 changes: 33 additions & 0 deletions cmake/QtConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ################################################################################
#
# The Qt SDK path
# You can set the evnironment varibale via
# 1. command line
# Windows: SET QTDIR=PATH/TO/QT
# Non-Windows: export QTDIR=PATH/TO/QT
# 2. modifying the value below directly
#

# Qt build toolchain path not set or doesn't exist
# try to read from environment QTDIR
if(NOT EXISTS ${QT_SDK_DIR})
message(STATUS "QT_SDK_DIR not found, try to read from environment variable: QTDIR")
set(QT_SDK_DIR "$ENV{QTDIR}" CACHE STRING "QT_SDK_DIR read from environment variable: QTDIR" FORCE)
endif()

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# You must make sure the target platform and architecture
# of QT binaries math the ones of CEF binaries
# Qt linux-x86 + CEF linux-x86
# Qt linux-x86_64 + CEF linux-x86_64
# Qt windows-x86 + CEF windows-x86
# Qt windows-x86_64 + CEF windows-x86_64
# Qt macos-x86_64 + CEF macos-x86_64
# Qt macos-arm64 + CEF macos-arm64
#

# find required components
message(STATUS " Qt SDK dir: " ${QT_SDK_DIR})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_SDK_DIR})
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED)
2 changes: 1 addition & 1 deletion generate-linux-x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ do
done

echo ============== Config project ==============
cmake -G "Unix Makefiles" -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=Release -DPROJECT_ARCH=x86 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/linux.x86"
cmake -G "Unix Makefiles" -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=Release -DPROJECT_ARCH=x86 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/linux.x86" $*

if [ ${BUILD_PROJECT} -eq 1 ]
then
Expand Down
2 changes: 1 addition & 1 deletion generate-linux-x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ do
done

echo ============== Config project ==============
cmake -G "Unix Makefiles" -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=Release -DPROJECT_ARCH=x86_64 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/linux.x86_64"
cmake -G "Unix Makefiles" -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=Release -DPROJECT_ARCH=x86_64 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/linux.x86_64" $*

if [ ${BUILD_PROJECT} -eq 1 ]
then
Expand Down
2 changes: 1 addition & 1 deletion generate-mac-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ do
done

echo ============== Config project ==============
cmake -G "Xcode" -S . -B "${BUILD_DIR}" -DPROJECT_ARCH=arm64 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/macos.arm64"
cmake -G "Xcode" -S . -B "${BUILD_DIR}" -DPROJECT_ARCH=arm64 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/macos.arm64" $*

if [ ${BUILD_PROJECT} -eq 1 ]
then
Expand Down
2 changes: 1 addition & 1 deletion generate-mac-x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ do
done

echo ============== Config project ==============
cmake -G "Xcode" -S . -B "${BUILD_DIR}" -DPROJECT_ARCH=x86_64 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/macos.x86_64"
cmake -G "Xcode" -S . -B "${BUILD_DIR}" -DPROJECT_ARCH=x86_64 -DBUILD_DEMO=ON -DUSE_SANDBOX=ON -DCMAKE_INSTALL_PREFIX:PATH="$(pwd)/out/macos.x86_64" $*

if [ ${BUILD_PROJECT} -eq 1 ]
then
Expand Down
3 changes: 2 additions & 1 deletion generate-win-arm64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ cmake -S . ^
-A ARM64 ^
-DPROJECT_ARCH=arm64 ^
-DBUILD_DEMO=ON ^
-DCMAKE_INSTALL_PREFIX:PATH="%cd%/out/windows.arm64"
-DCMAKE_INSTALL_PREFIX:PATH="%cd%/out/windows.arm64" ^
%*
3 changes: 2 additions & 1 deletion generate-win-x86.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ cmake -S . ^
-A Win32 ^
-DPROJECT_ARCH=x86 ^
-DBUILD_DEMO=ON ^
-DCMAKE_INSTALL_PREFIX:PATH="%cd%/out/windows.x86"
-DCMAKE_INSTALL_PREFIX:PATH="%cd%/out/windows.x86" ^
%*
3 changes: 2 additions & 1 deletion generate-win-x86_64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ cmake -S . ^
-A x64 ^
-DPROJECT_ARCH=x86_64 ^
-DBUILD_DEMO=ON ^
-DCMAKE_INSTALL_PREFIX:PATH="%cd%/out/windows.x86_64"
-DCMAKE_INSTALL_PREFIX:PATH="%cd%/out/windows.x86_64" ^
%*

0 comments on commit e2c901a

Please sign in to comment.