CMakeLists.txt 13.7 KB
Newer Older
1
2
3
4
5
6
# Checking for user explicity defined CMAKE_INSTALL_PREFIX
# It must be done before project(...)
if(NOT CMAKE_INSTALL_PREFIX)
  set(QCA_INSTALL_IN_QT_PREFIX ON)
endif(NOT CMAKE_INSTALL_PREFIX)

Ivan Romanov's avatar
Ivan Romanov committed
7
project(qca)
8

Ivan Romanov's avatar
Ivan Romanov committed
9
cmake_minimum_required(VERSION 2.6.0)
10

Ivan Romanov's avatar
Ivan Romanov committed
11
12
13
14
set(QCA_LIB_MAJOR_VERSION "2")
set(QCA_LIB_MINOR_VERSION "1")
set(QCA_LIB_PATCH_VERSION "0")

15
16
17
18
19
# Do not automatically link Qt executables to qtmain target on Windows.
# QCA exucatables use console mode only. Not need to link against
# qtmain.lib.
cmake_policy(SET CMP0020 OLD)

20
option(BUILD_TESTS "Create test" ON)
Ivan Romanov's avatar
Ivan Romanov committed
21
option(BUILD_TOOLS "Compile mozcerts and qcatool" ON)
Ivan Romanov's avatar
Ivan Romanov committed
22
set(BUILD_PLUGINS "auto" CACHE STRING "Plugins for building (also possible values: none, all and auto)")
23
option(BUILD_SHARED_LIBS "Build shared library" ON)
Ivan Romanov's avatar
Ivan Romanov committed
24
option(DEVELOPER_MODE "Special developer mode" OFF)
Ivan Romanov's avatar
Ivan Romanov committed
25

Ivan Romanov's avatar
Ivan Romanov committed
26
27
find_package(Doxygen)

Ivan Romanov's avatar
Ivan Romanov committed
28
29
30
31
string(TOLOWER "${BUILD_PLUGINS}" BUILD_PLUGINS)
if(NOT BUILD_PLUGINS)
  set(BUILD_PLUGINS "none")
endif(NOT BUILD_PLUGINS)
32

33
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" )
34

David Faure's avatar
David Faure committed
35
36
37
38
option(QT4_BUILD "Force building with Qt4 even if Qt5 is found")
if (NOT QT4_BUILD)
  find_package(Qt5Core QUIET)
endif()
Ivan Romanov's avatar
Ivan Romanov committed
39
40
41

include(QcaMacro)

42
43
if (Qt5Core_FOUND)
  message(STATUS "Building with Qt5 support")
Ivan Romanov's avatar
no ECM    
Ivan Romanov committed
44
45
  # Got from ECM
  # Distros have no ECM. So I just copied required cmake modules.
46
  find_package(Qt5Transitional REQUIRED Core Network)
Ivan Romanov's avatar
no ECM    
Ivan Romanov committed
47
48
  include(ECMQt4To5Porting)

49
  include(GNUInstallDirs)
Ivan Romanov's avatar
Ivan Romanov committed
50
  setup_qt5_dirs()
51
  set(QCA_QT_PC_VERSION "Qt5Core")
52
53
else()
  set(QT_MIN_VERSION "4.7.0")
54
  set(QT_USE_IMPORTED_TARGETS ON)
Ivan Romanov's avatar
Ivan Romanov committed
55
56
57
58
59
60
  if(BUILD_TESTS)
    find_package(Qt4 REQUIRED QtCore QtNetwork QtTest)
  else(BUILD_TESTS)
    find_package(Qt4 REQUIRED QtCore)
  endif(BUILD_TESTS)

61
62
  # properly set up compile flags (QT_DEBUG/QT_NO_DEBUG, ...)
  include(${QT_USE_FILE})
63
  setup_qt4_dirs()
64
  set(QCA_QT_PC_VERSION "QtCore")
65
66
endif()

Ivan Romanov's avatar
Ivan Romanov committed
67
68
# QCA can be shared but plugins will be static
# if Qt is static.
69
if(NOT BUILD_SHARED_LIBS OR QT_IS_STATIC)
Ivan Romanov's avatar
Ivan Romanov committed
70
71
72
  set(STATIC_PLUGINS ON)
  add_definitions(-DQT_STATICPLUGIN)
  set(PLUGIN_TYPE "STATIC")
73
else(NOT BUILD_SHARED_LIBS OR QT_IS_STATIC)
Ivan Romanov's avatar
Ivan Romanov committed
74
  set(PLUGIN_TYPE "MODULE")
75
endif(NOT BUILD_SHARED_LIBS OR QT_IS_STATIC)
Ivan Romanov's avatar
Ivan Romanov committed
76

77
78
79
80
set(QCA_SUFFIX "" CACHE STRING "QCA common suffix")
if(QCA_SUFFIX)
  set(QCA_LIB_NAME qca-${QCA_SUFFIX})
  set(QCA_TOOL_NAME qcatool-${QCA_SUFFIX})
Ivan Romanov's avatar
Ivan Romanov committed
81
  set(MOZCERTS_NAME mozcerts-${QCA_SUFFIX})
82
83
  set(QCA_PC_NAME qca2-${QCA_SUFFIX}.pc)
else(QCA_SUFFIX)
84
  set(QCA_LIB_NAME qca)
85
  set(QCA_TOOL_NAME qcatool)
Ivan Romanov's avatar
Ivan Romanov committed
86
  set(MOZCERTS_NAME mozcerts)
87
88
  set(QCA_PC_NAME qca2.pc)
endif(QCA_SUFFIX)
89

Ivan Romanov's avatar
Ivan Romanov committed
90
91
92
93
if(DEVELOPER_MODE)
  add_definitions(-DDEVELOPER_MODE -DQCA_PLUGIN_PATH="${CMAKE_BINARY_DIR}/lib/${QCA_LIB_NAME}")
endif(DEVELOPER_MODE)

94
set(QCA_LIB_VERSION_STRING "${QCA_LIB_MAJOR_VERSION}.${QCA_LIB_MINOR_VERSION}.${QCA_LIB_PATCH_VERSION}")
95

96
configure_file("include/QtCrypto/qca_version.h.in" "${CMAKE_BINARY_DIR}/qca_version.h")
97

98
99
if (WIN32)
 set(CMAKE_DEBUG_POSTFIX "d")
100
 add_definitions(-DWIN32_LEAN_AND_MEAN)
Ivan Romanov's avatar
Ivan Romanov committed
101
elseif (APPLE)
Ivan Romanov's avatar
Ivan Romanov committed
102
 set(CMAKE_DEBUG_POSTFIX "_debug")
Ivan Romanov's avatar
Ivan Romanov committed
103
endif (WIN32)
Ivan Romanov's avatar
Ivan Romanov committed
104

105
106
if (CMAKE_COMPILER_IS_GNUCXX)
   if (CMAKE_SYSTEM_NAME MATCHES Linux)
André Wöbbeking's avatar
André Wöbbeking committed
107
     add_definitions (-D_BSD_SOURCE)
108
109
110
111
112
     set ( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -Wno-long-long -ansi -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
     set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fno-check-new -fno-common")
   endif (CMAKE_SYSTEM_NAME MATCHES Linux)
endif (CMAKE_COMPILER_IS_GNUCXX)

113
add_definitions (${QT_DEFINITIONS})
114
include_directories("include/QtCrypto/")
Ivan Romanov's avatar
Ivan Romanov committed
115
116
# for generated files
include_directories(${CMAKE_BINARY_DIR})
117

Ivan Romanov's avatar
Ivan Romanov committed
118
119
120
121
122
123
124
125
126
127
# uninstall target
configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    IMMEDIATE @ONLY)

add_custom_target(uninstall
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# /uninstall target

128
129
130
131
132
133
134
135
136
# Always include srcdir and builddir in include path
# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in about every subdir
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# put the include dirs which are in the source or build tree
# before all other include dirs, so the headers in the sources
# are prefered over the already installed ones
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)

137
set(qca_INCLUDEDIR "${CMAKE_CURRENT_SOURCE_DIR}/include" )
138

139
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )
140
# Use the same path for shared and static library
141
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )
142
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )
143

144
145
if( QCA_INSTALL_IN_QT_PREFIX )
  set(QCA_PREFIX_INSTALL_DIR "${QT_PREFIX_DIR}" CACHE PATH "Directory where qca will install")
146
  set(QCA_PLUGINS_INSTALL_DIR "${QT_PLUGINS_DIR}/crypto" CACHE PATH "Directory where qca plugins will install")
147
148
149
  set(QCA_BINARY_INSTALL_DIR "${QT_BINARY_DIR}" CACHE PATH "Directory where qca plugins will install")
  set(QCA_LIBRARY_INSTALL_DIR "${QT_LIBRARY_DIR}" CACHE PATH "Directory where qca library will install")
  set(QCA_FEATURE_INSTALL_DIR "${QT_MKSPECS_DIR}/features" CACHE PATH "Directory where qca feature file will install")
150
151
  set(QCA_INCLUDE_INSTALL_DIR "${QT_HEADERS_DIR}" CACHE PATH "Directory where qca public headers will install")
  set(QCA_PRIVATE_INCLUDE_INSTALL_DIR "${QT_HEADERS_DIR}" CACHE PATH "Directory where qca headers will install")
152
153
154
  set(QCA_DOC_INSTALL_DIR "${QT_DOC_DIR}/html/qca/" CACHE PATH "Directory where qca documentation will install")
  set(QCA_MAN_INSTALL_DIR "${QT_DATA_DIR}/man" CACHE PATH "Directory where qca man pages will install")
else( QCA_INSTALL_IN_QT_PREFIX )
Ivan Romanov's avatar
Ivan Romanov committed
155
156
157
158
159
  # Cmake says nothing about LIB_SUFFIX
  # de facto it is a standard way to specify lib suffix on many distros
  set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
  set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "Directory where lib will install")

160
  set(QCA_PREFIX_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Directory where qca will install")
161
  set(QCA_PLUGINS_INSTALL_DIR "${LIB_INSTALL_DIR}/${QCA_LIB_NAME}/crypto" CACHE PATH "Directory where qca plugins will install")
162
163
  set(QCA_BINARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Directory where qca plugins will install")
  set(QCA_LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}" CACHE PATH "Directory where qca library will install")
164
  set(QCA_FEATURE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/mkspecs/features" CACHE PATH "Directory where qca feature file will install")
165
166
  set(QCA_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Directory where qca public headers will install")
  set(QCA_PRIVATE_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Directory where qca headers will install")
Ivan Romanov's avatar
Ivan Romanov committed
167
  set(QCA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${QCA_LIB_NAME}/html" CACHE PATH "Directory where qca documentation will install")
168
  set(QCA_MAN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Directory where qca man pages will install")
169
170
endif( QCA_INSTALL_IN_QT_PREFIX )

Ivan Romanov's avatar
Ivan Romanov committed
171
set(PKGCONFIG_INSTALL_PREFIX "${QCA_LIBRARY_INSTALL_DIR}/pkgconfig" CACHE PATH "Base directory for pkgconfig files")
172

173
174
175
176
177
178
179
180
181
182
183
184
if (APPLE)
   find_package(Carbon REQUIRED)
   set(CMAKE_INSTALL_NAME_DIR ${QCA_LIBRARY_INSTALL_DIR})
   set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif (APPLE)

# set up RPATH handling, so the libs are found if they are installed to a non-standard location, Alex
if (UNIX  AND NOT  APPLE)
  set(CMAKE_INSTALL_RPATH_USE_LINK_PATH  TRUE)
  set(CMAKE_INSTALL_RPATH   "${QCA_LIBRARY_INSTALL_DIR}" )
endif (UNIX  AND NOT  APPLE)

185
message(STATUS "Checking for certstore..")
186
# fixme add OR mac
187
if( WIN32 )
188
# USE BUILTIN
189
190
191
192
193
194
195
196
197
else ( WIN32 )
  if ( ENV{QC_CERTSTORE_PATH} )
    if(EXISTS ENV{QC_CERTSTORE_PATH})
      set( qca_CERTSTORE $ENV{QC_CERTSTORE_PATH})
    else(EXISTS ENV{QC_CERTSTORE_PATH})
      # path to try
    endif(EXISTS ENV{QC_CERTSTORE_PATH})
  else( ENV{QC_CERTSTORE_PATH} )
    set( toTry
198
199
200
201
      "/etc/ssl/certs/ca-certificates.crt"
      "/usr/share/ssl/cert.pem"
      "/usr/share/ssl/certs/ca-bundle.crt"
      "/etc/pki/tls/cert.pem"
202
      "/etc/ssl/ca-bundle.pem"
203
      "/usr/share/curl/curl-ca-bundle.crt"
204
    )
205
206
207
208
209
210
211
212
213
214
215
216
217
    foreach (_current_try ${toTry})
      if(EXISTS ${_current_try})
        set( qca_CERTSTORE ${_current_try})
      endif(EXISTS ${_current_try})
    endforeach (_current_try)
  endif( ENV{QC_CERTSTORE_PATH} )
endif(WIN32)

if (qca_CERTSTORE)
  message(STATUS "Found system certstore")
else (qca_CERTSTORE)
  message(STATUS "Using built in certstore.")
  set( qca_CERTSTORE "${CMAKE_CURRENT_SOURCE_DIR}/certs/rootcerts.pem")
218
  # note that INSTALL_FILES targets are relative to the current installation prefix...
219
  install(FILES "${qca_CERTSTORE}" DESTINATION "${QCA_PREFIX_INSTALL_DIR}/certs")
220
221
endif (qca_CERTSTORE)
message(STATUS "certstore path: " ${qca_CERTSTORE})
Ivan Romanov's avatar
Ivan Romanov committed
222
add_definitions( -DQCA_SYSTEMSTORE_PATH="${qca_CERTSTORE}" )
223
224


225
set( private_HEADERS ${qca_INCLUDEDIR}/QtCrypto/qca_plugin.h ${qca_INCLUDEDIR}/QtCrypto/qca_systemstore.h )
226

227
set( public_HEADERS 
228
229
230
231
  ${qca_INCLUDEDIR}/QtCrypto/qca.h
  ${qca_INCLUDEDIR}/QtCrypto/qcaprovider.h
  ${qca_INCLUDEDIR}/QtCrypto/QtCrypto
  ${qca_INCLUDEDIR}/QtCrypto/qca_export.h
232
233
234
235
236
237
238
239
240
241
  ${qca_INCLUDEDIR}/QtCrypto/qca_support.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_tools.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_core.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_textfilter.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_basic.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_publickey.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_cert.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_keystore.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_securelayer.h
  ${qca_INCLUDEDIR}/QtCrypto/qca_securemessage.h
242
  ${CMAKE_BINARY_DIR}/qca_version.h
243
244
245
  ${qca_INCLUDEDIR}/QtCrypto/qpipe.h )

set( qca_HEADERS ${private_HEADERS} ${public_HEADERS} )
246
247

#install public headers only
248
install(FILES ${public_HEADERS} DESTINATION "${QCA_INCLUDE_INSTALL_DIR}/QtCrypto")
249

250
include_directories(${QT_QTCORE_INCLUDE_DIR} "${qca_INCLUDEDIR}/QtCrypto")
251

252
if(NOT WIN32)
253
254
  configure_file("qca2.pc.cmake" "${CMAKE_BINARY_DIR}/${QCA_PC_NAME}" @ONLY)
  install(FILES "${CMAKE_BINARY_DIR}/${QCA_PC_NAME}" DESTINATION ${PKGCONFIG_INSTALL_PREFIX})
255
endif(NOT WIN32)
256

257
configure_file("crypto.prf.cmake" "${CMAKE_BINARY_DIR}/crypto.prf" @ONLY)
258
install(FILES "${CMAKE_BINARY_DIR}/crypto.prf" DESTINATION "${QCA_FEATURE_INSTALL_DIR}")
259

260
261
configure_file(man/qcatool.1 "${CMAKE_BINARY_DIR}/${QCA_TOOL_NAME}.1" COPYONLY)
install(FILES "${CMAKE_BINARY_DIR}/${QCA_TOOL_NAME}.1" DESTINATION "${QCA_MAN_INSTALL_DIR}/man1")
262

263
add_subdirectory(src)
Laurent Montel's avatar
Laurent Montel committed
264
add_subdirectory(plugins)
Ivan Romanov's avatar
Ivan Romanov committed
265
266
267
268
269
270
271
272
273
274
275
276

if(STATIC_PLUGINS)
  # Generate header with static plugins list
  file(WRITE "${CMAKE_BINARY_DIR}/import_plugins.h" "#include <QtPlugin>\n")
  foreach(PLUGIN IN LISTS PLUGINS)
    if(WITH_${PLUGIN}_PLUGIN_INTERNAL)
      string(REPLACE "-" "_" IMPORT_NAME "qca-${PLUGIN}")
      file(APPEND "${CMAKE_BINARY_DIR}/import_plugins.h" "Q_IMPORT_PLUGIN(${IMPORT_NAME})\n")
    endif(WITH_${PLUGIN}_PLUGIN_INTERNAL)
  endforeach(PLUGIN IN LISTS PLUGINS)
endif(STATIC_PLUGINS)

277
if(BUILD_TESTS)
278
279
280
  enable_testing()
  add_subdirectory(unittest)
  add_subdirectory(examples)
281
endif(BUILD_TESTS)
Ivan Romanov's avatar
Ivan Romanov committed
282
283
284
if(BUILD_TOOLS)
  add_subdirectory(tools)
endif(BUILD_TOOLS)
285

Ivan Romanov's avatar
Ivan Romanov committed
286
287
288
289
290
291
292
293
if(DOXYGEN_FOUND)
  configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)
  add_custom_target(doc
    ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
    COMMENT "Generating API documentation with Doxygen" VERBATIM)
endif(DOXYGEN_FOUND)

294
295
296
297
298
299
300
301
302
# /usr/local is traditional path for installing apps on POSIX-systems.
# I consciously break this. Qt by default looks plugins and features only in
# own directory. So by default install libs in Qt prefix it is a best choice.
# This can be unwanted behaviour for users who don't read INSTALL file or/and
# not read cmake reports. I just try to warn their.

# In really anybody who do cmake . && make && sudo make install do it for own risk.

if(QCA_INSTALL_IN_QT_PREFIX)
303
  string(ASCII 27 ESCAPE)
304
  message("")
305
  message("${ESCAPE}[31m")
306
307
308
309
310
  message("!!!!!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!!!!!!!")
  message("!! QCA will be installed in Qt prefix             !!")
  message("!! If you want to install in /usr/local           !!")
  message("!! you MUST explicity define CMAKE_INSTALL_PREFIX !!")
  message("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
311
  message("${ESCAPE}[0m")
312
313
314
315
316
317
318
319
320
321
322
323
324
325
endif(QCA_INSTALL_IN_QT_PREFIX)

message("")
message("QCA prefix is " ${QCA_PREFIX_INSTALL_DIR})
message("Plugins will be installed to " ${QCA_PLUGINS_INSTALL_DIR})
message("Binary will be installed to " ${QCA_BINARY_INSTALL_DIR})
message("Library will be installed to " ${QCA_LIBRARY_INSTALL_DIR})
message("Feature file will be installed to " ${QCA_FEATURE_INSTALL_DIR})
message("Public headers will be installed to " ${QCA_INCLUDE_INSTALL_DIR})
message("Private headers will be installed to " ${QCA_PRIVATE_INCLUDE_INSTALL_DIR})
message("Documentation will be installed to " ${QCA_DOC_INSTALL_DIR})
message("Man page will be installed to " ${QCA_MAN_INSTALL_DIR})
message("Pkg-config file will be installed to " ${PKGCONFIG_INSTALL_PREFIX})
message("")
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

include(CMakePackageConfigHelpers)
configure_package_config_file(
  "${CMAKE_CURRENT_SOURCE_DIR}/QCA2Config.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/QCA2Config.cmake"
  INSTALL_DESTINATION "share/cmake/QCA2"
)
write_basic_config_version_file(QCA2ConfigVersion.cmake VERSION ${QCA_LIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion)

install(EXPORT QCATargets DESTINATION "share/cmake/QCA2" FILE QCA2Targets.cmake NAMESPACE QCA:: )
install(FILES
  "${CMAKE_CURRENT_BINARY_DIR}/QCA2Config.cmake"
  "${CMAKE_CURRENT_BINARY_DIR}/QCA2ConfigVersion.cmake"
  DESTINATION "share/cmake/QCA2"
  COMPONENT Devel
)