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

Add cmake for QtService #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
122 changes: 122 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.so.*
*.dll
*.dylib
*.json

# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl

# Qt unit tests
target_wrapper.*

# QtCreator
*.autosave

# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*

# QtCreator CMake
CMakeLists.txt.user*

# QtCreator 4.8< compilation database
compile_commands.json

# QtCreator local machine specific files for imported projects
*creator.user*

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Platform Specifics - auto generated files
PlatformSpecifics/Windows/*.rc

# Visual studio - project files
*.sln
*.suo
*.vcxproj
*.vcxproj.filters
*.vcxproj.user

# Visual Studio - Build Results
[Dd]ebug/
[Rr]elease/
[Mm]in[Ss]ize[Rr]el/
[Rr]el[Ww]ith[Dd]eb[Ii]nfo/
build*/

# Visual Studio - Browsing Database File
*.sdf
*.opensdf

#osx xcode
DerivedData/
*.DS_Store
*.build
*.xcodeproj

#CPACK related files
CPackConfig-*.cmake
_CPack_Packages/

#packages
*.tar.gz
*.zip

*.swp
*.*~

build_doxygen
138 changes: 138 additions & 0 deletions qtservice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Author: Kang Lin <[email protected]>

cmake_minimum_required(VERSION 3.5)

project(QtService)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "verbose")
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

# Open qt compile tool
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)

# Need qt compones
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
message("QT_VERSION:${Qt${QT_VERSION_MAJOR}_VERSION}")
get_filename_component(QT_INSTALL_DIR "${Qt${QT_VERSION_MAJOR}_DIR}/../../.." ABSOLUTE)
message("QT_INSTALL_DIR:${QT_INSTALL_DIR}")

if(POLICY CMP0083)
cmake_policy(SET CMP0083 NEW)
endif()

if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif()

SET(BUILD_VERSION "v0.0.1")
# Find Git Version Patch
IF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
if(NOT GIT)
SET(GIT $ENV{GIT})
endif()
if(NOT GIT)
FIND_PROGRAM(GIT NAMES git git.exe git.cmd)
endif()
IF(GIT)
EXECUTE_PROCESS(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GIT} describe --tags
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_VERSION)
EXECUTE_PROCESS(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GIT} rev-parse --short HEAD
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
SET(BUILD_VERSION ${GIT_VERSION})
ENDIF()
ENDIF()
message("BUILD_VERSION:${BUILD_VERSION}")
set(VERSION ${BUILD_VERSION})

if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif(NOT DEFINED CMAKE_BUILD_TYPE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
if("debug" STREQUAL build_type)
add_definitions(-D_DEBUG)
endif()

IF(MSVC)
# This option is to enable the /MP switch for Visual Studio 2005 and above compilers
OPTION(WIN32_USE_MP "Set to ON to build with the /MP option (Visual Studio 2005 and above)." ON)
MARK_AS_ADVANCED(WIN32_USE_MP)
IF(WIN32_USE_MP)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
add_compile_options(/MP)
ENDIF(WIN32_USE_MP)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
ENDIF(MSVC)

SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs")
if (BUILD_SHARED_LIBS)
add_definitions(-DBUILD_SHARED_LIBS)
if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
# Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set
# -fPIC for GCC but sometimes it still doesn't get set, so make sure it
# does.
add_definitions("-fPIC")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
else(BUILD_SHARED_LIBS)
add_definitions(-DQT_STATICPLUGIN)
endif(BUILD_SHARED_LIBS)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(GenerateExportHeader)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckFunctionExists)

#CHECK_INCLUDE_FILE_CXX("string" HAVE_STRING_H)
#check_include_file("math.h" HAVE_MATH_H)

#check_function_exists("fabs" HAVE_FABS)

set(BUILD_PLATFORM "${CMAKE_SYSTEM_NAME}")
# ----------------------------------------------------------------------------
# Detect compiler and target platform architecture
# ----------------------------------------------------------------------------
if(NOT ANDROID)
if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BUILD_ARCH x86_64)
elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
set(BUILD_ARCH x86)
endif()
else()
set(BUILD_ARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()

add_subdirectory(src)

option(BUILD_EXAMPLES "Build examples" OFF)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif(BUILD_EXAMPLES)

# Create will be delete files
CONFIGURE_FILE(
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
# Create unistall target
ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
)
12 changes: 12 additions & 0 deletions qtservice/cmake/QtService.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_PREFIX@/include

Name: @PROJECT_NAME@
Description:
Version: @BUILD_VERSION@
Requires:
Requires.private:
Libs: -L${libdir} -l@PROJECT_NAME@
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions qtservice/cmake/QtServiceConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@PACKAGE_INIT@

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/")

include(CMakeFindDependencyMacro)
#foreach(dependens_lib @QTSERVICE_DEPENDENS@)
# find_dependency(${dependens_lib})
#endforeach()

find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS @QT_COMPONENTS@)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

57 changes: 57 additions & 0 deletions qtservice/cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Author: Kang Lin([email protected])

# Use: Please add the follow code to CMakeLists.txt

# # Install runtime target
# add_custom_target(install-runtime
# COMMAND
# "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=Runtime
# -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
# )
# # Uninstall runtime target
# add_custom_target(uninstall-runtime
# COMMAND
# "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=Runtime
# -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
# )
# # Create will be delete files
# CONFIGURE_FILE(
# "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
# "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
# IMMEDIATE @ONLY)
# # Create unistall target
# ADD_CUSTOM_TARGET(uninstall
# "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
# DEPENDS uninstall-runtime)


if(CMAKE_INSTALL_COMPONENT)
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
else()
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
endif()

IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}")
MESSAGE(WARNING "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}\"")
ELSE()

FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}" files)
STRING(REGEX REPLACE "\n" ";" files "${files}")
FOREACH(file ${files})
MESSAGE(STATUS "Uninstalling \"${file}\"")
IF(EXISTS "${file}")
EXEC_PROGRAM(
"@CMAKE_COMMAND@" ARGS "-E remove \"${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
IF("${rm_retval}" STREQUAL 0)
ELSE("${rm_retval}" STREQUAL 0)
MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"")
ENDIF("${rm_retval}" STREQUAL 0)
ELSE(EXISTS "${file}")
MESSAGE(STATUS "File \"${file}\" does not exist.")
ENDIF(EXISTS "${file}")
ENDFOREACH(file)

ENDIF()
3 changes: 3 additions & 0 deletions qtservice/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(server)
add_subdirectory(controller)
add_subdirectory(interactive)
6 changes: 6 additions & 0 deletions qtservice/examples/controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Author: Kang Lin <[email protected]>

project(controller)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE QtService)
16 changes: 16 additions & 0 deletions qtservice/examples/interactive/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Author: Kang Lin <[email protected]>

project(interactive)

SET(QT_COMPONENTS Gui Widgets)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS})
if(Qt${QT_VERSION_MAJOR}_FOUND)
FOREACH(_COMPONENT ${QT_COMPONENTS})
LIST(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT})
ENDFOREACH()
endif()
message("${PROJECT_NAME} QT_LIBRARIES:${QT_LIBRARIES}")

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE QtService ${QT_LIBRARIES})
Loading