summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 07194dec4dafd006a822da5273303edeb53a672b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# The special language NONE is not available in cmake 2.6
if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 6)
    project(Libkolabxml NONE)
else()
    project(Libkolabxml C)
endif()

cmake_minimum_required(VERSION 2.6)

option( BUILD_TESTS "Build the tests" TRUE )
option( DIST_ONLY "Build dist targets only (does not require a compiler)" FALSE )
option( PYTHON_BINDINGS "Build bindings for python" FALSE )
option( PHP_BINDINGS "Build bindings for php" FALSE )
option( CSHARP_BINDINGS "Build bindings for csharp" FALSE )
option( JAVA_BINDINGS "Build bindings for java" FALSE )


set(Libkolabxml_MODULE_DIR ${Libkolabxml_SOURCE_DIR}/cmake/modules)
set(CMAKE_MODULE_PATH ${Libkolabxml_MODULE_DIR})

# only available from cmake-2.8.0
if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 7)
    cmake_policy(SET CMP0012 NEW)
endif()

# only available from cmake-2.8.4
if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 7 AND
    ${CMAKE_PATCH_VERSION} GREATER 3)
    cmake_policy(SET CMP0017 NEW)
endif()

# Versioning
# x.y.z scheme
# Development versions are only x.y
#
# i.e.
# 0.1 (0.1 development version)
# 0.1.0 (first release)
# 0.1.1 (patch release for 0.1.0)
# 0.2 (0.2 development version)

set (Libkolabxml_VERSION_MAJOR 0)
set (Libkolabxml_VERSION_MINOR 5)
# Enable the full x.y.z version only for release versions
# set (Libkolabxml_VERSION_PATCH 0)
# set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )

set (Libkolabxml_VERSION_STRING ${CMAKE_PROJECT_NAME}-${Libkolabxml_VERSION})
set (KOLAB_FORMAT_VERSION "3.0dev1")

message("Building DIST targets (make dist, make snapshot)")
#make dist requires a tag with ${ARCHIVE_NAME} (e.g. libkolabxml-0.2.0)
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${Libkolabxml_VERSION})
add_custom_target(dist
    COMMAND git archive --prefix=${ARCHIVE_NAME}/ ${ARCHIVE_NAME}
        | bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

#snapshot of current development version
set(SNAPSHOTARCHIVE_NAME "${CMAKE_PROJECT_NAME}-${Libkolabxml_VERSION}-HEAD")
add_custom_target(snapshot
    COMMAND git archive --prefix=${SNAPSHOTARCHIVE_NAME}/ HEAD
        | bzip2 > ${CMAKE_BINARY_DIR}/${SNAPSHOTARCHIVE_NAME}.tar.bz2
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
        
#It's possible to make dist targets only using:
#cmake -DDIST_ONLY=TRUE  ..
if (DIST_ONLY)
    message("Building DIST targets ONLY (cmake -DDIST_ONLY=FALSE  .. for full build)")
    return()
endif()

#C++ is required from here on
enable_language(CXX)

# set up install directories. INCLUDE_INSTALL_DIR and LIB_INSTALL_DIR must not be absolute paths
set(LIB_INSTALL_DIR_SUFFIX "" CACHE STRING "The directories where to install libraries to")
set(LIB_INSTALL_DIR lib${LIB_INSTALL_DIR_SUFFIX} )
set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Libkolabxml )

# Use a versioned install directory for the headers so multiple versions can be installed in parallel
set(INCLUDE_INSTALL_DIR include )

configure_file(libkolabxml-version.h.cmake "${CMAKE_BINARY_DIR}/libkolabxml-version.h" @ONLY)

set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS thread)
if (Boost_FOUND)
    message("Found boost in ${Boost_INCLUDE_DIRS}")
endif (Boost_FOUND)

find_package(LibkolabxmlDependencies REQUIRED) # Must be after findboost

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )

execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
                OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
    message(STATUS "GCC Version >= 4.7, applying unqualified lookup workaround")
    # gcc 4.7 no longer performs unqualified lookups by default, see: http://gcc.gnu.org/gcc-4.7/porting_to.html.
    # This workaround is added for xsd code, which fails otherwise to compile. -fpermissive turns the errors into warnings. 
    # It's only temporary, and should be removed once xsd is fixed.
    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive" ) 
endif()

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bindings)

set( SCHEMA_DIR ${CMAKE_SOURCE_DIR}/schemas )

# Generate bindings

set( SCHEMAS
    ${SCHEMA_DIR}/ical/kolabformat-xcal.xsd
    ${SCHEMA_DIR}/ical/iCalendar-params.xsd
    ${SCHEMA_DIR}/ical/iCalendar-props.xsd
    ${SCHEMA_DIR}/ical/iCalendar-valtypes.xsd
    ${SCHEMA_DIR}/xCard.xsd
    ${SCHEMA_DIR}/kolabformat-xcard.xsd
    ${SCHEMA_DIR}/kolabformat.xsd
)

set( SCHEMA_SOURCEFILES  
    ${CMAKE_BINARY_DIR}/bindings/kolabformat.cxx
    ${CMAKE_BINARY_DIR}/bindings/xCard.cxx
    ${CMAKE_BINARY_DIR}/bindings/kolabformat-xcal.cxx
    ${CMAKE_BINARY_DIR}/bindings/kolabformat-xcard.cxx
    ${CMAKE_BINARY_DIR}/bindings/iCalendar-params.cxx
    ${CMAKE_BINARY_DIR}/bindings/iCalendar-props.cxx
    ${CMAKE_BINARY_DIR}/bindings/iCalendar-valtypes.cxx
#     bindings/iCalendar-link-extension.cxx
#     bindings/iCalendar-bw-extensions.cxx
#     bindings/iCalendar-ms-extensions.cxx
)

#xsdcxx cxx-tree --generate-xml-schema --generate-serialization --custom-type date_time --hxx-epilogue '#include "bindings/customtypes/xml-schema-custom.hxx"' xml-schema.xsd
# --generate-inline --extern-xml-schema xml-schema.xsd
# --cxx-suffix .cpp --hxx-suffix .h   
add_custom_command(OUTPUT ${SCHEMA_SOURCEFILES}
    COMMAND ${XSDCXX} cxx-tree --generate-polymorphic --generate-serialization  --namespace-map http://kolab.org=KolabXSD --root-element icalendar --root-element vcards --root-element note --output-dir ${CMAKE_BINARY_DIR}/bindings ${SCHEMAS}
    COMMENT "Generating XSD bindings"
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    DEPENDS ${SCHEMAS}
    VERBATIM
    )

# Compile xsdbin if not found
if (NOT XSDBIN_FOUND)
    add_executable(xsdbin compiled/xsdbin.cxx)
    target_link_libraries(xsdbin ${XERCES_C})
    set(XSDBIN ${CMAKE_BINARY_DIR}/xsdbin)
endif ()

# Compile Schemas
add_custom_command(OUTPUT kolabformat-xcal-schema.cxx
        COMMAND ${XSDBIN} --verbose --array-name iCalendar_schema --output-dir ${CMAKE_BINARY_DIR} ${SCHEMAS}
        COMMENT "Compiling Kolab XSD schema"
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        DEPENDS ${SCHEMAS} ${XSDBIN}
        VERBATIM
    )

set( SCHEMA_SOURCEFILES ${SCHEMA_SOURCEFILES} ${CMAKE_BINARY_DIR}/kolabformat-xcal-schema.cxx)

# ---------

SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1)
ADD_CUSTOM_TARGET(generate_bindings ALL DEPENDS ${SCHEMA_SOURCEFILES})

include_directories(
    ./
    compiled
    ${CMAKE_CURRENT_BINARY_DIR}
    ${Boost_INCLUDE_DIRS}
    ${XSDCXX_INCLUDE_DIRS}
    ${XERCES_C_INCLUDE_DIRS}
)


add_subdirectory(src)

if (BUILD_TESTS)
    add_subdirectory(tests)
endif()

install(EXPORT LibkolabxmlExport DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE LibkolabxmlTargets.cmake )

file(RELATIVE_PATH relInstallDir ${CMAKE_INSTALL_PREFIX}/${CMAKECONFIG_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX} )

configure_file(${Libkolabxml_MODULE_DIR}/LibkolabxmlConfig.cmake.in ${Libkolabxml_BINARY_DIR}/LibkolabxmlConfig.cmake @ONLY )
configure_file(${Libkolabxml_MODULE_DIR}/LibkolabxmlConfigVersion.cmake.in ${Libkolabxml_BINARY_DIR}/LibkolabxmlConfigVersion.cmake @ONLY )
# Install these two files into the same directory as the generated exports-file.
install(FILES ${Libkolabxml_BINARY_DIR}/LibkolabxmlConfig.cmake ${Libkolabxml_BINARY_DIR}/LibkolabxmlConfigVersion.cmake
        DESTINATION ${CMAKECONFIG_INSTALL_DIR} )