Style and formatting cleanup of /CMakeLists.txt, #3678

This commit is contained in:
Morgan Hardwood
2017-04-09 15:08:32 +02:00
parent 36cd8b7787
commit cd731e1015

View File

@@ -1,26 +1,27 @@
if(WIN32)
cmake_minimum_required(VERSION 2.8.4)
else (WIN32)
else()
cmake_minimum_required(VERSION 2.6)
endif (WIN32)
endif()
# must stay before the 'project' command
# Must stay before the 'project' command:
if(${CMAKE_EXTRA_GENERATOR} MATCHES "Eclipse CDT4")
set(CMAKE_CXX_COMPILER_ARG1 "-std=c++11" CACHE STRING "C++ version for eclipse" FORCE)
# users building with Eclipse should set CMAKE_ECLIPSE_VERSION through the command line to their current version of Eclipse
# Users building with Eclipse should set CMAKE_ECLIPSE_VERSION through the
# command line to their current version of Eclipse:
#set(CMAKE_ECLIPSE_VERSION "4.6.0" CACHE STRING "Eclipse version" FORCE)
endif()
PROJECT(RawTherapee)
# the default target is 'Debug'
# The default target is Debug:
if(CMAKE_BUILD_TYPE STREQUAL "")
set (CMAKE_BUILD_TYPE Debug CACHE STRING "One of: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
set (CMAKE_BUILD_TYPE Debug CACHE STRING "One of: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPER_CMAKE_BUILD_TYPE)
# Set required C and C++ standards and check GCC version
# Set required C and C++ standards and check GCC version:
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
@@ -28,7 +29,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_L
message(FATAL_ERROR "Building RawTherapee requires using GCC version 4.9 or higher!")
endif()
# We might want to build using the old C++ ABI, even when using a new GCC version
# We might want to build using the old C++ ABI, even when using a new GCC version:
if(USE_OLD_CXX_ABI)
add_definitions (-D_GLIBCXX_USE_CXX11_ABI=0)
endif()
@@ -44,17 +45,17 @@ message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
# Examples: "" = ~/.config/RawTherapee, "latesttag" = ~/.config/RawTherapee4.2, "_testing" = ~/.config/RawTherapee_testing
# Cache name suffix examples: "" = ~/.config/RawTherapee, "5" = ~/.config/RawTherapee-5, "_testing" = ~/.config/RawTherapee_testing
set(CACHE_NAME_SUFFIX "" CACHE STRING "RawTherapee's cache folder suffix")
# By default, we don't use specific processor target, so PROC_TARGET_NUMBER is set to 0. If can specify other values to select specific
# processor targets, which list can be found in ProcessorTargets.cmake.
# By default we don't use a specific processor target, so PROC_TARGET_NUMBER is set to 0.
# Specify other values to optimize for specific processor architecture as listed in ProcessorTargets.cmake:
set(PROC_TARGET_NUMBER 0 CACHE STRING "Selected target processor from the list above (taken from ProcessorTargets.cmake)")
# The following line set special compilation flags for RTEngine, and will be added to CMAKE_CXX_FLAGS
# Set special compilation flags for rtengine which get added to CMAKE_CXX_FLAGS:
set(RTENGINE_CXX_FLAGS "" CACHE STRING "Special compilation flags for RTEngine")
#loading the processor targets list
# Loads the ProcessorTargets list:
include(ProcessorTargets.cmake)
set(PROC_LABEL "undefined" CACHE STRING "Target processor label, unused if PROC_TARGET_NUMBER = 0 or 2")
set(PROC_FLAGS "" CACHE STRING "Target processor related build/link flags")
@@ -73,32 +74,31 @@ if (UNIX AND PROC_LABEL STREQUAL "undefined")
endif()
endif()
# if it exists, the PROC_FORCED_LABEL value is loaded in PROC_LABEL to override the one of ProcessorTargets
# If PROC_FORCED_LABEL exists, its value is loaded in PROC_LABEL to override the one from ProcessorTargets:
if(DEFINED PROC_FORCED_LABEL)
set(PROC_LABEL ${PROC_FORCED_LABEL})
endif (DEFINED PROC_FORCED_LABEL)
endif()
# adding the proc flags to the build flags
# Add the proc flags to the build flags:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PROC_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROC_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PROC_FLAGS}")
#stop compile on typos like std:swap (missing colon will be detected as unused label)
# Stop compilation on typos such as std:swap (missing colon will be detected as unused label):
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=unused-label")
if(WIN32)
# we additionnally look in the MinGW path first then in the Gtkmm path,
# so if you wish to build some dependant library, you have to install them in MinGW to use them
# Add additional paths. Look in the MinGW path first, then in the Gtkmm path.
# If you wish to build some dependent libraries, you have to install them in MinGW to use them:
set(CMAKE_PREFIX_PATH $ENV{MINGW_BASEPATH} $ENV{GTKMM_BASEPATH} CACHE STRING "Additional search paths")
endif (WIN32)
endif()
if(APPLE)
if (CMAKE_CXX_COMPILER MATCHES "g\\+\\+-mp-4.[5-8]" OR
CMAKE_CXX_COMPILER_ARG1 MATCHES "g\\+\\+-mp-4.[5-8]")
if(CMAKE_CXX_COMPILER MATCHES "g\\+\\+-mp-4.[5-8]" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "g\\+\\+-mp-4.[5-8]")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /usr/lib/libstdc++.6.dylib")
message(STATUS "CMAKE_CXX_COMPILER is MacPorts GCC.\n CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
endif()
endif (APPLE)
endif()
option(USE_EXPERIMENTAL_LANG_VERSIONS "Build RT with -std=c++0x" OFF)
option(BUILD_SHARED "Build rawtherapee with shared libraries" OFF)
@@ -112,108 +112,108 @@ option (STRICT_MUTEX "True (recommended): MyMutex will behave like POSIX Mutex;
option(TRACE_MYRWMUTEX "Trace RT's custom R/W Mutex (Debug builds only); redirecting std::out to a file is strongly recommended!" OFF)
option(AUTO_GDK_FLUSH "Use gdk_flush on all gdk_thread_leave other than the GUI thread; set it ON if you experience X Server warning/errors" OFF)
# set install directories
# Set installation directories:
if(WIN32 OR APPLE)
if(BUILD_BUNDLE)
message(STATUS "You have set BUILD_BUNDLE=ON but this is not necessary - the option if force to ON on Windows and macOS.")
endif()
set (BUILD_BUNDLE ON FORCE)
endif(WIN32 OR APPLE)
endif()
if(NOT DEFINED BUNDLE_BASE_INSTALL_DIR)
if(APPLE)
set(BUNDLE_BASE_INSTALL_DIR "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MacOS")
else (APPLE)
else()
set(BUNDLE_BASE_INSTALL_DIR "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
endif (APPLE)
endif (NOT DEFINED BUNDLE_BASE_INSTALL_DIR)
endif()
endif()
if(BUILD_BUNDLE)
set(BINDIR .)
set(CMAKE_INSTALL_PREFIX "${BUNDLE_BASE_INSTALL_DIR}")
endif (BUILD_BUNDLE)
endif()
if(NOT DEFINED BINDIR)
set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
endif (NOT DEFINED BINDIR)
endif()
if(NOT DEFINED DATADIR)
if(BUILD_BUNDLE)
if(APPLE)
set(DATADIR "../Resources")
else (APPLE)
else()
set(DATADIR .)
endif (APPLE)
else (BUILD_BUNDLE)
endif()
else()
set(DATADIR "${CMAKE_INSTALL_PREFIX}/share/rawtherapee")
endif (BUILD_BUNDLE)
endif (NOT DEFINED DATADIR)
endif()
endif()
if(NOT DEFINED LIBDIR)
if(BUILD_BUNDLE)
if(APPLE)
set(LIBDIR "../Frameworks")
else (APPLE)
else()
set(LIBDIR .)
endif (APPLE)
else (BUILD_BUNDLE)
endif()
else()
# Respect CMAKE_INSTALL_LIBDIR if set
if(DEFINED CMAKE_INSTALL_LIBDIR)
if(IS_ABSOLUTE "${LIBDIR}")
set(LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else (IS_ABSOLUTE "${LIBDIR}")
else()
set(LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif (IS_ABSOLUTE "${LIBDIR}")
else (DEFINED CMAKE_INSTALL_LIBDIR)
endif()
else()
set(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
endif (DEFINED CMAKE_INSTALL_LIBDIR)
endif (BUILD_BUNDLE)
endif (NOT DEFINED LIBDIR)
endif()
endif()
endif()
if(NOT DEFINED DOCDIR)
if(BUILD_BUNDLE)
set(DOCDIR "${DATADIR}/share/doc")
else (BUILD_BUNDLE)
else()
set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/rawtherapee")
endif (BUILD_BUNDLE)
endif (NOT DEFINED DOCDIR)
endif()
endif()
if(NOT DEFINED CREDITSDIR)
if(BUILD_BUNDLE)
set(CREDITSDIR "${DATADIR}")
else (BUILD_BUNDLE)
else()
set(CREDITSDIR "${CMAKE_INSTALL_PREFIX}/share/doc/rawtherapee")
endif (BUILD_BUNDLE)
endif (NOT DEFINED CREDITSDIR)
endif()
endif()
if(NOT DEFINED LICENCEDIR)
if(BUILD_BUNDLE)
set(LICENCEDIR "${DATADIR}")
else (BUILD_BUNDLE)
else()
set(LICENCEDIR "${CMAKE_INSTALL_PREFIX}/share/doc/rawtherapee")
endif (BUILD_BUNDLE)
endif (NOT DEFINED LICENCEDIR)
endif()
endif()
if(NOT DEFINED DESKTOPDIR)
if(UNIX)
set(DESKTOPDIR "${CMAKE_INSTALL_PREFIX}/share/applications") # Absolute
#set(DESKTOPDIR "${DATADIR}/share/applications") # Relative
endif (UNIX)
endif (NOT DEFINED DESKTOPDIR)
endif()
endif()
if(NOT DEFINED ICONSDIR)
if(UNIX)
set(ICONSDIR "${CMAKE_INSTALL_PREFIX}/share/icons")
endif (UNIX)
endif (NOT DEFINED ICONSDIR)
endif()
endif()
if(NOT DEFINED APPDATADIR)
if(UNIX)
set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/appdata")
endif (UNIX)
endif (NOT DEFINED APPDATADIR)
endif()
endif()
# Enforce absolute paths for non-bundle builds.
# Enforce absolute paths for non-bundle builds:
if(NOT BUILD_BUNDLE)
if(NOT(IS_ABSOLUTE "${BINDIR}"))
message(FATAL_ERROR "The BINDIR path has to be absolute, or use -DBUILD_BUNDLE=ON")
@@ -230,27 +230,27 @@ if(NOT BUILD_BUNDLE)
endif()
endif()
# MyMutex
# MyMutex:
if(STRICT_MUTEX OR UPPER_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_definitions(-DSTRICT_MUTEX=1)
else (STRICT_MUTEX OR UPPER_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
else()
add_definitions(-DSTRICT_MUTEX=0)
endif (STRICT_MUTEX OR UPPER_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
endif()
# MyRWMutex
# MyRWMutex:
if(TRACE_MYRWMUTEX)
add_definitions(-DTRACE_MYRWMUTEX=1)
else (TRACE_MYRWMUTEX)
else()
add_definitions(-DTRACE_MYRWMUTEX=0)
endif (TRACE_MYRWMUTEX)
endif()
if(AUTO_GDK_FLUSH)
add_definitions(-DAUTO_GDK_FLUSH=1)
else (AUTO_GDK_FLUSH)
else()
add_definitions(-DAUTO_GDK_FLUSH=0)
endif (AUTO_GDK_FLUSH)
endif()
# check for libraries
# Check for libraries:
find_package(PkgConfig)
pkg_check_modules (GTK REQUIRED gtk+-3.0>=3.16)
pkg_check_modules (GLIB2 REQUIRED glib-2.0>=2.44)
@@ -262,19 +262,19 @@ pkg_check_modules (GIOMM REQUIRED giomm-2.4>=2.44)
pkg_check_modules (GTHREAD REQUIRED gthread-2.0>=2.44)
pkg_check_modules (GOBJECT REQUIRED gobject-2.0>=2.44)
pkg_check_modules (SIGC REQUIRED sigc++-2.0>=2.3.1)
# NOTE: The new mechanism has been tested with BUILD_SHARED = OFF
if(WIN32)
add_definitions(-DWIN32)
add_definitions(-D_WIN32)
if(MINGW)
add_definitions(-D__MINGW32__)
endif (MINGW)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_definitions(-DWINVER=0x0501)
endif (CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()
set(EXTRA_LIB "-lws2_32 -lshlwapi")
endif (WIN32)
# you may need lcms v1.xx for older version : pkg_check_modules (LCMS REQUIRED lcms<=1.99)
endif()
pkg_check_modules(LCMS REQUIRED lcms2>=2.6)
pkg_check_modules(EXPAT REQUIRED expat>=2.1)
pkg_check_modules(FFTW3F REQUIRED fftw3f)
@@ -284,51 +284,51 @@ find_package (PNG REQUIRED)
find_package(TIFF REQUIRED)
find_package(ZLIB REQUIRED)
# link witz bzip
# Link with bzip:
if(WITH_BZIP)
find_package(BZip2)
if(BZIP2_FOUND)
add_definitions(-DBZIP_SUPPORT)
set(EXTRA_INCDIR ${BZIP2_INCLUDE_DIR})
set(EXTRA_LIB ${EXTRA_LIB} ${BZIP2_LIBRARIES})
endif (BZIP2_FOUND)
endif (WITH_BZIP)
endif()
endif()
#Check for libcanberra-gtk3 (sound events on Linux)
# Check for libcanberra-gtk3 (sound events on Linux):
if(UNIX AND(NOT APPLE))
pkg_check_modules(CANBERRA-GTK REQUIRED libcanberra-gtk3)
endif (UNIX AND (NOT APPLE))
endif()
if(WITH_MYFILE_MMAP)
add_definitions(-DMYFILE_MMAP)
endif (WITH_MYFILE_MMAP)
endif()
if(WITH_LTO)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
endif (WITH_LTO)
endif()
if(WITH_SAN)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${WITH_SAN}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${WITH_SAN}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${WITH_SAN}")
endif (WITH_SAN)
endif()
if(WITH_PROF)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
endif (WITH_PROF)
endif()
if(OPTION_OMP)
find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -Werror=unknown-pragmas -Wall -Wno-unused-result -Wno-deprecated-declarations")
endif (OPENMP_FOUND)
endif (OPTION_OMP)
endif()
endif()
# find out whether we are building out of source
# Find out whether we are building out of source:
get_filename_component(ABS_SOURCE_DIR "${PROJECT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(ABS_BINARY_DIR "${CMAKE_BINARY_DIR}" ABSOLUTE)
set(OUT_OF_SOURCE_BUILD TRUE)
@@ -337,37 +337,35 @@ if (ABS_SOURCE_DIR STREQUAL ABS_BINARY_DIR)
message(WARNING "You are performing an in-source build. This is discouraged. For an explanation and the advantages of out-of-source builds, please refer to http://www.cmake.org/Wiki/CMake_FAQ#What_is_an_.22out-of-source.22_build.3F")
endif()
# XXX remove files triggering the below check to prevent every developer from
# needing manual manual work. We will remove this after some time to have a
# clean build system without file modifications in the source tree again.
# Remove files which could require manual work.
# We will remove this after some time to have a clean build system without file modifications in the source tree again. (?)
set(OOSB_FILES "${PROJECT_SOURCE_DIR}/rtdata/rawtherapee.desktop" "${PROJECT_SOURCE_DIR}/rtgui/version.h" "${PROJECT_SOURCE_DIR}/rtgui/config.h" "${PROJECT_SOURCE_DIR}/AboutThisBuild.txt")
if(OUT_OF_SOURCE_BUILD)
foreach(f ${OOSB_FILES})
file(REMOVE "${f}")
endforeach(f)
endforeach()
endif()
# check for generated files in the source tree which should not be there when
# doing out of source builds. Without checking for this it might happen that old
# versions are used for the compilation
# Check for generated files in the source tree which should not be there when doing an out-of-source build.
# Without checking for this it might happen that old versions are used for the compilation:
if(OUT_OF_SOURCE_BUILD)
foreach(f ${OOSB_FILES})
if(EXISTS "${f}")
message(SEND_ERROR "Generated \"${f}\" found inside the source tree. Please remove it as it is a relic of the old build system and prevents valid compilation now.")
endif()
endforeach(f)
endforeach()
endif()
## BEGIN: Create AboutThisBuild.txt and other version-dependent files.
# set the bit number information of the platform
### Start generating AboutThisBuild.txt
# Set the platform bit-depth:
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(PROC_BIT_DEPTH 32 bits)
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
elseif()
set(PROC_BIT_DEPTH 64 bits)
endif (CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()
# Get compiler name and version
# only cmake > 2.8.7 knows CMAKE_*_COMPILER_VERSION
# Get compiler name and version.
# Only CMake > 2.8.7 knows CMAKE_*_COMPILER_VERSION
if(CMAKE_VERSION VERSION_GREATER 2.8.7)
get_filename_component(COMPILER_INFO ${CMAKE_C_COMPILER} NAME_WE)
set(COMPILER_INFO "${COMPILER_INFO} ${CMAKE_C_COMPILER_VERSION}")
@@ -376,7 +374,7 @@ else ()
set(COMPILER_INFO "gcc ${GCC_VERSION}")
endif()
# Get c++ and linker flags for rtengine (the gui's c++ flags may have less flags)
# Get C++ and linker flags for rtengine (the GUI's C++ flags may have fewer flags):
set(CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${UPPER_CMAKE_BUILD_TYPE}} ${RTENGINE_CXX_FLAGS}")
set(LFLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${UPPER_CMAKE_BUILD_TYPE}}")
@@ -402,37 +400,39 @@ elseif (APPLE)
-DCXX_FLAGS:STRING=${CXX_FLAGS}
-DLFLAGS:STRING=${LFLAGS}
-DCOMPILER_INFO:STRING=${COMPILER_INFO})
else (WIN32)
else()
list(APPEND ABOUT_COMMAND_WITH_ARGS -DSYSTEM:STRING=Linux
-DCXX_FLAGS:STRING=${CXX_FLAGS}
-DLFLAGS:STRING=${LFLAGS}
-DCOMPILER_INFO:STRING=${COMPILER_INFO})
endif (WIN32)
endif()
list(APPEND ABOUT_COMMAND_WITH_ARGS -P "${PROJECT_SOURCE_DIR}/UpdateInfo.cmake")
add_custom_target(UpdateInfo ALL
COMMAND ${ABOUT_COMMAND_WITH_ARGS}
COMMENT "Creating AboutThisBuild.txt and other version-dependent files")
## END: Generating AboutThisBuild.txt
### End generating AboutThisBuild.txt
install(FILES AUTHORS.txt DESTINATION "${CREDITSDIR}")
install(FILES LICENSE.txt DESTINATION "${LICENCEDIR}")
install(FILES "${CMAKE_BINARY_DIR}/AboutThisBuild.txt" DESTINATION "${CREDITSDIR}")
install(FILES RELEASE_NOTES.txt DESTINATION "${CREDITSDIR}" OPTIONAL)
if(UNIX OR WIN32)
install(FILES "${PROJECT_SOURCE_DIR}/doc/manpage/rawtherapee.1" DESTINATION "${DOCDIR}/man")
endif()
if(WIN32)
install(DIRECTORY "licenses" DESTINATION "${LICENCEDIR}")
endif()
if(UNIX)
install(FILES rawtherapee.appdata.xml DESTINATION "${APPDATADIR}")
endif()
add_subdirectory(rtexif)
add_subdirectory(rtengine)
add_subdirectory(rtgui)
add_subdirectory(rtdata)