Fix build error
[platform/upstream/podofo.git] / CMakeLists.txt
1 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
2
3 #*****************  IMPORTANT  ************* IMPORTANT **********************
4 # Look at http://www.vtk.org/Wiki/CMake_HowToDoPlatformChecks
5 # and the other wiki entries before you add anything. You might not need to.
6 #****************************************************************************
7
8 #
9 # Project name and version
10 #
11 PROJECT(PoDoFo)
12
13 SET(PODOFO_VERSION_MAJOR "0" CACHE STRING "Major part of PoDoFo version number")
14 SET(PODOFO_VERSION_MINOR "9" CACHE STRING "Minor part of PoDoFo version number")
15 SET(PODOFO_VERSION_PATCH "7" CACHE STRING "Patchlevel part of PoDoFo version number")
16 SET(PODOFO_SOVERSION "${PODOFO_VERSION_MAJOR}.${PODOFO_VERSION_MINOR}.${PODOFO_VERSION_PATCH}")
17 SET(PODOFO_LIBVERSION "${PODOFO_SOVERSION}")
18
19
20 #
21 # Main includes
22 #
23 INCLUDE(CheckCXXSourceCompiles)
24 INCLUDE(CheckIncludeFile)
25 INCLUDE(CheckLibraryExists)
26 INCLUDE(TestBigEndian)
27 INCLUDE(CheckTypeSize)
28
29 #
30 # Setup CMake Policies
31 #
32
33 # Prefer files in CMAKE_MODULE_PATH over shipped ones in module directory
34 CMAKE_POLICY(SET CMP0017 NEW) # https://cmake.org/cmake/help/v3.0/policy/CMP0017.html
35 # Do not use export_library_dependencies() anymore
36 if(POLICY CMP0033)
37 CMAKE_POLICY(SET CMP0033 NEW) # https://cmake.org/cmake/help/v3.0/policy/CMP0033.html
38 endif()
39
40 # Load modules from our source tree too
41 SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
42
43
44 # Builds must use this CMakeLists.txt, not the one in src/ or somewhere else.
45 # If users try to use something else the results can be confusing. We set a
46 # variable here that we require to be set elsewhere, otherwise we'll complain.
47 SET(PODOFO_MAIN_CMAKELISTS_READ TRUE)
48
49 # If the user hasn't told use specifically what they want, build only
50 # a static library or only a shared library on Windows.
51 IF(NOT DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
52     IF(WIN32)
53         SET(PODOFO_BUILD_STATIC FALSE)
54         SET(PODOFO_BUILD_SHARED TRUE)
55     ELSE(WIN32)
56         SET(PODOFO_BUILD_STATIC TRUE)
57         SET(PODOFO_BUILD_SHARED FALSE)
58     ENDIF(WIN32)
59 ENDIF(NOT DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
60 IF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
61     IF(PODOFO_BUILD_SHARED)
62         SET(PODOFO_BUILD_STATIC FALSE)
63     ELSE(PODOFO_BUILD_SHARED)
64         SET(PODOFO_BUILD_STATIC TRUE)
65     ENDIF(PODOFO_BUILD_SHARED)
66 ENDIF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
67 IF(NOT DEFINED PODOFO_BUILD_SHARED AND DEFINED PODOFO_BUILD_STATIC)
68     IF(PODOFO_BUILD_STATIC)
69         SET(PODOFO_BUILD_SHARED FALSE)
70     ELSE(PODOFO_BUILD_STATIC)
71         SET(PODOFO_BUILD_SHARED TRUE)
72     ENDIF(PODOFO_BUILD_STATIC)
73 ENDIF(NOT DEFINED PODOFO_BUILD_SHARED AND DEFINED PODOFO_BUILD_STATIC)
74
75 IF(DEFINED LIB_SUFFIX)
76         SET(LIBDIRNAME "lib${LIB_SUFFIX}")
77 ELSE(DEFINED LIB_SUFFIX)
78
79 # Some 64 bit linux distros use /usr/lib64 for 64 bit libraries.
80 # on these platforms we must
81 IF(NOT DEFINED WANT_LIB64)
82         # TODO: detect 64-bit build and existance of /usr/lib64 and set to TRUE.
83         MESSAGE("WANT_LIB64 unset; assuming normal library directory names")
84         SET(WANT_LIB64 FALSE)
85 ENDIF(NOT DEFINED WANT_LIB64)
86
87 IF(WANT_LIB64)
88         SET(LIBDIRNAME "lib64")
89 ELSE(WANT_LIB64)
90         SET(LIBDIRNAME "lib")
91 ENDIF(WANT_LIB64)
92
93 ENDIF(DEFINED LIB_SUFFIX)
94 MESSAGE("Will install libraries to ${CMAKE_INSTALL_PREFIX}/${LIBDIRNAME}")
95
96 CHECK_CXX_SOURCE_COMPILES("#include <memory>
97                         class Cls {
98                         public:
99                         Cls() {}
100                         ~Cls() {}
101                         };
102                         int main(void) { std::unique_ptr<Cls> cls; return 0; }" PODOFO_HAVE_UNIQUE_PTR)
103
104 # Some headers that tend to vary a bit
105 CHECK_INCLUDE_FILE("strings.h" PODOFO_HAVE_STRINGS_H) 
106 CHECK_INCLUDE_FILE("arpa/inet.h" PODOFO_HAVE_ARPA_INET_H) 
107 CHECK_INCLUDE_FILE("winsock2.h" PODOFO_HAVE_WINSOCK2_H) 
108 CHECK_INCLUDE_FILE("mem.h" PODOFO_HAVE_MEM_H) 
109 CHECK_INCLUDE_FILE("ctype.h" PODOFO_HAVE_CTYPE_H) 
110
111 # Do some type size detection and provide yet another set of typedefs for fixed
112 # font sizes. We can't use the c99 / c++0x uint32_t etc, because people use
113 # ancient compilers that don't and will never support the standard.
114
115 CHECK_INCLUDE_FILE("sys/types.h" PODOFO_HAVE_SYS_TYPES_H) 
116 CHECK_INCLUDE_FILE("stdint.h" PODOFO_HAVE_STDINT_H) 
117 # See: http://msdn.microsoft.com/en-us/library/aa384264(VS.85).aspx
118 CHECK_INCLUDE_FILE("BaseTsd.h" PODOFO_HAVE_BASETSD_H) 
119
120 CHECK_TYPE_SIZE("long int" SZ_LONG)
121
122 # We cache integer type detection results, and don't repeat them
123 # (and overwrite the user's manual changes) if they've been done already.
124 IF(NOT PDF_INT64_TYPENAME)
125   # I hate old compilers.
126   IF(PODOFO_HAVE_STDINT_H)
127     SET(pdfint8 "int8_t")
128     SET(pdfint16 "int16_t")
129     SET(pdfint32 "int32_t")
130     SET(pdfint64 "int64_t")
131     SET(pdfuint8 "uint8_t")
132     SET(pdfuint16 "uint16_t")
133     SET(pdfuint32 "uint32_t")
134     SET(pdfuint64 "uint64_t")
135     CHECK_TYPE_SIZE("int64_t" SZ_INT64)
136   ELSE(PODOFO_HAVE_STDINT_H)
137     # No stdint.h . Try BaseTsd.h windows types.
138     IF(PODOFO_HAVE_BASETSD_H)
139        # We have BaseTsd.h, so use those types.
140        SET(pdfint8  "signed char")
141        SET(pdfint16 "short")
142        SET(pdfint32 "INT32")
143        SET(pdfint64 "INT64")
144        SET(pdfuint8 "unsigned char")
145        SET(pdfuint16 "unsigned short")
146        SET(pdfuint32 "UINT32")
147        SET(pdfuint64 "UINT64")
148        CHECK_TYPE_SIZE("INT64" SZ_INT64)
149     ELSE(PODOFO_HAVE_BASETSD_H)
150        # No BaseTsd.h either. Assume the standard types, and go poking
151        # for a sane 64-bit integer.
152        #
153        # First, though, make sure sizeof(int) = 4 and if not, scream, because
154        # hopefully this case will never be hit and we'll never have to write
155        # the horrible code check for
156        CHECK_TYPE_SIZE("signed char"        SZ_TINY_INT)
157        CHECK_TYPE_SIZE("unsigned char"      SZ_TINY_UINT)
158        CHECK_TYPE_SIZE("short int"          SZ_SHORT_INT)
159        CHECK_TYPE_SIZE("int"                SZ_INT)
160        CHECK_TYPE_SIZE("unsigned short int" SZ_UINT)
161        CHECK_TYPE_SIZE("unsigned int"       SZ_SHORT_UINT)
162        SET(smallintsok SZ_INT == 4 AND SZ_UINT == 4 AND SZ_SHORT_INT == 2 AND SZ_SHORT_UINT == 2 AND SZ_TINY_INT == 1 AND SZ_TINY_UINT == 1)
163        IF(NOT smallintsok)
164          MESSAGE(FATAL "sizeof(int) != 4 and/or sizeof(short) != 2 and no stdint.h or BaseTsd.h found. We don't know how to cope with this.")
165        ENDIF(NOT smallintsok)
166        SET(pdfint8 "signed char")
167        SET(pdfint16 "short")
168        SET(pdfint32 "int")
169        SET(pdfuint8 "unsigned char")
170        SET(pdfuint16 "unsigned short")
171        SET(pdfuint32 "unsigned int")
172        # Now we just have to figure out what 64-bit integer type we can use.
173        #
174        # Do we have VC >= 6's __uint64 and __int64?
175        # See: http://icfun.blogspot.com/2008/04/use-of-int64-variable-in-c.html
176        CHECK_TYPE_SIZE("__int64" SZ___INT64)
177        CHECK_TYPE_SIZE("__uint64"  SZ___UINT64)
178        IF(SZ___INT64 == 8 AND SZ___UINT64 == 8)
179          # MS compiler, VC6 or newer without BaseTsd.h in SDK
180          SET(pdfint64 "__int64")
181          SET(pdfuint64 "__uint64")
182          CHECK_TYPE_SIZE("__int64" SZ_INT64)
183        ELSE(SZ___INT64 AND SZ___UINT64)
184          # Still no luck. Old unix compiler, Borland, or some other monster?
185          # Are we lucky and sizeof(long) == 8?
186          CHECK_TYPE_SIZE("unsigned long int" SZ_ULONG)
187          IF(SZ_LONG == 8 AND SZ_ULONG == 8)
188            # Must be on a LP64 platform, sizeof(long) = 8
189            SET(pdfint64 "long int")
190            SET(pdfuint64 "unsigned long int")
191            CHECK_TYPE_SIZE("long int" SZ_INT64)
192          ELSE(SZ_LONG == 8 AND SZ_ULONG == 8)
193            # See if the compiler implements "long long int", int64_t, int64,
194            # or _int64 (in this order, __int64 check already done)
195            IF(PODOFO_HAVE_SYS_TYPES_H)
196              SET(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
197            ENDIF(PODOFO_HAVE_SYS_TYPES_H)
198            CHECK_TYPE_SIZE("long long int"          SZ_LONG_LONG)
199            CHECK_TYPE_SIZE("unsigned long long int" SZ_UNSIGNED_LONG_LONG)
200            IF(SZ_LONG_LONG == 8 AND SZ_UNSIGNED_LONG_LONG == 8)
201              SET(pdfint64 "long long int")
202              SET(pdfuint64 "unsigned long long int")
203              CHECK_TYPE_SIZE("long long int" SZ_INT64)
204            ELSE(SZ_LONG_LONG == 8 AND SZ_UNSIGNED_LONG_LONG == 8)
205              # The standard type int64_t is normally found in stdint.h,
206              # but use a type of this name anyway if present
207              CHECK_TYPE_SIZE("int64_t"       SZ_INT64_T)
208              CHECK_TYPE_SIZE("uint64_t"      SZ_UINT64_T)
209              IF(SZ_INT64_T AND SZ_UINT64_T)
210                SET(pdfint64 "int64_t")
211                SET(pdfuint64 "uint64_t")
212                CHECK_TYPE_SIZE("int64_t" SZ_INT64)
213              ELSE(SZ_INT64_T AND SZ_UINT64_T)
214                CHECK_TYPE_SIZE("int64"                SZ_INT64)
215                CHECK_TYPE_SIZE("uint64"               SZ_UINT64)
216                IF(SZ_INT64 AND SZ_UINT64)
217                  SET(pdfint64 "int64")
218                  SET(pdfuint64 "uint64")
219                  CHECK_TYPE_SIZE("int64" SZ_INT64)
220                ELSE(SZ_INT64 AND SZ_UINT64)
221                  CHECK_TYPE_SIZE("_int64"                SZ__INT64)
222                  CHECK_TYPE_SIZE("_uint64"               SZ__UINT64)
223                  IF(SZ__INT64 AND SZ__UINT64)
224                    SET(pdfint64 "_int64")
225                    SET(pdfuint64 "_uint64")
226                    CHECK_TYPE_SIZE("_int64" SZ_INT64)
227                  ELSE(SZ__INT64 AND SZ__UINT64)
228                    MESSAGE("Oh my lord, your compiler doesn't seem to support any of the int64 type flavours we tried.")
229                    MESSAGE(WARNING "You must set the PDF_INTxx_TYPENAME and PDF_UINTxx_TYPENAME variables manually")
230                  ENDIF(SZ__INT64 AND SZ__UINT64)
231                ENDIF(SZ_INT64 AND SZ_UINT64)
232              ENDIF(SZ_INT64_T AND SZ_UINT64_T)
233            ENDIF(SZ_LONG_LONG == 8 AND SZ_UNSIGNED_LONG_LONG == 8)
234          ENDIF(SZ_LONG == 8 AND SZ_ULONG == 8)
235        ENDIF(SZ___INT64 AND SZ___UINT64)
236     ENDIF(PODOFO_HAVE_BASETSD_H)
237   ENDIF(PODOFO_HAVE_STDINT_H)
238   SET(CMAKE_EXTRA_INCLUDE_FILES)
239 ENDIF(NOT PDF_INT64_TYPENAME)
240
241 IF(NOT PDF_INT64_TYPENAME AND pdfint64)
242   SET(PDF_INT64_TYPENAME  "${pdfint64}" CACHE STRING "Name of detected 64-bit signed integer type to use")
243   SET(PDF_INT32_TYPENAME  "${pdfint32}" CACHE STRING "Name of detected 32-bit signed integer type to use")
244   SET(PDF_INT16_TYPENAME  "${pdfint16}" CACHE STRING "Name of detected 16-bit signed integer type to use")
245   SET(PDF_INT8_TYPENAME   "${pdfint8}" CACHE STRING "Name of detected 8-bit signed integer type to use")
246   SET(PDF_UINT64_TYPENAME "${pdfuint64}" CACHE STRING "Name of detected 64-bit unsigned integer type to use")
247   SET(PDF_UINT32_TYPENAME "${pdfuint32}" CACHE STRING "Name of detected 32-bit unsigned integer type to use")
248   SET(PDF_UINT16_TYPENAME "${pdfuint16}" CACHE STRING "Name of detected 16-bit unsigned integer type to use")
249   SET(PDF_UINT8_TYPENAME  "${pdfuint8}" CACHE STRING "Name of detected 8-bit unsigned integer type to use")
250 ENDIF(NOT PDF_INT64_TYPENAME AND pdfint64)
251
252 # Linux packagers want an uninstall target.
253 CONFIGURE_FILE(
254     "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
255     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
256     IMMEDIATE @ONLY)
257 ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}"
258     -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
259
260 # Check if we are big endian
261 TEST_BIG_ENDIAN(TEST_BIG)
262
263 IF(WIN32)
264     # We must explicitly link to the core win32 libraries, and we need winsock2
265     # to get some byte-order conversion routines too.
266     SET(PLATFORM_SYSTEM_LIBRARIES kernel32 user32 gdi32 winspool comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32)
267     # Microsoft deprecate certain POSIX functions that we use.
268     # for now, turn off these warnings.
269     ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
270     # We need a fake unistd.h for some libraries to build. They try to include <unistd.h>
271     # which is not available under win32 with MSVC++, but everything in unistd.h is defined,
272     # so an empty file solves the issue.
273     SET(EXTRA_INCLUDES ${PoDoFo_SOURCE_DIR}/vcincludes)
274 ELSE(WIN32)
275     SET(PLATFORM_SYSTEM_LIBRARIES)
276     SET(EXTRA_INCLUDES)
277 ENDIF(WIN32)
278
279 IF(UNIX AND NOT PODOFO_NO_FONTMANAGER)
280     SET(WANT_FONTCONFIG TRUE CACHE INTERNAL
281         "True if PoDoFo should be built with fontconfig support")
282 ELSE(UNIX AND NOT PODOFO_NO_FONTMANAGER)
283     SET(WANT_FONTCONFIG FALSE CACHE INTERNAL
284         "True if PoDoFo should be built with fontconfig support")
285 ENDIF(UNIX AND NOT PODOFO_NO_FONTMANAGER)
286
287
288 IF(CMAKE_COMPILER_IS_GNUCXX)
289     MESSAGE("Using gcc specific compiler options")
290     # We can be more specific about what we want out of g++
291     # than with most other compilers.
292
293     # If the user hasn't specifically said whether they want
294     # -fvisibility=hidden or not, turn it on if it's said to
295     # be supported, off for other gcc versions.
296     IF(NOT DEFINED PODOFO_USE_VISIBILITY)
297         SET(PODOFO_USE_VISIBILITY ${PODOFO_HAVE_GCC_SYMBOL_VISIBILITY})
298     ENDIF(NOT DEFINED PODOFO_USE_VISIBILITY)
299
300     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
301
302     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual -Wswitch -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder -Wno-deprecated-declarations")
303
304     #
305     # Note that we do not need debug definitions here. Set
306     # -DCMAKE_BUILD_TYPE=debug or (if you want an optimised
307     # release build with debug info) -DCMAKE_CXX_FLAGS="-g3"
308     #
309     # We add -W unless we're using gcc on win32, where it produces
310     # spurious warnings about dllimport of inlines because of a dllimport
311     # declaration on the whole class.
312     IF(NOT WIN32)
313         ADD_DEFINITIONS(-W)
314     ENDIF(NOT WIN32)
315     # If they've enabled the use of gcc4 symbol visibility, use it.
316     IF(PODOFO_USE_VISIBILITY)
317         ADD_DEFINITIONS(
318             -DPODOFO_HAVE_GCC_SYMBOL_VISIBILITY
319             -fvisibility=hidden
320             )
321     ENDIF(PODOFO_USE_VISIBILITY)
322 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
323
324 FIND_PACKAGE(ZLIB REQUIRED)
325 MESSAGE("Found zlib headers in ${ZLIB_INCLUDE_DIR}, library at ${ZLIB_LIBRARIES}")
326
327 FIND_PACKAGE(LIBCRYPTO)
328
329 IF(LIBCRYPTO_FOUND)
330         SET(PODOFO_HAVE_OPENSSL TRUE)
331         INCLUDE_DIRECTORIES(${LIBCRYPTO_INCLUDE_DIR})
332         MESSAGE("Found OpenSSL's libCrypto headers in ${LIBCRYPTO_INCLUDE_DIR}, library at ${LIBCRYPTO_LIBRARIES}")
333 ELSE(LIBCRYPTO_FOUND)
334         MESSAGE("OpenSSL's libCrypto not found. Encryption support will be disabled")
335 ENDIF(LIBCRYPTO_FOUND)
336
337 FIND_PACKAGE(LIBIDN)
338
339 IF(LIBIDN_FOUND)
340   MESSAGE("Found libidn headers in ${LIBIDN_INCLUDE_DIR}, library at ${LIBIDN_LIBRARIES}")
341 ENDIF(LIBIDN_FOUND)
342
343 IF(LIBIDN_FOUND)
344         SET(PODOFO_HAVE_LIBIDN TRUE)
345         INCLUDE_DIRECTORIES(${LIBIDN_INCLUDE_DIR})
346         MESSAGE("Libidn found. AES-256 Encryption support will be enabled")
347 ELSE(LIBIDN_FOUND)
348         MESSAGE("Libidn not found. AES-256 Encryption support will be disabled")
349 ENDIF(LIBIDN_FOUND)
350
351 FIND_PACKAGE(LIBJPEG)
352
353 IF(LIBJPEG_FOUND)
354   MESSAGE("Found libjpeg headers in ${LIBJPEG_INCLUDE_DIR}, library at ${LIBJPEG_LIBRARIES}")
355   SET(PODOFO_HAVE_JPEG_LIB TRUE)
356   INCLUDE_DIRECTORIES(${LIBJPEG_INCLUDE_DIR})
357 ELSE(LIBJPEG_FOUND)
358   MESSAGE("Libjpeg not found. JPEG support will be disabled")
359 ENDIF(LIBJPEG_FOUND)
360
361 FIND_PACKAGE(TIFF)
362
363 IF(TIFF_FOUND)
364   MESSAGE("Found libtiff headers in ${TIFF_INCLUDE_DIR}, library at ${TIFF_LIBRARIES}")
365   SET(PODOFO_HAVE_TIFF_LIB TRUE)
366   INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
367 ELSE(TIFF_FOUND)
368   MESSAGE("Libtiff not found. TIFF support will be disabled")
369 ENDIF(TIFF_FOUND)
370
371 FIND_PACKAGE(PNG)
372
373 IF(PNG_FOUND)
374   MESSAGE("Found LibPng headers in ${PNG_INCLUDE_DIR}, library at ${PNG_LIBRARIES}")
375   SET(PODOFO_HAVE_PNG_LIB TRUE)
376   INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIR})
377 ELSE(PNG_FOUND)
378   MESSAGE("LibPng not found. PNG support will be disabled")
379   SET(PNG_LIBRARIES "")
380 ENDIF(PNG_FOUND)
381
382 FIND_PACKAGE(UNISTRING)
383
384 IF(UNISTRING_FOUND)
385   MESSAGE("Found LibUnistring headers in ${UNISTRING_INCLUDE_DIR}, library at ${UNISTRING_LIBRARY}")
386   SET(PODOFO_HAVE_UNISTRING_LIB TRUE)
387   INCLUDE_DIRECTORIES(${UNISTRING_INCLUDE_DIR})
388 ELSE(UNISTRING_FOUND)
389   MESSAGE("LibUnistring not found. Unistring support will be disabled")
390   SET(UNISTRING_LIBRARY "")
391 ENDIF(UNISTRING_FOUND)
392
393
394 IF(NOT PODOFO_BUILD_LIB_ONLY)
395
396 FIND_PACKAGE(CppUnit)
397
398 IF(CppUnit_FOUND)
399   MESSAGE("Found cppunit. Unit tests will be built.")
400   SET(PODOFO_HAVE_CPPUNIT CppUnit_FOUND)
401   INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR})
402 ELSE(CppUnit_FOUND)
403   MESSAGE("Cppunit not found. No unit tests will be built.")
404 ENDIF(CppUnit_FOUND)
405
406 ENDIF(NOT PODOFO_BUILD_LIB_ONLY)
407
408 FIND_PACKAGE(OpenSSL)
409
410 FIND_PACKAGE(FREETYPE REQUIRED)
411 MESSAGE("Found freetype library at ${FREETYPE_LIBRARIES}, headers ${FREETYPE_INCLUDE_DIR}")
412
413 FIND_PACKAGE(LIBSTLPORT)
414 SET(stlport_libraries_if_use_stlport)
415 IF(USE_STLPORT)
416         IF(LIBSTLPORT_FOUND)
417                 MESSAGE("Using STLPort")
418                 INCLUDE_DIRECTORIES(${LIBSTLPORT_HEADERS})
419                 LINK_DIRECTORIES(${LIBSTLPORT_LIB})
420                 SET(stlport_libraries_if_use_stlport stlport)
421                 # Use the threaded STLPort
422                 ADD_DEFINITIONS(-D_PTHREADS)
423         ELSE(LIBSTLPORT_FOUND)
424                 MESSAGE(FATAL_ERROR "STLPort use requested, but STLPort not found.")
425         ENDIF(LIBSTLPORT_FOUND)
426 ENDIF(USE_STLPORT)
427
428 IF(WANT_FONTCONFIG)
429         FIND_PACKAGE(FONTCONFIG REQUIRED)
430         SET(PODOFO_HAVE_FONTCONFIG TRUE)
431         SET(PODOFO_LIB_FONTCONFIG:STRING fontconfig)
432         IF(FONTCONFIG_FOUND)
433           MESSAGE("Found fontconfig headers in ${FONTCONFIG_INCLUDE_DIR}, library at ${FONTCONFIG_LIBRARIES}")
434         ELSE(FONTCONFIG_FOUND)
435           MESSAGE("Could not find fontconfig.")
436         ENDIF(FONTCONFIG_FOUND)
437 ELSE(WANT_FONTCONFIG)
438         # Might as well look for it anyway. This also sets the appropriate
439         # variables to empty values.
440         FIND_PACKAGE(FONTCONFIG)
441         SET(PODOFO_LIB_FONTCONFIG:STRING)
442 ENDIF(WANT_FONTCONFIG)
443
444 IF(NOT PODOFO_BUILD_LIB_ONLY)
445 FIND_PACKAGE(LUA)
446 IF(LUA_FOUND)
447         # If we have lua, we can build podofoimpose.
448         MESSAGE("Lua found - PoDoFoImpose and PoDoFoColor will be built with Lua support")
449         MESSAGE(" * Lua include directory: ${LUA_INCLUDE_DIR}")
450         MESSAGE(" * Lua libraries: ${LUA_LIBRARIES}")
451         INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR})
452         SET(PODOFO_HAVE_LUA TRUE)
453 ELSE(LUA_FOUND)
454         MESSAGE("Lua not found - PoDoFoImpose and PoDoFoColor will be built without Lua support")
455 ENDIF(LUA_FOUND)
456 ENDIF(NOT PODOFO_BUILD_LIB_ONLY)
457
458
459 # Check if we should build a multithreaded version of PoDoFo
460 IF(DEFINED PODOFO_NO_MULTITHREAD)
461   MESSAGE("Building non multithreaded version of PoDoFo.")
462   SET(PODOFO_MULTI_THREAD FALSE)
463 ELSE(DEFINED PODOFO_NO_MULTITHREAD)
464   MESSAGE("Building multithreaded version of PoDoFo.")
465   SET(PODOFO_MULTI_THREAD TRUE)
466   FIND_PACKAGE(Threads)
467   SET(PLATFORM_SYSTEM_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${PLATFORM_SYSTEM_LIBRARIES})
468 ENDIF(DEFINED PODOFO_NO_MULTITHREAD)
469
470 IF(WANT_BOOST)
471     MESSAGE("Looking optional for Boost.")
472     MESSAGE("Boost is optional, so don't worry if it is not found.")
473     MESSAGE("Set the BOOST_ROOT env var if you have problems.")
474     FIND_PACKAGE(Boost)
475     IF(BOOST_FOUND)
476        SET(PODOFO_HAVE_BOOST TRUE)
477        INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})
478     ELSE(BOOST_FOUND)
479        MESSAGE("If you don't need graph support you can ignore the above error.")
480     ENDIF(BOOST_FOUND)
481 ENDIF(WANT_BOOST)
482
483 INCLUDE_DIRECTORIES(BEFORE # before toolchain include dir (to ignore installed)
484     ${PoDoFo_SOURCE_DIR}/src   # order will be reversed, so this is the second dir
485     ${PoDoFo_BINARY_DIR}   # because of BEFORE, this is the first include dir
486     )
487
488 INCLUDE_DIRECTORIES(
489     ${PoDoFo_SOURCE_DIR}/src/podofo
490     ${FREETYPE_INCLUDE_DIR}
491     ${ZLIB_INCLUDE_DIR}
492     ${EXTRA_INCLUDES}
493      )
494 LINK_DIRECTORIES(
495     ${PoDoFo_BINARY_DIR}/src/podofo
496     )
497
498 #
499 # The PoDoFo library needs to be linked to these libraries,
500 # as do any apps or libraries linking to PoDoFo. PODOFO_LIB
501 # will include these and the correct podofo target, so clients
502 # should specify only PODOFO_LIB .
503 #
504 # The LIBCRYPTO_LDFLAGS is defined only if the libcrypto was found
505 # by pkg-config, otherwise it will be empty. It can contain proper
506 # path for the libcrypto too, thus it's added here.
507 #
508 SET(PODOFO_LIB_DEPENDS
509   ${ZLIB_LIBRARIES}
510   ${LIBIDN_LIBRARIES}
511   ${LIBCRYPTO_LDFLAGS}
512   ${LIBCRYPTO_LIBRARIES}
513   ${OPENSSL_LIBRARIES}
514   ${LIBJPEG_LIBRARIES}
515   ${PLATFORM_SYSTEM_LIBRARIES}
516   ${stlport_libraries_if_use_stlport}
517   ${FREETYPE_LIBRARIES}
518   ${PNG_LIBRARIES}
519   ${TIFF_LIBRARIES}
520   ${UNISTRING_LIBRARY}
521   )
522
523 IF(FONTCONFIG_FOUND AND WANT_FONTCONFIG)
524   SET(PODOFO_LIB_DEPENDS ${FONTCONFIG_LIBRARIES} ${PODOFO_LIB_DEPENDS})
525   INCLUDE_DIRECTORIES(${FONTCONFIG_INCLUDE_DIR})
526 ENDIF(FONTCONFIG_FOUND AND WANT_FONTCONFIG)
527
528 IF(WIN32 OR PODOFO_BUILD_STATIC)
529   SET(PODOFO_LIB
530       podofo
531       ${PODOFO_LIB_DEPENDS}
532       )
533 ELSE(WIN32 OR PODOFO_BUILD_STATIC)
534   SET(PODOFO_LIB podofo
535       ${stlport_libraries_if_use_stlport}
536       )
537 ENDIF(WIN32 OR PODOFO_BUILD_STATIC)
538
539 #
540 # Setup directories we will need
541 #
542 SET(MANDIR "share/man/")
543
544 # Create the config file. It'll be appended to as the subdirs run though
545 # then dependency information will be written to it at the end of the
546 # build.
547 FILE(WRITE
548      "${PoDoFo_BINARY_DIR}/PoDoFoConfig.cmake"
549      "# CMake module for PoDoFo\n"
550      )
551 FILE(APPEND 
552      "${PoDoFo_BINARY_DIR}/PoDoFoConfig.cmake"
553      "SET(PODOFO_INCLUDES ${PoDoFo_SOURCE_DIR}/src)\n"
554      )
555
556 ADD_SUBDIRECTORY(src/podofo)
557 IF(NOT PODOFO_BUILD_LIB_ONLY)
558 ADD_SUBDIRECTORY(test)
559 ADD_SUBDIRECTORY(tools)
560 ADD_SUBDIRECTORY(examples)
561 ADD_SUBDIRECTORY(man)
562 ENDIF(NOT PODOFO_BUILD_LIB_ONLY)
563
564 # Generate our configure file
565 CONFIGURE_FILE(${PoDoFo_SOURCE_DIR}/podofo_config.h.in ${PoDoFo_BINARY_DIR}/podofo_config.h)
566
567 # Export some variables into the config file so it's easier for others
568 # to build and link against PoDoFo
569
570 # To use these dependencies set PODOFO_DIR to the podofo BUILD directory in
571 # your build (eg -DPODOFO_DIR=/path/to/podofo when running cmake to configure
572 # the app that'll use podofo). See: FIND_PACKAGE(...) in the cmake docs.
573 IF(PODOFO_BUILD_SHARED)
574   EXPORT(TARGETS podofo_shared FILE "${CMAKE_CURRENT_BINARY_DIR}/PoDoFoConfig.cmake")
575 ENDIF(PODOFO_BUILD_SHARED)
576 IF(PODOFO_BUILD_STATIC)
577   EXPORT(TARGETS podofo_static FILE "${CMAKE_CURRENT_BINARY_DIR}/PoDoFoConfig.cmake")
578 ENDIF(PODOFO_BUILD_STATIC)
579