CMakeLists.txt 13.6 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0-or-later
2
cmake_minimum_required(VERSION 3.1.0)
3

4 5 6
cmake_policy(SET CMP0003 NEW) # don't be prolific with library paths
cmake_policy(SET CMP0005 NEW) # proper define quoting
cmake_policy(SET CMP0009 NEW) # don't follow symbolic links when using GLOB
7 8 9 10

if(POLICY CMP0075)
    cmake_policy(SET CMP0075 NEW) # link check-executable to CMAKE_REQUIRED_LIBRARIES (CMake 3.12.1)
endif(POLICY CMP0075)
11

12 13 14 15 16 17 18 19 20
message("------------------------------")
message("Building Makefile for Inkscape")
message("------------------------------")
message("Source Dir: ${CMAKE_CURRENT_SOURCE_DIR}")
message("Binary Dir: ${CMAKE_CURRENT_BINARY_DIR}")

# -----------------------------------------------------------------------------
# CMake Configuration
# -----------------------------------------------------------------------------
21 22
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
23 24
# set(CMAKE_CXX_EXTENSIONS OFF) # enforces -std=c++11 instead of -std=gnu++11
                                # TODO: build currently fails with it as we actually depend on GNU compiler extensions...
25

26
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeScripts/Modules")
27

28 29 30
# avoid having empty buildtype
set(CMAKE_BUILD_TYPE_INIT "Release")

Patrick Storz's avatar
Patrick Storz committed
31 32
include(CMakeScripts/HelperFunctions.cmake)
include(CMakeScripts/ConfigEnv.cmake)
33
include(GNUInstallDirs) # for the CMAKE_INSTALL_LIBDIR variable
Patrick Storz's avatar
Patrick Storz committed
34

35
project(inkscape)
36 37 38

include(CMakeScripts/ConfigPaths.cmake)

39
set(PROJECT_NAME inkscape)
40

Bryce Harrington's avatar
Bryce Harrington committed
41 42
set(INKSCAPE_VERSION_MAJOR  1)
set(INKSCAPE_VERSION_MINOR  0)
43
set(INKSCAPE_VERSION_PATCH  0)
44
set(INKSCAPE_VERSION_SUFFIX "alpha2")
45 46 47 48 49 50 51 52 53

set(INKSCAPE_VERSION ${INKSCAPE_VERSION_MAJOR}.${INKSCAPE_VERSION_MINOR})
if(INKSCAPE_VERSION_PATCH)
    set(INKSCAPE_VERSION ${INKSCAPE_VERSION}.${INKSCAPE_VERSION_PATCH})
endif()
if(INKSCAPE_VERSION_SUFFIX)
    set(INKSCAPE_VERSION ${INKSCAPE_VERSION}${INKSCAPE_VERSION_SUFFIX})
endif()

54
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
Sebastian Faubel's avatar
Sebastian Faubel committed
55

su-v's avatar
su-v committed
56 57
if(APPLE)
    SET(CMAKE_MACOSX_RPATH TRUE)
58
    SET(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}/inkscape")
su-v's avatar
su-v committed
59
else()
60
    SET(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}/inkscape")
su-v's avatar
su-v committed
61
endif()
62

63 64 65
# this can be removed if/when cmake 3.1 is made the minimum required version
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)

66 67 68
# console output is slow as hell on Windows and as a result status messages of the "install" target slow down
# the whole build process considerably (especially since we also copy a lot of files from the devlibs)
# TODO: Is this worth to be configurable / also applicable to other platforms?
69
if(WIN32 AND NOT CMAKE_INSTALL_MESSAGE)
70 71 72
    set(CMAKE_INSTALL_MESSAGE "LAZY")
endif()

73 74
# Define a very strict set of build flags that will prevent any use of deprecated symbols.
# This will almost certainly cause compilation failure and is intended only for developer use.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
set(CMAKE_CXX_FLAGS_STRICT "${CMAKE_CXX_FLAGS_DEBUG} -Werror=deprecated-declarations -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGTKMM_DISABLE_DEPRECATED -DGDKMM_DISABLE_DEPRECATED"
	CACHE STRING
	"Flags used by C++ compiler during Strict builds"
	FORCE)
set(CMAKE_C_FLAGS_STRICT   "${CMAKE_C_FLAGS_DEBUG}   -Werror=deprecated-declarations -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGTKMM_DISABLE_DEPRECATED -DGDKMM_DISABLE_DEPRECATED"
	CACHE STRING
	"Flags used by C compiler during Strict builds"
	FORCE)
mark_as_advanced(
	CMAKE_CXX_FLAGS_STRICT
	CMAKE_C_FLAGS_STRICT)

set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING
	"Choose the type of build, options are: None(CMAKE_CXXFLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Strict."
	FORCE)
90

91
# -----------------------------------------------------------------------------
92
# Redirect output files
93
# -----------------------------------------------------------------------------
94
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Output directory for runtime binaries")
95 96
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} CACHE PATH "Output directory for shared libraries")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} CACHE PATH "Output directory for static libraries")
97

Campbell Barton's avatar
Campbell Barton committed
98 99 100 101
# -----------------------------------------------------------------------------
# Options
# -----------------------------------------------------------------------------
option(WITH_DBUS "Compile with support for DBus interface" OFF)
102
option(ENABLE_LCMS "Compile with LCMS support" ON)
103 104
option(WITH_SVG2 "Compile with support for new SVG2 features" ON)
option(WITH_LPETOOL "Compile with LPE Tool and experimental LPEs enabled" ON)
105
option(WITH_OPENMP "Compile with OpenMP support" ON)
Campbell Barton's avatar
Campbell Barton committed
106 107

option(WITH_PROFILING "Turn on profiling" OFF) # Set to true if compiler/linker should enable profiling
108
option(BUILD_SHARED_LIBS "Compile libraries as shared and not static" ON)
109

110
option(ENABLE_POPPLER "Compile with support of libpoppler" ON)
111
option(ENABLE_POPPLER_CAIRO "Compile with support of libpoppler-cairo for rendering PDF preview (depends on ENABLE_POPPLER)" ON)
112 113
option(WITH_IMAGE_MAGICK "Compile with support of ImageMagick for raster extensions and image import resolution (requires ImageMagick 6; set to OFF if you prefer GraphicsMagick)" ON)
option(WITH_GRAPHICS_MAGICK "Compile with support of GraphicsMagick for raster extensions and image import resolution" ON)
114 115 116
option(WITH_LIBCDR "Compile with support of libcdr for CorelDRAW Diagrams" ON)
option(WITH_LIBVISIO "Compile with support of libvisio for Microsoft Visio Diagrams" ON)
option(WITH_LIBWPG "Compile with support of libwpg for WordPerfect Graphics" ON)
117
option(WITH_NLS "Compile with Native Language Support (using gettext)" ON)
Marc Jeanmougin's avatar
Marc Jeanmougin committed
118
option(WITH_JEMALLOC "Compile with JEMALLOC support" OFF)
119

Marc Jeanmougin's avatar
Marc Jeanmougin committed
120
option(WITH_FUZZ "Compile for fuzzing purpose (use 'make fuzz' only)" OFF)
121
mark_as_advanced(WITH_FUZZ)
Marc Jeanmougin's avatar
Marc Jeanmougin committed
122

Ted Gould's avatar
Ted Gould committed
123 124
option(ENABLE_BINRELOC "Enable relocatable binaries" OFF)

125

126 127
include(CMakeScripts/DefineDependsandFlags.cmake) # Includes, Compiler Flags, and Link Libraries
include(CMakeScripts/HelperMacros.cmake) # Misc Utility Macros
Campbell Barton's avatar
Campbell Barton committed
128 129 130

# -----------------------------------------------------------------------------
# BAD HACKS, NEED TO INVESTIGATE MAKING THESE LESS BAD
131
if(BUILD_SHARED_LIBS AND NOT WIN32)
Moritz Eberl's avatar
Moritz Eberl committed
132
    add_definitions(-fPIC)
133
endif()
Campbell Barton's avatar
Campbell Barton committed
134 135 136
#
# end badness
# -----------------------------------------------------------------------------
137

Marc Jeanmougin's avatar
Marc Jeanmougin committed
138

Ted Gould's avatar
Ted Gould committed
139

Campbell Barton's avatar
Campbell Barton committed
140
# -----------------------------------------------------------------------------
141
# Subdirectories
Campbell Barton's avatar
Campbell Barton committed
142 143
# -----------------------------------------------------------------------------
add_subdirectory(src)
144

145
if(ENABLE_NLS)
146
    add_subdirectory(po)
147
endif(ENABLE_NLS)
148

149
if(NOT WIN32)
150 151
    include(CMakeScripts/Pod2man.cmake)
    add_subdirectory(man)
152
endif()
153

154 155 156 157 158 159 160 161


# -----------------------------------------------------------------------------
# Check License Headers
# -----------------------------------------------------------------------------
add_custom_target(check-license-headers WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ./buildtools/check_license_headers.py)


162
# -----------------------------------------------------------------------------
163
# Test Harness
164
# -----------------------------------------------------------------------------
165 166 167
find_package(GTest) # gtest 1.8.0 and later already include gmock
if(GTEST_FOUND AND EXISTS "${GTEST_INCLUDE_DIR}/gmock" AND IS_DIRECTORY "${GTEST_INCLUDE_DIR}/gmock")
    set(GMOCK_PRESENT ON)
168
else()
169 170 171 172 173 174 175
    unset(GTEST_FOUND)
    if(NOT GMOCK_DIR)
        find_path(GMOCK_DIR
              NAMES src/gmock.cc
              PATHS "$ENV{GMOCK_DIR}"
                "/usr/src/googletest/googlemock"
                    "/usr/src/gmock"
176
                "${CMAKE_SOURCE_DIR}/gtest/gtest/googlemock"
177 178 179 180 181 182 183 184
             )
    endif(NOT GMOCK_DIR)
    if(EXISTS "${GMOCK_DIR}" AND IS_DIRECTORY "${GMOCK_DIR}")
        set(GMOCK_PRESENT ON)
    else()
        set(GMOCK_PRESENT OFF)
        message("No gmock/gtest found! Perhaps you wish to run 'bash download-gtest.sh' to download it.")
    endif()
185
endif()
186
if(GMOCK_PRESENT)
187
    enable_testing()
188
    set(CMAKE_CTEST_COMMAND ctest -V)
Patrick Storz's avatar
Patrick Storz committed
189
    if(WIN32)
190
        set(CMAKE_CTEST_ENV INKSCAPE_DATADIR=${CMAKE_BINARY_DIR}/inkscape_datadir)
Patrick Storz's avatar
Patrick Storz committed
191
    endif()
192
    add_subdirectory(testfiles EXCLUDE_FROM_ALL)
193
    add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS tests)
194
    add_dependencies(check inkscape)
195 196 197 198 199 200 201 202 203 204 205

    if(WIN32)
        # create symlink "inkscape_datadir" to use as INKSCAPE_DATADIR
        file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/share inkscape_share)
        add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/inkscape_datadir
            COMMAND mkdir inkscape_datadir
            COMMAND mklink /D inkscape_datadir\\inkscape ${inkscape_share}
        )
        add_custom_target(inkscape_datadir_symlink DEPENDS ${CMAKE_BINARY_DIR}/inkscape_datadir)
        add_dependencies(check inkscape_datadir_symlink)
    endif()
206
endif()
207

208
# -----------------------------------------------------------------------------
209 210
# Canonicalize the flags to speed up recompilation using ccache/etc.
# This should be the last thing we do:
211
# -----------------------------------------------------------------------------
212 213 214
include(CMakeScripts/CanonicalizeFlagsVar.cmake)
canonicalize_flags_var("${CMAKE_CXX_FLAGS}" _new_cxx)
set(CMAKE_CXX_FLAGS "${_new_cxx}" CACHE STRING "" FORCE)
Thomas Holder's avatar
Thomas Holder committed
215 216
canonicalize_flags_var("${CMAKE_CXX_FLAGS_DEBUG}" _new_cxx)
set(CMAKE_CXX_FLAGS_DEBUG "${_new_cxx}" CACHE STRING "" FORCE)
217 218
# message(FATAL_ERROR "CMAKE_CXX_FLAGS = <${CMAKE_CXX_FLAGS}>")

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238



# -----------------------------------------------------------------------------
# Clean Targets
# -----------------------------------------------------------------------------
add_custom_target(clean-cmake-files
    COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/CMakeScripts/CleanAll.cmake"
)

add_custom_target(clean-all
    COMMAND ${CMAKE_BUILD_TOOL} clean
    COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/CMakeScripts/CleanAll.cmake"
)

# -----------------------------------------------------------------------------
# Install Target
# -----------------------------------------------------------------------------
add_subdirectory(share)

239 240 241 242
install(FILES
	AUTHORS
	TRANSLATORS
	DESTINATION ${INKSCAPE_SHARE_INSTALL}/doc)
243

244
include(CMakeScripts/Install.cmake)
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

# -----------------------------------------------------------------------------
# Uninstall Target
# -----------------------------------------------------------------------------
if(WIN32)
    add_custom_target(uninstall
        "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_INSTALL_PREFIX}")
else()
    configure_file(
        "${CMAKE_SOURCE_DIR}/CMakeScripts/cmake_uninstall.cmake.in"
        "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
        @ONLY)
    add_custom_target(uninstall
        "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif()

# -----------------------------------------------------------------------------
# Dist Targets
# -----------------------------------------------------------------------------
include(CMakeScripts/Dist.cmake)

266 267 268 269 270
# -----------------------------------------------------------------------------
# Packaging (CPack)
# -----------------------------------------------------------------------------
include(CMakeScripts/ConfigCPack.cmake)

271 272


273 274 275 276 277 278 279 280 281 282
# ----------------------------------------------------------------------
# Information Summary
# ----------------------------------------------------------------------
message("------------------------------------------------------------------------")
message("Configuration Summary")
message("------------------------------------------------------------------------")
# project info
message("PROJECT_NAME:            ${PROJECT_NAME}")
message("INKSCAPE_VERSION:        ${INKSCAPE_VERSION}")
message("INKSCAPE_DIST_PREFIX:    ${INKSCAPE_DIST_PREFIX}")
283
message("INKSCAPE_CPACK_PREFIX:   ${INKSCAPE_CPACK_PREFIX}")
284 285 286 287
message("")

# cmake info
message("CMAKE_BINARY_DIR:        ${CMAKE_BINARY_DIR}")
Sebastian Faubel's avatar
Sebastian Faubel committed
288
message("CMAKE_INSTALL_PREFIX:    ${CMAKE_INSTALL_PREFIX}")
289
message("CMAKE_INSTALL_LIBDIR:    ${CMAKE_INSTALL_LIBDIR}")
290
message("PACKAGE_LOCALE_DIR       ${PACKAGE_LOCALE_DIR}")
291 292 293 294 295 296 297 298
message("CMAKE_SYSTEM_NAME:       ${CMAKE_SYSTEM_NAME}")
message("CMAKE_SYSTEM_VERSION:    ${CMAKE_SYSTEM_VERSION}")
message("CMAKE_SYSTEM_PROCESSOR:  ${CMAKE_SYSTEM_PROCESSOR}")
message("CMAKE_C_COMPILER:        ${CMAKE_C_COMPILER}")
message("CMAKE_CXX_COMPILER:      ${CMAKE_CXX_COMPILER}")
message("CMAKE_BUILD_TYPE:        ${CMAKE_BUILD_TYPE}")
message("")

Sebastian Faubel's avatar
Sebastian Faubel committed
299 300 301 302 303 304 305
if(WIN32)
message("CMAKE_PREFIX_PATH:           ${CMAKE_PREFIX_PATH}")
message("CMAKE_FIND_LIBRARY_PREFIXES: ${CMAKE_FIND_LIBRARY_PREFIXES}")
message("CMAKE_FIND_LIBRARY_SUFFIXES: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
message("")
endif()

306 307 308 309 310 311 312 313
# dependency info
message("ENABLE_LCMS:             ${ENABLE_LCMS}")
message("ENABLE_POPPLER:          ${ENABLE_POPPLER}")
message("ENABLE_POPPLER_CAIRO:    ${ENABLE_POPPLER_CAIRO}")
message("GMOCK_PRESENT:           ${GMOCK_PRESENT}")
message("WITH_DBUS:               ${WITH_DBUS}")
message("WITH_GTKSPELL:           ${WITH_GTKSPELL}")
message("WITH_IMAGE_MAGICK:       ${WITH_IMAGE_MAGICK}")
314
message("WITH_GRAPHICS_MAGICK:    ${WITH_GRAPHICS_MAGICK}")
315 316 317 318 319 320
message("WITH_LIBCDR:             ${WITH_LIBCDR}")
message("WITH_LIBVISIO:           ${WITH_LIBVISIO}")
message("WITH_LIBWPG:             ${WITH_LIBWPG}")
message("WITH_NLS:                ${WITH_NLS}")
message("WITH_OPENMP:             ${WITH_OPENMP}")
message("WITH_PROFILING:          ${WITH_PROFILING}")
321
message("WITH_JEMALLOC:           ${WITH_JEMALLOC}")
Sebastian Faubel's avatar
Sebastian Faubel committed
322 323 324 325 326 327 328

if(WIN32)
message("")
message("HAVE_MINGW64:            ${HAVE_MINGW64}")
message("MINGW_PATH:              ${MINGW_PATH}")
message("MINGW_ARCH:              ${MINGW_ARCH}")
message("MINGW_ARCH_PATH:         ${MINGW_ARCH_PATH}")
329
endif()
Sebastian Faubel's avatar
Sebastian Faubel committed
330

331
message("------------------------------------------------------------------------")