CMakeLists.txt 21.9 KB
Newer Older
1
cmake_minimum_required(VERSION 3.1)
2

3
cmake_policy(SET CMP0011 NEW)
4
cmake_policy(SET CMP0025 NEW)
5
cmake_policy(SET CMP0048 OLD) # don't touch PROJECT_VERSION/VERSION
6

7 8 9 10 11 12 13 14 15 16
#
# Avoid source tree pollution
#
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

If(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
  message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building:\nmkdir build; cd build; cmake ..\nBefore that, remove the files already created:\nrm -rf CMakeCache.txt CMakeFiles")
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)

17 18 19
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")

20
project(darktable CXX C)
21

22 23
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

24 25 26 27 28 29 30 31 32 33 34 35
# Allow forcing the C/CPP compiler that is actually used during the compilation
# to something other than what is used by the cmake run. This is useful when
# the compiler for some reason breaks the initial cmake checks but works fine
# for actually compiling darktable. This allows building darktable using
# afl-clang-fast achieving a >4x speedup in fuzzing.
IF(DEFINED DT_FORCE_C_COMPILER)
  set(CMAKE_C_COMPILER ${DT_FORCE_C_COMPILER})
endif()
IF(DEFINED DT_FORCE_CXX_COMPILER)
  set(CMAKE_CXX_COMPILER ${DT_FORCE_CXX_COMPILER})
endif()

36
include(CheckCCompilerFlag)
37
include(TestBigEndian)
38 39 40 41 42 43 44 45

# Check if this is source package build
if(NOT IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
  set(SOURCE_PACKAGE 1)
else()
  set(SOURCE_PACKAGE 0)
endif()

46 47 48 49 50
# Include GNUInstallDirs, which sets sensible defaults for install directories.
# See https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html for further information.
# These values can be easily overridden if required.
# Some defaults are set for OpenBSD as well (info and man pages).

51 52
include(GNUInstallDirs)

53
option(USE_CAMERA_SUPPORT "Detect and use camera support if available." ON)
54
option(USE_NLS "Build Native Language Support (using gettext)" ON)
55
option(USE_COLORD "Enable colord support" ON)
56
option(USE_MAP "Build Map View parts" ON)
Boucman's avatar
Boucman committed
57
option(USE_LUA "Build lua scripting support" ON)
58
option(DONT_USE_INTERNAL_LUA "Never fall back to the intree copy of lua" ON)
59
option(USE_FLICKR "Enable Flickr support" ON)
Moritz Lipp's avatar
Moritz Lipp committed
60 61
option(USE_KWALLET "Build kwallet password storage back-end" ON)
option(USE_LIBSECRET "Build libsecret password storage back-end" ON)
62
option(USE_UNITY "Use libunity to report progress in the launcher" OFF)
63
option(USE_OPENMP "Use openmp threading support." ON)
64
option(USE_OPENCL "Use OpenCL support." ON)
65
option(USE_GRAPHICSMAGICK "Use GraphicsMagick library for image import." ON)
66
option(USE_DARKTABLE_PROFILING OFF)
67
option(CUSTOM_CFLAGS "Don't override compiler optimization flags." OFF)
68
option(BUILD_USERMANUAL "Build all the versions of the usermanual." OFF)
69
option(BINARY_PACKAGE_BUILD "Sets march optimization to generic" OFF)
70
option(USE_XMLLINT "Run xmllint to test if darktableconfig.xml is valid" ON)
71
option(USE_OPENJPEG "Enable JPEG 2000 support" ON)
72
option(USE_WEBP "Enable WebP export support" ON)
73
option(BUILD_CMSTEST "Build a test program to check your system's color management setup" ON)
74
option(USE_OPENEXR "Enable OpenEXR support" ON)
75
option(BUILD_PRINT "Build the print module" ON)
76
option(BUILD_RS_IDENTIFY "Build the darktable-rs-identify debug aid" ON)
77
option(BUILD_SSE2_CODEPATHS "(EXPERIMENTAL OPTION, DO NOT DISABLE) Building SSE2-optimized codepaths" ON)
78
option(VALIDATE_APPDATA_FILE "Use appstream-util (if found) to validate the .appdata file" OFF)
79
option(BUILD_TESTS "Build tests in src/tests/, runnable from the build/ directory" OFF)
80
option(BUILD_BATTERY_INDICATOR "Add an icon to the top toolbar showing the state of a laptop battery" OFF)
81
option(BUILD_MSYS2_INSTALL "Build an MSYS2 version of the install, aka for Windows platform, but without dependency installs" OFF)
82
option(BUILD_NOISE_TOOLS "Build tools for generating noise proifles" OFF)
83 84 85 86 87 88

if(USE_OPENCL)
  option(TESTBUILD_OPENCL_PROGRAMS "Test-compile opencl programs (needs llvm and clang 3.9+)" ON)
else()
  set(TESTBUILD_OPENCL_PROGRAMS OFF)
endif()
89

90 91 92 93 94
if(BUILD_SSE2_CODEPATHS)
  CHECK_C_COMPILER_FLAG("-msse2" _MSSE2)
  if(NOT _MSSE2)
    MESSAGE(WARNING "Building of SSE2-optimized codepaths is enabled, but the compiler does not understand -msse2.")
    set(BUILD_SSE2_CODEPATHS OFF)
95 96 97 98 99
  endif()
endif()

MESSAGE(STATUS "Building SSE2-optimized codepaths: ${BUILD_SSE2_CODEPATHS}")

100 101 102 103 104 105 106 107 108
test_big_endian(BIGENDIAN)
if(${BIGENDIAN})
	# we do not really want those.
	# besides, no one probably tried darktable on such systems
	MESSAGE(FATAL_ERROR "Found big endian system. Bad.")
else()
	MESSAGE(STATUS "Found little endian system. Good.")
endif(${BIGENDIAN})

109 110 111
set(CMAKE_REQUIRED_INCLUDES_OLD "${CMAKE_REQUIRED_INCLUDES}")
list(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_SOURCE_DIR}")

112
check_c_source_compiles("
113
#include <stdio.h>
114
int main() {
115
#include \"src/is_supported_platform.h\"
116 117 118 119 120 121
}" IS_SUPPORTED_PLATFORM)
if(NOT IS_SUPPORTED_PLATFORM)
  MESSAGE(FATAL_ERROR "The target platform is not supported!")
endif(NOT IS_SUPPORTED_PLATFORM)
MESSAGE(STATUS "Is the target platform supported: ${IS_SUPPORTED_PLATFORM}")

122 123 124
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES_OLD}")
unset(CMAKE_REQUIRED_INCLUDES_OLD)

125 126 127 128 129
if(APPLE)
	option(USE_MAC_INTEGRATION "Enable OS X integration" ON)
else(APPLE)
	set(USE_MAC_INTEGRATION OFF)
endif(APPLE)
130

131 132 133 134 135 136
# When cross compiling, CMAKE_INSTALL_PREFIX will point to something like "/opt/darktable", but that's not useful when using the path to load
# modules on runtime. Then we need something like "C:\Program Files\darktable". Doesn't need to be set when doing regular compiles.
if(NOT DEFINED RUNTIME_INSTALL_PREFIX)
  set(RUNTIME_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
endif(NOT DEFINED RUNTIME_INSTALL_PREFIX)

137 138 139
# Generate multi arch triplet
EXECUTE_PROCESS(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH OUTPUT_VARIABLE CMAKE_ARCH_TRIPLET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(CMAKE_ARCH_TRIPLET)
140
	message("-- multiarch triplet detected: " ${CMAKE_ARCH_TRIPLET})
141 142 143 144
	LIST(INSERT CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES 0 /lib/${CMAKE_ARCH_TRIPLET}
		/usr/lib/${CMAKE_ARCH_TRIPLET})
endif()

145 146 147 148
#
# Set platform defaults...
#
if(APPLE)
149
	message("-- Mac OS X build detected, setting default features")
150

151 152
	# prefer macports and/or user-installed libraries over system ones
	LIST(APPEND CMAKE_PREFIX_PATH /opt/local /usr/local)
153
	set(CMAKE_FIND_FRAMEWORK "LAST")
154 155 156 157
	# except libstdc++ (only one linked via -l flag, not full path)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/lib")
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/lib")
	set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L/usr/lib")
158

159 160
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DARWIN_C_SOURCE")
161
	add_definitions("-DOS_OBJECT_USE_OBJC=0")
162 163
endif(APPLE)

164
include(compiler-versions)
165

166
if(WIN32)
167
  message("-- Win32 build detected, setting default features")
168 169 170 171
  set(USE_COLORD OFF)
  set(USE_KWALLET OFF)
  set(BUILD_CMSTEST OFF)
  set(BUILD_PRINT OFF)
172
  set(TESTBUILD_OPENCL_PROGRAMS OFF)
173 174 175
  if(BUILD_MSYS2_INSTALL)
    add_definitions(-DMSYS2_INSTALL)
  endif()
176 177
endif(WIN32)

178

179
#
180
# Set package version
181
#
182
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src/") # the src/ subdirectory won't exist yet
183 184 185

# adds custom command to generate header containing version info.
# takes 1 optional parameter - version override.
186
function(generate_version_gen_c)
187
  if(ARGC EQUAL 2)
188 189
    # if a version override was specified, use it
    set(_VERSION "${ARGV0}")
190
    set(_TYPE "${ARGV1}")
191 192 193
  else()
    # else, the tool will autodetect the version
    set(_VERSION "")
194
    set(_TYPE "git checkout")
195 196
  endif()

197 198
  add_custom_target(
    create_version_gen ALL
199 200
    COMMAND ${CMAKE_SOURCE_DIR}/tools/create_version_c.sh ${CMAKE_BINARY_DIR}/src/version_gen.c ${_VERSION}
    DEPENDS ${CMAKE_SOURCE_DIR}/tools/create_version_c.sh
201
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
202
    COMMENT "Updating version string (${_TYPE})"
203
    VERBATIM # else might break when export-subst was needed but did not happen
204
  )
205
endfunction(generate_version_gen_c)
206 207 208 209

if(DEFINED PROJECT_VERSION)
  #project version is defined by -D on the cmake command line
  # only use that value, do not update it at make time
210
  generate_version_gen_c(${PROJECT_VERSION} "version override")
211
else(DEFINED PROJECT_VERSION)
212 213 214
  if(NOT SOURCE_PACKAGE) # i.e., a git checkout
    # this part is setting the corresponding CMake variable which gets used for example when creating a source package
    execute_process(
215
      COMMAND sh ${CMAKE_SOURCE_DIR}/tools/get_git_version_string.sh OUTPUT_STRIP_TRAILING_WHITESPACE
216
      OUTPUT_VARIABLE PROJECT_VERSION
217
      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
218
    # FIXME: PROJECT_VERSION will not be updated automatically, until you rerun cmake
219
    generate_version_gen_c()
220
  else(NOT SOURCE_PACKAGE)
221
    if(NOT EXISTS ${CMAKE_SOURCE_DIR}/src/version_gen.c)
222
      # should be expanded by git archive due to export-subst in .gitattributes
223
      set(PROJECT_VERSION "archive-6305f8363de0e349f7947b701efb54e035ac0709")
224 225 226 227
      # but was it expanded?
      if(PROJECT_VERSION MATCHES Format)
        set(PROJECT_VERSION "unknown-version")
      endif(PROJECT_VERSION MATCHES Format)
228 229 230
      generate_version_gen_c(${PROJECT_VERSION} "source package")
    else(NOT EXISTS ${CMAKE_SOURCE_DIR}/src/version_gen.c)
      # no need to create version_gen.c if it's already shipped. that is for example the case with our release tarballs
231
      execute_process(
232
        COMMAND sh ${CMAKE_SOURCE_DIR}/tools/parse_version_c.sh ${CMAKE_SOURCE_DIR}/src/version_gen.c OUTPUT_STRIP_TRAILING_WHITESPACE
233 234 235
        OUTPUT_VARIABLE PROJECT_VERSION
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
      )
236
      # FIXME: (irrelevant) PROJECT_VERSION will not be updated automatically, until you rerun cmake
237
      # but generate_version target expects it to be in build dir, so we need to copy it
238 239
      add_custom_target(
        create_version_gen ALL
240 241
        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/src/version_gen.c ${CMAKE_BINARY_DIR}/src/version_gen.c
        DEPENDS ${CMAKE_SOURCE_DIR}/src/version_gen.c
242
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
243
        COMMENT "Updating version string (source package) - ${PROJECT_VERSION}"
244
      )
245
    endif(NOT EXISTS ${CMAKE_SOURCE_DIR}/src/version_gen.c)
246
  endif(NOT SOURCE_PACKAGE)
247 248
endif(DEFINED PROJECT_VERSION)

249 250
# needed to make sure that version string is actually updated.
add_custom_command(
251
  OUTPUT ${CMAKE_BINARY_DIR}/src/version_gen.c
252 253 254 255 256
  COMMAND ${CMAKE_COMMAND} -E echo
  DEPENDS create_version_gen
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

257
# WARNING: no target should reference version_gen.c directly. instead, they should add_dependencies(yourtarget generate_version)
258 259
add_custom_target(
  generate_version ALL
260
  DEPENDS ${CMAKE_BINARY_DIR}/src/version_gen.c
261 262
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
263

264 265 266 267 268 269
# Add a sensible build type default and warning because empty means no optimization and no debug info.
if(NOT CMAKE_BUILD_TYPE)
	message("WARNING: CMAKE_BUILD_TYPE is not defined!\n         Defaulting to CMAKE_BUILD_TYPE=RelWithDebInfo. Use ccmake to set a proper value.")
	SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)

270
if(CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$" AND SOURCE_PACKAGE)
271
  message(FATAL_ERROR "ERROR: Debug build type most likely isn't what you want, use RelWithDebInfo instead. If you're absolutely sure that this is what you want then just comment out this line.")
272 273
endif()

274
include(compiler-warnings)
275
include(windows-macros)
276

277 278
# Setting the runtime path works differently on OSX than on Linux or BSD.
# Hence use a variable that maps those in the correct way for each OS.
279
if(APPLE)
280
    # The string "@loader_path" should end up in the executable as-is.
281
    set(RPATH_DT "@loader_path")
282 283 284
else(APPLE)
    # Note that $ORIGIN is not a variable but has a special meaning at runtime.
    # The string "$ORIGIN" should end up in the executable as-is.
285
    set(RPATH_DT "$ORIGIN")
286
endif(APPLE)
287

288 289 290 291 292 293 294
if(NOT WIN32)
  # Windows doesn't know the concept of RPATHs :(
  set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
  set(CMAKE_INSTALL_RPATH ${RPATH_DT}/../${CMAKE_INSTALL_LIBDIR}/darktable)
endif(NOT WIN32)

295 296 297 298 299 300
# we need some external programs for building darktable
message(STATUS "Looking for external programs")
set(EXTERNAL_PROGRAMS_FOUND 1)

# we need perl for introspection
find_program(perl_BIN perl)
301
if(${perl_BIN} STREQUAL "perl_BIN-NOTFOUND")
302 303 304 305
  message(STATUS "Missing perl")
  set(EXTERNAL_PROGRAMS_FOUND 0)
else(${perl_BIN} STREQUAL "perl_BIN-NOTFOUND")
  message(STATUS "Found perl")
306 307
endif(${perl_BIN} STREQUAL "perl_BIN-NOTFOUND")

308 309 310 311 312 313 314 315 316
# we need intltool-merge for darktable.desktop
find_program(intltool_merge_BIN intltool-merge)
if(${intltool_merge_BIN} STREQUAL "intltool_merge_BIN-NOTFOUND")
  message(STATUS "Missing intltool-merge")
  set(EXTERNAL_PROGRAMS_FOUND 0)
else(${intltool_merge_BIN} STREQUAL "intltool_merge_BIN-NOTFOUND")
  message(STATUS "Found intltool-merge")
endif(${intltool_merge_BIN} STREQUAL "intltool_merge_BIN-NOTFOUND")

317 318 319
# we need desktop-file-validate to check darktable.desktop
find_program(desktop_file_validate_BIN desktop-file-validate)
if(${desktop_file_validate_BIN} STREQUAL "desktop_file_validate_BIN-NOTFOUND")
320 321
  message(STATUS "Missing desktop-file-validate, problems in darktable.desktop might go unnoticed")
  set(VALIDATE_DESKTOP_FILE 0)
322 323
else(${desktop_file_validate_BIN} STREQUAL "desktop_file_validate_BIN-NOTFOUND")
  message(STATUS "Found desktop-file-validate")
324
  set(VALIDATE_DESKTOP_FILE 1)
325 326
endif(${desktop_file_validate_BIN} STREQUAL "desktop_file_validate_BIN-NOTFOUND")

327
# we need appstream-util to check darktable.appdata.xml
328 329 330 331 332 333 334 335 336
if(VALIDATE_APPDATA_FILE)
  find_program(appstream_util_BIN appstream-util)
  if(${appstream_util_BIN} STREQUAL "appstream_util_BIN-NOTFOUND")
    message(STATUS "Missing appstream-util, problems in darktable.appdata.xml might go unnoticed")
    set(VALIDATE_APPDATA_FILE OFF)
  else(${appstream_util_BIN} STREQUAL "appstream_util_BIN-NOTFOUND")
    message(STATUS "Found appstream-util")
  endif(${appstream_util_BIN} STREQUAL "appstream_util_BIN-NOTFOUND")
endif(VALIDATE_APPDATA_FILE)
337

338 339 340
if(TESTBUILD_OPENCL_PROGRAMS)
  set(TESTBUILD_OPENCL_PROGRAMS OFF)

341 342 343 344 345 346 347 348 349
  macro(find_llvm versions)
    foreach(version ${versions})
      find_package(LLVM ${version} CONFIG)
      if(LLVM_FOUND)
        break()
      endif()
    endforeach()
  endmacro()

350
  # 3.9 is the first version with which this works.
351
  find_llvm("6.0;5.0;4.0;3.9")
352

353 354 355 356
  if (LLVM_FOUND)
    message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")

    find_program(CLANG_OPENCL_COMPILER
357
      NAMES clang-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} clang-${LLVM_PACKAGE_VERSION} clang${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR}
358 359 360 361 362 363
    )

    if (NOT ${CLANG_OPENCL_COMPILER} STREQUAL "CLANG_OPENCL_COMPILER-NOTFOUND")
      message(STATUS "Found clang compiler - ${CLANG_OPENCL_COMPILER}")

      find_path(CLANG_OPENCL_INCLUDE_DIR opencl-c.h
364
        HINTS ${LLVM_INSTALL_PREFIX}/lib/clang ${LLVM_INSTALL_PREFIX}/lib64/clang
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
        PATH_SUFFIXES include ${LLVM_PACKAGE_VERSION}/include
        NO_DEFAULT_PATH
      )

      if (NOT ${CLANG_OPENCL_INCLUDE_DIR} STREQUAL "CLANG_OPENCL_INCLUDE_DIR-NOTFOUND")
        message(STATUS "Found clang opencl-c.h header in ${CLANG_OPENCL_INCLUDE_DIR}")
        set(TESTBUILD_OPENCL_PROGRAMS ON)
      else()
        message(WARNING "Could not find clang opencl-c.h header include dir")
        message(WARNING "Test-compilation of OpenCL programs can not be done.")
      endif()
    else()
      message(WARNING "Could not find appropriate clang compiler")
      message(WARNING "Test-compilation of OpenCL programs can not be done.")
    endif()
  else()
    message(WARNING "Could not find LLVM 3.9+")
    message(WARNING "Test-compilation of OpenCL programs can not be done.")
  endif()
endif()

386
if(USE_OPENCL AND TESTBUILD_OPENCL_PROGRAMS)
387
  message(STATUS "Will be able to test-compile OpenCL programs. Nice.")
388
elseif(USE_OPENCL)
389 390 391
  message(STATUS "Test-compilation of OpenCL programs is disabled.")
endif()

392 393 394 395 396 397 398 399 400 401
# we need jsonschema to check noiseprofiles.json
find_program(jsonschema_BIN jsonschema)
if(${jsonschema_BIN} STREQUAL "jsonschema_BIN-NOTFOUND")
  message(STATUS "Missing jsonschema, problems in noiseprofiles.json might go unnoticed")
  set(VALIDATE_JSON 0)
else(${jsonschema_BIN} STREQUAL "jsonschema_BIN-NOTFOUND")
  message(STATUS "Found jsonschema")
  set(VALIDATE_JSON 1)
endif(${jsonschema_BIN} STREQUAL "jsonschema_BIN-NOTFOUND")

402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
# we need an xslt interpreter to generate preferences_gen.h and darktablerc
find_program(Xsltproc_BIN xsltproc)
if(${Xsltproc_BIN} STREQUAL "Xsltproc_BIN-NOTFOUND")
  message(STATUS "Missing xsltproc")
  find_program(Saxon_BIN saxon-xslt)
  if(${Saxon_BIN} STREQUAL "Saxon_BIN-NOTFOUND")
    message(STATUS "Missing saxon-xslt")
    message(STATUS "No xslt interpreter found")
    set(EXTERNAL_PROGRAMS_FOUND 0)
  else(${Saxon_BIN} STREQUAL "Saxon_BIN-NOTFOUND")
    message(STATUS "Found saxon-xslt")
  endif(${Saxon_BIN} STREQUAL "Saxon_BIN-NOTFOUND")
else(${Xsltproc_BIN} STREQUAL "Xsltproc_BIN-NOTFOUND")
  message(STATUS "Found xsltproc")
endif(${Xsltproc_BIN} STREQUAL "Xsltproc_BIN-NOTFOUND")

# do we have xmllint?
if(USE_XMLLINT)
  find_program(Xmllint_BIN xmllint)
  if(${Xmllint_BIN} STREQUAL "Xmllint_BIN-NOTFOUND")
    message(STATUS "Missing xmllint")
    set(USE_XMLLINT OFF)
  else(${Xmllint_BIN} STREQUAL "Xmllint_BIN-NOTFOUND")
    message(STATUS "Found xmllint")
  endif(${Xmllint_BIN} STREQUAL "Xmllint_BIN-NOTFOUND")
endif(USE_XMLLINT)

# done with looking for programs
if(NOT EXTERNAL_PROGRAMS_FOUND)
  message(FATAL_ERROR "Some external programs couldn't be found")
else(NOT EXTERNAL_PROGRAMS_FOUND)
  message(STATUS "All external programs found")
endif(NOT EXTERNAL_PROGRAMS_FOUND)

436
# The path can be modified by setting CMAKE_INSTALL_LOCALEDIR
437
if(USE_NLS)
438
    find_package(Gettext)
439 440 441 442 443 444
    if(GETTEXT_MSGFMT_EXECUTABLE)
        message(STATUS "Found msgfmt to convert .po file. Translation enabled")
        add_subdirectory(po)
    else()
        message(STATUS "Cannot find msgfmt to convert .po file. Translation won't be enabled")
    endif()
445
endif(USE_NLS)
446

447
# needed to generate file "preferences_gen.h" accordingly
448
if(USE_OPENCL)
449 450 451
	SET(HAVE_OPENCL 1)
else()
	SET(HAVE_OPENCL 0)
452
endif(USE_OPENCL)
453

454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
if(NOT SOURCE_PACKAGE AND NOT (CMAKE_VERSION VERSION_LESS 3.3) AND DEFINED ENV{_DO_IWYU})
  find_program(iwyu_path NAMES include-what-you-use iwyu)

  if(iwyu_path)
    set(DT_CMAKE_INCLUDE_WHAT_YOU_USE ${iwyu_path} -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/iwyu.imp -Xiwyu --prefix_header_includes=add)
  endif()

  find_program(iwyu_tool_path NAMES iwyu_tool.py)
  if (iwyu_tool_path)
    add_custom_command(
      OUTPUT "${CMAKE_BINARY_DIR}/iwyu.log"
      COMMAND "${iwyu_tool_path}" -v -p "${CMAKE_BINARY_DIR}"
              -- --mapping_file=${CMAKE_SOURCE_DIR}/iwyu.imp
              --prefix_header_includes=add 2>
              "${CMAKE_BINARY_DIR}/iwyu.log"
      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
      COMMENT "Running include-what-you-use tool"
      VERBATIM
    )
    add_custom_target(iwyu
      DEPENDS "${CMAKE_BINARY_DIR}/iwyu.log"
      VERBATIM
    )
  endif()

  find_program(fix_includes_path NAMES fix_includes.py)
  if (fix_includes_path)
    add_custom_target(iwyu_fix
      COMMAND "${fix_includes_path}" --noblank_lines --comments
              --nosafe_headers < "${CMAKE_BINARY_DIR}/iwyu.log" || true
      COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/iwyu.log"
      DEPENDS "${CMAKE_BINARY_DIR}/iwyu.log"
      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
      COMMENT "Running include-what-you-use fix_includes tool"
      VERBATIM
    )
  endif()
endif()

Henrik Andersson's avatar
Henrik Andersson committed
493 494 495
#
# Test SSE level
#
johannes hanika's avatar
johannes hanika committed
496 497 498 499 500 501 502 503 504 505 506 507 508
# if(NOT USE_SSE_FLAG)
# 	set(SSE_C_TESTS "sse4" "sse3" "sse2" "sse")
# 	message("-- Checking SSE instructions support by current CPU")
# 	foreach(sse_test ${SSE_C_TESTS})
# 		if(NOT SSE_FOUND)
# 			if(WIN32)
# 				set(SSE_CHECK_COMMAND "FAILURE")
# 			elseif(APPLE)
# 				set(SSE_CHECK_COMMAND sysctl -a | grep ${sse_test})
# 			else()#other os
# 				set(SSE_CHECK_COMMAND grep ${sse_test} /proc/cpuinfo)
# 			endif(WIN32)
# 			execute_process(COMMAND ${SSE_CHECK_COMMAND} RESULT_VARIABLE ret_var OUTPUT_VARIABLE out_var)
509
#
johannes hanika's avatar
johannes hanika committed
510 511 512 513 514
# 			if(ret_var EQUAL 0) # grep returns 0 on success
# 				set(SSE_FOUND TRUE)
# 				message("--  ${sse_test} detected and working.")
# 				set(USE_SSE_SET ${sse_test})
# 			endif(ret_var EQUAL 0)
515
#
johannes hanika's avatar
johannes hanika committed
516 517 518
# 		endif(NOT SSE_FOUND)
# 	endforeach(sse_test)
# endif(NOT USE_SSE_FLAG)
519
#
johannes hanika's avatar
johannes hanika committed
520 521 522 523
# # set the SSE
# if(USE_SSE_SET)
# 	set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-m${USE_SSE_SET}")
# endif(USE_SSE_SET)
524 525 526

# setup some theme specific variables
set(THEME hicolor)
527
set(THEME_DIRECTORY "${CMAKE_INSTALL_DATAROOTDIR}/icons/${THEME}")
528

529
# we need some specific functions:
530 531 532 533 534 535 536 537
if(NOT WIN32)
  IF(CMAKE_SYSTEM MATCHES "SunOS.*")
  add_definitions("-D_XOPEN_SOURCE=600")
  elseif(CMAKE_SYSTEM_NAME MATCHES "^(DragonFly|FreeBSD|NetBSD|OpenBSD)$")
  else(CMAKE_SYSTEM MATCHES "SunOS.*")
  add_definitions("-D_XOPEN_SOURCE=700")
  endif(CMAKE_SYSTEM MATCHES "SunOS.*")
endif(NOT WIN32)
538

539 540 541 542
# Set default component name - that way external modules like RawSpeed will install their
# materials under the default component and not under 'Unspecified'
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME DTApplication)

543
# lets continue into build directories
Unknown's avatar
Unknown committed
544
include(data/supported_extensions.cmake) # this file needs to be included first as it gets amended in src/
545
add_subdirectory(src) # src/ needs to be before data/ so that the correct CSS file gets installed
546
add_subdirectory(data)
547
add_subdirectory(doc)
548
add_subdirectory(tools)
549

550 551 552 553 554
# This contains fixup_bundle
# And adding a separate subderectory as a last one will make sure
# that fixup_bundle will run _after_ all files has been installed
add_subdirectory(packaging)

johannes hanika's avatar
johannes hanika committed
555
include(cmake/darktable-packaging.cmake)
556

557 558 559 560 561 562 563 564
# uninstall target
configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/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)