Release 0.2.0
[lxde/libsysstat.git] / CMakeLists.txt
CommitLineData
f474b9c8
HJYP
1cmake_minimum_required(VERSION 2.6)
2
90ef4ddc
KS
3project(libsysstat)
4
151ef16f
AG
5# Support different versions of Qt
6option(USE_QT5 "Build with Qt5." $ENV{USE_QT5})
80275532 7
91511e30 8# Set default installation paths
b3806d89 9set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries")
91511e30
VP
10set(INCLUDE_INSTALL_DIR include CACHE PATH "Installation path for includes")
11
1bbb8db9
JL
12set(MAJOR_VERSION 0)
13set(MINOR_VERSION 2)
14set(PATCH_VERSION 0)
15set(SYSSTAT_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
e61f67d1 16
90ef4ddc
KS
17add_definitions(-DMAJOR_VERSION=${MAJOR_VERSION})
18add_definitions(-DMINOR_VERSION=${MINOR_VERSION})
19add_definitions(-DPATCH_VERSION=${PATCH_VERSION})
5431d797 20add_definitions(-DSYSSTAT_LIBRARY)
90ef4ddc 21
df748e85
HJYP
22# use gcc visibility feature to decrease unnecessary exported symbols
23if (CMAKE_COMPILER_IS_GNUCXX)
24 # set visibility to hidden to hide symbols, unlesss they're exporeted manually in the code
a3676952 25 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall")
df748e85 26endif()
90ef4ddc 27
80275532
LP
28if (USE_QT5)
29 cmake_minimum_required(VERSION 2.8.11)
30 find_package(Qt5Core REQUIRED QUIET)
31 find_package(Qt5LinguistTools REQUIRED QUIET)
32 set(QT_VERSION_SUFFIX "-qt5")
80275532
LP
33else()
34 find_package(Qt4 REQUIRED)
35 include(${QT_USE_FILE})
36 set(QT_VERSION_SUFFIX "")
80275532 37endif()
f474b9c8 38
80275532
LP
39set(SYSSTAT_LIBRARY_NAME "sysstat${QT_VERSION_SUFFIX}")
40set(HEADER_NAMESPACE "SysStat")
90ef4ddc
KS
41
42set(SYSSTAT_PUBLIC_HDRS
11cc6ba1
KS
43 version.h
44 sysstat_global.h
45 basestat.h
46 cpustat.h
47 memstat.h
48 netstat.h
90ef4ddc
KS
49)
50
80275532
LP
51set(SYSSTAT_PUBLIC_CLASSES
52 Version
53 Global
54 BaseStat
55 CpuStat
56 MemStat
57 NetStat
58)
59
90ef4ddc 60set(SYSSTAT_PRIVATE_HDRS
11cc6ba1
KS
61 version_p.h
62 basestat_p.h
63 cpustat_p.h
64 memstat_p.h
65 netstat_p.h
90ef4ddc
KS
66)
67
68set(SYSSTAT_SRCS
69 version.cpp
70 basestat.cpp
71 cpustat.cpp
72 memstat.cpp
73 netstat.cpp
74)
75
76set(SYSSTAT_MOCS
11cc6ba1
KS
77 basestat.h
78 cpustat.h
79 memstat.h
80 netstat.h
81 basestat_p.h
82 cpustat_p.h
83 memstat_p.h
84 netstat_p.h
90ef4ddc
KS
85)
86
87
88# Translations **********************************
89file(GLOB SYSSTAT_TS_FILES
90 translations/*.ts
91)
92#************************************************
93
94
95#**********************************************************
90ef4ddc 96
80275532
LP
97if (USE_QT5)
98 QT5_WRAP_CPP(SYSSTAT_CXX ${SYSSTAT_MOCS})
99 qt5_add_translation(SYSSTAT_QM_FILES ${SYSSTAT_TS_FILES})
100else()
101 QT4_WRAP_CPP(SYSSTAT_CXX ${SYSSTAT_MOCS})
102 qt4_add_translation(SYSSTAT_QM_FILES ${SYSSTAT_TS_FILES})
103endif()
90ef4ddc
KS
104
105if (NOT CMAKE_BUILD_TYPE)
106 set ( CMAKE_BUILD_TYPE Release )
107endif (NOT CMAKE_BUILD_TYPE)
108
109
80275532 110set(APP_SHARE_DIR "${CMAKE_INSTALL_PREFIX}/share/${SYSSTAT_LIBRARY_NAME}")
f9847091
KS
111
112include_directories( .. )
90ef4ddc
KS
113add_definitions(-DTRANSLATIONS_DIR=\"${APP_SHARE_DIR}\")
114
80275532
LP
115add_library(${SYSSTAT_LIBRARY_NAME} SHARED ${SYSSTAT_PUBLIC_HDRS} ${SYSSTAT_PRIVATE_HDRS} ${SYSSTAT_SRCS} ${SYSSTAT_CXX} ${SYSSTAT_QM_FILES})
116
117if(USE_QT5)
118 target_link_libraries(${SYSSTAT_LIBRARY_NAME} Qt5::Core)
119else()
120 target_link_libraries(${SYSSTAT_LIBRARY_NAME} ${QT_LIBRARIES})
121endif()
122
90ef4ddc 123
80275532 124set_target_properties(${SYSSTAT_LIBRARY_NAME} PROPERTIES
e61f67d1 125 VERSION ${SYSSTAT_VERSION}
90ef4ddc
KS
126 SOVERSION ${MAJOR_VERSION}
127)
128
80275532
LP
129include(cmake/create_portable_headers.cmake)
130
131create_portable_headers(SYSSTAT_NAMESPACE_HEADERS
132 NAMESPACE "${HEADER_NAMESPACE}/"
133 FILENAMES ${SYSSTAT_PUBLIC_CLASSES}
134)
135install(TARGETS ${SYSSTAT_LIBRARY_NAME} DESTINATION ${LIB_INSTALL_DIR})
136install(FILES ${SYSSTAT_PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${SYSSTAT_LIBRARY_NAME})
137install(FILES ${SYSSTAT_NAMESPACE_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/${SYSSTAT_LIBRARY_NAME}/${HEADER_NAMESPACE})
90ef4ddc
KS
138install(FILES ${SYSSTAT_QM_FILES} DESTINATION ${APP_SHARE_DIR})
139
f474b9c8 140include(cmake/create_pkgconfig_file.cmake)
80275532 141create_pkgconfig_file(${SYSSTAT_LIBRARY_NAME} "SysStat, a Qt-based interface to system statistics")
e61f67d1
HJYP
142
143# cmake config file
80275532 144set(SYSSTAT_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include/${SYSSTAT_LIBRARY_NAME})
e61f67d1
HJYP
145configure_file(
146 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sysstat-config.cmake.in
80275532 147 ${CMAKE_CURRENT_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config.cmake
e61f67d1
HJYP
148 @ONLY
149)
80275532
LP
150install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SYSSTAT_LIBRARY_NAME}-config.cmake DESTINATION share/cmake/${SYSSTAT_LIBRARY_NAME})
151install(FILES cmake/sysstat_use.cmake DESTINATION share/cmake/${SYSSTAT_LIBRARY_NAME})
cdbfc4c9
HJYP
152
153# building tarball with CPack -------------------------------------------------
154include (InstallRequiredSystemLibraries)
155set (CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
156set (CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
157set (CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION})
158set (CPACK_GENERATOR TBZ2)
159set (CPACK_SOURCE_GENERATOR TBZ2)
160set (CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
161include (CPack)