Drop Qt foreach.
[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.7.1")
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         "QT_NO_FOREACH"
97 )
98
99 target_include_directories(${SYSSTAT_LIBRARY_NAME}
100     INTERFACE
101         "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${SYSSTAT_LIBRARY_NAME}>"
102         "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/include/${SYSSTAT_LIBRARY_NAME}>"
103 )
104
105 lxqt_create_portable_headers(SYSSTAT_NAMESPACE_HEADERS
106     PATH_PREFIX ".."
107     HEADER_NAMES ${SYSSTAT_PUBLIC_CLASSES}
108 )
109
110 foreach(h ${SYSSTAT_NAMESPACE_HEADERS})
111     get_filename_component(bh ${h} NAME)
112     configure_file("${h}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/include/${SYSSTAT_LIBRARY_NAME}/${HEADER_NAMESPACE}/${bh}" COPYONLY)
113 endforeach()
114
115 foreach(h ${SYSSTAT_PUBLIC_HDRS})
116     get_filename_component(bh ${h} NAME)
117     configure_file("${h}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/include/${SYSSTAT_LIBRARY_NAME}/${bh}" COPYONLY)
118 endforeach()
119
120 install(TARGETS
121     ${SYSSTAT_LIBRARY_NAME}
122     DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT ${SYSSTAT_LIBRARY_NAME}-targets
123     COMPONENT Runtime
124 )
125
126 install(FILES
127     ${SYSSTAT_PUBLIC_HDRS}
128     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SYSSTAT_LIBRARY_NAME}"
129     COMPONENT Devel
130 )
131
132 install(FILES
133     ${SYSSTAT_NAMESPACE_HEADERS}
134     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SYSSTAT_LIBRARY_NAME}/${HEADER_NAMESPACE}"
135     COMPONENT Devel
136 )
137
138 #install(FILES ${SYSSTAT_QM_FILES} DESTINATION "${APP_SHARE_DIR}")
139
140 export(TARGETS
141     ${SYSSTAT_LIBRARY_NAME}
142     FILE "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-targets.cmake"
143 )
144
145 lxqt_create_pkgconfig_file(
146     PACKAGE_NAME ${SYSSTAT_LIBRARY_NAME}
147     DESCRIPTIVE_NAME ${SYSSTAT_LIBRARY_NAME}
148     DESCRIPTION "SysStat, a Qt-based interface to system statistics"
149     INCLUDEDIRS ${SYSSTAT_LIBRARY_NAME}
150     LIBS ${SYSSTAT_LIBRARY_NAME}
151     REQUIRES "Qt5Core"
152     VERSION ${SYSSTAT_VERSION}
153     INSTALL
154 )
155
156
157 # cmake config file
158 set(SYSSTAT_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include/${SYSSTAT_LIBRARY_NAME}")
159 configure_package_config_file(
160     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sysstat-config.cmake.in"
161     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config.cmake"
162     INSTALL_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${SYSSTAT_LIBRARY_NAME}"
163 )
164
165 # cmake version config file
166 write_basic_package_version_file(
167     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config-version.cmake"
168     VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
169     COMPATIBILITY AnyNewerVersion
170 )
171
172 install(FILES
173     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config.cmake"
174     "${CMAKE_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config-version.cmake"
175     DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${SYSSTAT_LIBRARY_NAME}"
176     COMPONENT Devel
177 )
178
179 install(EXPORT
180     ${SYSSTAT_LIBRARY_NAME}-targets
181     DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${SYSSTAT_LIBRARY_NAME}"
182     COMPONENT Devel
183 )