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