4d162ba84da1dcd3a017fe995220c20966780f9d
[lxde/libsysstat.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
2
3 project(libsysstat)
4
5 set(MAJOR_VERSION 0)
6 set(MINOR_VERSION 4)
7 set(PATCH_VERSION 0)
8 set(SYSSTAT_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
9
10 set(LXQTBT_MINIMUM_VERSION "0.4.0")
11 set(QT_MINIMUM_VERSION "5.4.2")
12
13 # additional cmake files
14 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
15
16 find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
17 find_package(Qt5Core ${QT_MINIMUM_VERSION} REQUIRED)
18 message(STATUS "Building ${PROJECT_NAME} with Qt ${Qt5Core_VERSION}")
19
20 include(CMakePackageConfigHelpers)
21 include(GNUInstallDirs)             # Standard directories for installation
22 include(LXQtCreatePkgConfigFile)
23 include(LXQtCreatePortableHeaders)
24 include(LXQtCompilerSettings NO_POLICY_SCOPE)
25
26 set(CMAKE_AUTOMOC ON)
27 set(CMAKE_INCLUDE_CURRENT_DIR ON)
28
29 set(SYSSTAT_LIBRARY_NAME "sysstat-qt5")
30 set(HEADER_NAMESPACE "SysStat")
31
32 set(SYSSTAT_PUBLIC_HDRS
33     version.h
34     sysstat_global.h
35     basestat.h
36     cpustat.h
37     memstat.h
38     netstat.h
39 )
40
41 set(SYSSTAT_PUBLIC_CLASSES
42     Version
43     Global
44     BaseStat
45     CpuStat
46     MemStat
47     NetStat
48 )
49
50 set(SYSSTAT_PRIVATE_HDRS
51     version_p.h
52     basestat_p.h
53     cpustat_p.h
54     memstat_p.h
55     netstat_p.h
56 )
57
58 set(SYSSTAT_SRCS
59     version.cpp
60     basestat.cpp
61     cpustat.cpp
62     memstat.cpp
63     netstat.cpp
64 )
65
66 set(SYSSTAT_QM_FILES "")
67
68 if(NOT CMAKE_BUILD_TYPE)
69     set(CMAKE_BUILD_TYPE Release)
70 endif()
71
72
73 set(APP_SHARE_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${SYSSTAT_LIBRARY_NAME}")
74
75 add_library(${SYSSTAT_LIBRARY_NAME}
76     SHARED
77         ${SYSSTAT_PUBLIC_HDRS}
78         ${SYSSTAT_PRIVATE_HDRS}
79         ${SYSSTAT_SRCS}
80         ${SYSSTAT_QM_FILES}
81 )
82
83 target_link_libraries(${SYSSTAT_LIBRARY_NAME} Qt5::Core)
84
85 set_target_properties(${SYSSTAT_LIBRARY_NAME} PROPERTIES
86     VERSION ${SYSSTAT_VERSION}
87     SOVERSION ${MAJOR_VERSION}
88 )
89
90 target_compile_definitions(${SYSSTAT_LIBRARY_NAME}
91     PRIVATE
92         "MAJOR_VERSION=${MAJOR_VERSION}"
93         "MINOR_VERSION=${MINOR_VERSION}"
94         "PATCH_VERSION=${PATCH_VERSION}"
95         "SYSSTAT_LIBRARY"
96 )
97
98 target_include_directories(${SYSSTAT_LIBRARY_NAME}
99     INTERFACE
100         "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${SYSSTAT_LIBRARY_NAME}>"
101         "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/include/${SYSSTAT_LIBRARY_NAME}>"
102 )
103
104 lxqt_create_portable_headers(SYSSTAT_NAMESPACE_HEADERS
105     PATH_PREFIX ".."
106     HEADER_NAMES ${SYSSTAT_PUBLIC_CLASSES}
107 )
108
109 foreach(h ${SYSSTAT_NAMESPACE_HEADERS})
110     get_filename_component(bh ${h} NAME)
111     configure_file("${h}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/include/${SYSSTAT_LIBRARY_NAME}/${HEADER_NAMESPACE}/${bh}" COPYONLY)
112 endforeach()
113
114 foreach(h ${SYSSTAT_PUBLIC_HDRS})
115     get_filename_component(bh ${h} NAME)
116     configure_file("${h}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/include/${SYSSTAT_LIBRARY_NAME}/${bh}" COPYONLY)
117 endforeach()
118
119 install(TARGETS
120     ${SYSSTAT_LIBRARY_NAME}
121     DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT ${SYSSTAT_LIBRARY_NAME}-targets
122     COMPONENT Runtime
123 )
124
125 install(FILES
126     ${SYSSTAT_PUBLIC_HDRS}
127     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SYSSTAT_LIBRARY_NAME}"
128     COMPONENT Devel
129 )
130
131 install(FILES
132     ${SYSSTAT_NAMESPACE_HEADERS}
133     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SYSSTAT_LIBRARY_NAME}/${HEADER_NAMESPACE}"
134     COMPONENT Devel
135 )
136
137 #install(FILES ${SYSSTAT_QM_FILES} DESTINATION "${APP_SHARE_DIR}")
138
139 export(TARGETS
140     ${SYSSTAT_LIBRARY_NAME}
141     FILE "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-targets.cmake"
142 )
143
144 lxqt_create_pkgconfig_file(
145     PACKAGE_NAME ${SYSSTAT_LIBRARY_NAME}
146     DESCRIPTIVE_NAME ${SYSSTAT_LIBRARY_NAME}
147     DESCRIPTION "SysStat, a Qt-based interface to system statistics"
148     INCLUDEDIRS ${SYSSTAT_LIBRARY_NAME}
149     LIBS ${SYSSTAT_LIBRARY_NAME}
150     REQUIRES "Qt5Core"
151     VERSION ${SYSSTAT_VERSION}
152     INSTALL
153 )
154
155
156 # cmake config file
157 set(SYSSTAT_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include/${SYSSTAT_LIBRARY_NAME}")
158 configure_package_config_file(
159     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sysstat-config.cmake.in"
160     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config.cmake"
161     INSTALL_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${SYSSTAT_LIBRARY_NAME}"
162 )
163
164 # cmake version config file
165 write_basic_package_version_file(
166     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config-version.cmake"
167     VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
168     COMPATIBILITY AnyNewerVersion
169 )
170
171 install(FILES
172     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config.cmake"
173     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config-version.cmake"
174     DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${SYSSTAT_LIBRARY_NAME}"
175     COMPONENT Devel
176 )
177
178 install(EXPORT
179     ${SYSSTAT_LIBRARY_NAME}-targets
180     DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${SYSSTAT_LIBRARY_NAME}"
181     COMPONENT Devel
182 )