Skip to content

Commit 75622fc

Browse files
committed
QtService: add cmake
Change-Id: Icb8ce9458340d2dcc2f65bafa07ca282420751e4
1 parent 11730d4 commit 75622fc

File tree

10 files changed

+508
-0
lines changed

10 files changed

+508
-0
lines changed

.gitignore

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# C++ objects and libs
2+
*.slo
3+
*.lo
4+
*.o
5+
*.a
6+
*.la
7+
*.lai
8+
*.so
9+
*.so.*
10+
*.dll
11+
*.dylib
12+
*.json
13+
14+
# Qt-es
15+
object_script.*.Release
16+
object_script.*.Debug
17+
*_plugin_import.cpp
18+
/.qmake.cache
19+
/.qmake.stash
20+
*.pro.user
21+
*.pro.user.*
22+
*.qbs.user
23+
*.qbs.user.*
24+
*.moc
25+
moc_*.cpp
26+
moc_*.h
27+
qrc_*.cpp
28+
ui_*.h
29+
*.qmlc
30+
*.jsc
31+
Makefile*
32+
*build-*
33+
*.qm
34+
*.prl
35+
36+
# Qt unit tests
37+
target_wrapper.*
38+
39+
# QtCreator
40+
*.autosave
41+
42+
# QtCreator Qml
43+
*.qmlproject.user
44+
*.qmlproject.user.*
45+
46+
# QtCreator CMake
47+
CMakeLists.txt.user*
48+
49+
# QtCreator 4.8< compilation database
50+
compile_commands.json
51+
52+
# QtCreator local machine specific files for imported projects
53+
*creator.user*
54+
55+
# Compiled Object files
56+
*.slo
57+
*.lo
58+
*.o
59+
*.obj
60+
61+
# Precompiled Headers
62+
*.gch
63+
*.pch
64+
65+
# Compiled Dynamic libraries
66+
*.so
67+
*.dylib
68+
*.dll
69+
70+
# Fortran module files
71+
*.mod
72+
73+
# Compiled Static libraries
74+
*.lai
75+
*.la
76+
*.a
77+
*.lib
78+
79+
# Executables
80+
*.exe
81+
*.out
82+
*.app
83+
84+
# Platform Specifics - auto generated files
85+
PlatformSpecifics/Windows/*.rc
86+
87+
# Visual studio - project files
88+
*.sln
89+
*.suo
90+
*.vcxproj
91+
*.vcxproj.filters
92+
*.vcxproj.user
93+
94+
# Visual Studio - Build Results
95+
[Dd]ebug/
96+
[Rr]elease/
97+
[Mm]in[Ss]ize[Rr]el/
98+
[Rr]el[Ww]ith[Dd]eb[Ii]nfo/
99+
build*/
100+
101+
# Visual Studio - Browsing Database File
102+
*.sdf
103+
*.opensdf
104+
105+
#osx xcode
106+
DerivedData/
107+
*.DS_Store
108+
*.build
109+
*.xcodeproj
110+
111+
#CPACK related files
112+
CPackConfig-*.cmake
113+
_CPack_Packages/
114+
115+
#packages
116+
*.tar.gz
117+
*.zip
118+
119+
*.swp
120+
*.*~
121+
122+
build_doxygen

qtservice/CMakeLists.txt

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Author: Kang Lin <kl222@126.com>
2+
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
project(QtService)
6+
7+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
8+
#set(CMAKE_CXX_STANDARD 11)
9+
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "verbose")
11+
if(CMAKE_VERSION VERSION_LESS "3.7.0")
12+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
13+
endif()
14+
15+
# Open qt compile tool
16+
SET(CMAKE_AUTOUIC ON)
17+
SET(CMAKE_AUTOMOC ON)
18+
SET(CMAKE_AUTORCC ON)
19+
20+
# Need qt compones
21+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
22+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
23+
message("QT_VERSION:${Qt${QT_VERSION_MAJOR}_VERSION}")
24+
get_filename_component(QT_INSTALL_DIR "${Qt${QT_VERSION_MAJOR}_DIR}/../../.." ABSOLUTE)
25+
message("QT_INSTALL_DIR:${QT_INSTALL_DIR}")
26+
27+
if(POLICY CMP0083)
28+
cmake_policy(SET CMP0083 NEW)
29+
endif()
30+
31+
if(POLICY CMP0020)
32+
cmake_policy(SET CMP0020 NEW)
33+
endif()
34+
35+
SET(BUILD_VERSION "v0.0.1")
36+
# Find Git Version Patch
37+
IF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
38+
if(NOT GIT)
39+
SET(GIT $ENV{GIT})
40+
endif()
41+
if(NOT GIT)
42+
FIND_PROGRAM(GIT NAMES git git.exe git.cmd)
43+
endif()
44+
IF(GIT)
45+
EXECUTE_PROCESS(
46+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
47+
COMMAND ${GIT} describe --tags
48+
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
49+
)
50+
if(NOT GIT_VERSION)
51+
EXECUTE_PROCESS(
52+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
53+
COMMAND ${GIT} rev-parse --short HEAD
54+
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
55+
)
56+
endif()
57+
SET(BUILD_VERSION ${GIT_VERSION})
58+
ENDIF()
59+
ENDIF()
60+
message("BUILD_VERSION:${BUILD_VERSION}")
61+
set(VERSION ${BUILD_VERSION})
62+
63+
if(NOT DEFINED CMAKE_BUILD_TYPE)
64+
set(CMAKE_BUILD_TYPE "Release")
65+
endif(NOT DEFINED CMAKE_BUILD_TYPE)
66+
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
67+
if("debug" STREQUAL build_type)
68+
add_definitions(-D_DEBUG)
69+
endif()
70+
71+
IF(MSVC)
72+
# This option is to enable the /MP switch for Visual Studio 2005 and above compilers
73+
OPTION(WIN32_USE_MP "Set to ON to build with the /MP option (Visual Studio 2005 and above)." ON)
74+
MARK_AS_ADVANCED(WIN32_USE_MP)
75+
IF(WIN32_USE_MP)
76+
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
77+
add_compile_options(/MP)
78+
ENDIF(WIN32_USE_MP)
79+
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
80+
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
81+
ENDIF(MSVC)
82+
83+
SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs")
84+
if (BUILD_SHARED_LIBS)
85+
add_definitions(-DBUILD_SHARED_LIBS)
86+
if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
87+
# Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set
88+
# -fPIC for GCC but sometimes it still doesn't get set, so make sure it
89+
# does.
90+
add_definitions("-fPIC")
91+
endif()
92+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
93+
else(BUILD_SHARED_LIBS)
94+
add_definitions(-DQT_STATICPLUGIN)
95+
endif(BUILD_SHARED_LIBS)
96+
97+
include(CMakePackageConfigHelpers)
98+
include(GNUInstallDirs)
99+
include(GenerateExportHeader)
100+
include(CheckIncludeFile)
101+
include(CheckIncludeFileCXX)
102+
include(CheckFunctionExists)
103+
104+
#CHECK_INCLUDE_FILE_CXX("string" HAVE_STRING_H)
105+
#check_include_file("math.h" HAVE_MATH_H)
106+
107+
#check_function_exists("fabs" HAVE_FABS)
108+
109+
set(BUILD_PLATFORM "${CMAKE_SYSTEM_NAME}")
110+
# ----------------------------------------------------------------------------
111+
# Detect compiler and target platform architecture
112+
# ----------------------------------------------------------------------------
113+
if(NOT ANDROID)
114+
if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
115+
set(BUILD_ARCH x86_64)
116+
elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
117+
set(BUILD_ARCH x86)
118+
endif()
119+
else()
120+
set(BUILD_ARCH ${CMAKE_SYSTEM_PROCESSOR})
121+
endif()
122+
123+
add_subdirectory(src)
124+
125+
option(BUILD_EXAMPLES "Build examples" OFF)
126+
if(BUILD_EXAMPLES)
127+
add_subdirectory(examples)
128+
endif(BUILD_EXAMPLES)
129+
130+
# Create will be delete files
131+
CONFIGURE_FILE(
132+
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
133+
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
134+
IMMEDIATE @ONLY)
135+
# Create unistall target
136+
ADD_CUSTOM_TARGET(uninstall
137+
"${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
138+
)

qtservice/cmake/QtService.pc.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
exec_prefix=@CMAKE_INSTALL_PREFIX@
3+
libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@
4+
includedir=@CMAKE_INSTALL_PREFIX@/include
5+
6+
Name: @PROJECT_NAME@
7+
Description:
8+
Version: @BUILD_VERSION@
9+
Requires:
10+
Requires.private:
11+
Libs: -L${libdir} -l@PROJECT_NAME@
12+
Cflags: -I${includedir}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@PACKAGE_INIT@
2+
3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/")
4+
5+
include(CMakeFindDependencyMacro)
6+
#foreach(dependens_lib @QTSERVICE_DEPENDENS@)
7+
# find_dependency(${dependens_lib})
8+
#endforeach()
9+
10+
find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS @QT_COMPONENTS@)
11+
12+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
13+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Author: Kang Lin(kl222@126.com)
2+
3+
# Use: Please add the follow code to CMakeLists.txt
4+
5+
# # Install runtime target
6+
# add_custom_target(install-runtime
7+
# COMMAND
8+
# "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=Runtime
9+
# -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
10+
# )
11+
# # Uninstall runtime target
12+
# add_custom_target(uninstall-runtime
13+
# COMMAND
14+
# "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=Runtime
15+
# -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
16+
# )
17+
# # Create will be delete files
18+
# CONFIGURE_FILE(
19+
# "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
20+
# "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
21+
# IMMEDIATE @ONLY)
22+
# # Create unistall target
23+
# ADD_CUSTOM_TARGET(uninstall
24+
# "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
25+
# DEPENDS uninstall-runtime)
26+
27+
28+
if(CMAKE_INSTALL_COMPONENT)
29+
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
30+
else()
31+
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
32+
endif()
33+
34+
IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}")
35+
MESSAGE(WARNING "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}\"")
36+
ELSE()
37+
38+
FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/${CMAKE_INSTALL_MANIFEST}" files)
39+
STRING(REGEX REPLACE "\n" ";" files "${files}")
40+
FOREACH(file ${files})
41+
MESSAGE(STATUS "Uninstalling \"${file}\"")
42+
IF(EXISTS "${file}")
43+
EXEC_PROGRAM(
44+
"@CMAKE_COMMAND@" ARGS "-E remove \"${file}\""
45+
OUTPUT_VARIABLE rm_out
46+
RETURN_VALUE rm_retval
47+
)
48+
IF("${rm_retval}" STREQUAL 0)
49+
ELSE("${rm_retval}" STREQUAL 0)
50+
MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"")
51+
ENDIF("${rm_retval}" STREQUAL 0)
52+
ELSE(EXISTS "${file}")
53+
MESSAGE(STATUS "File \"${file}\" does not exist.")
54+
ENDIF(EXISTS "${file}")
55+
ENDFOREACH(file)
56+
57+
ENDIF()

qtservice/examples/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_subdirectory(server)
2+
add_subdirectory(controller)
3+
add_subdirectory(interactive)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Author: Kang Lin <kl222@126.com>
2+
3+
project(controller)
4+
5+
add_executable(${PROJECT_NAME} main.cpp)
6+
target_link_libraries(${PROJECT_NAME} PRIVATE QtService)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Author: Kang Lin <kl222@126.com>
2+
3+
project(interactive)
4+
5+
SET(QT_COMPONENTS Gui Widgets)
6+
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core)
7+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS})
8+
if(Qt${QT_VERSION_MAJOR}_FOUND)
9+
FOREACH(_COMPONENT ${QT_COMPONENTS})
10+
LIST(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT})
11+
ENDFOREACH()
12+
endif()
13+
message("${PROJECT_NAME} QT_LIBRARIES:${QT_LIBRARIES}")
14+
15+
add_executable(${PROJECT_NAME} main.cpp)
16+
target_link_libraries(${PROJECT_NAME} PRIVATE QtService ${QT_LIBRARIES})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Author: Kang Lin <kl222@126.com>
2+
3+
project(httpservice)
4+
5+
# Need qt components
6+
set(QT_COMPONENTS Network)
7+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS})
8+
if(Qt${QT_VERSION_MAJOR}_FOUND)
9+
FOREACH(_COMPONENT ${QT_COMPONENTS})
10+
LIST(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT})
11+
ENDFOREACH()
12+
endif()
13+
message("${PROJECT_NAME} QT_LIBRARIES:${QT_LIBRARIES}")
14+
15+
add_executable(${PROJECT_NAME} main.cpp)
16+
17+
target_link_libraries(${PROJECT_NAME} PRIVATE QtService ${QT_LIBRARIES})

0 commit comments

Comments
 (0)