Warning, /libraries/perceptualcolor/src/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com> 0002 # SPDX-License-Identifier: BSD-2-Clause OR MIT 0003 0004 0005 0006 0007 0008 ################# Version number ################# 0009 # Substitutes all occurrences of @MAJOR_VERSION@… and similar declarations 0010 # in the source code file by the actual value in CMake: 0011 configure_file( 0012 # Input: 0013 version.in.hpp 0014 # Output: 0015 ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h 0016 ) 0017 # TODO Also configure rpm.spec and Doxygen files with this version information. 0018 0019 0020 0021 0022 0023 ################# Setup source code ################# 0024 # Set the sources for our library 0025 set(library_SRC 0026 absolutecolor.cpp 0027 abstractdiagram.cpp 0028 asyncimageproviderbase.cpp 0029 asyncimagerendercallback.cpp 0030 asyncimagerenderthread.cpp 0031 chromahuediagram.cpp 0032 chromahueimageparameters.cpp 0033 chromalightnessdiagram.cpp 0034 chromalightnessimageparameters.cpp 0035 colordialog.cpp 0036 colorpatch.cpp 0037 colorwheel.cpp 0038 colorwheelimage.cpp 0039 extendeddoublevalidator.cpp 0040 genericcolor.cpp 0041 gradientimageparameters.cpp 0042 gradientslider.cpp 0043 helper.cpp 0044 helperconversion.cpp 0045 helpermath.cpp 0046 initializelibraryresources.cpp 0047 initializetranslation.cpp 0048 interlacingpass.cpp 0049 iohandlerfactory.cpp 0050 languagechangeeventfilter.cpp 0051 lchadouble.cpp 0052 lchdouble.cpp 0053 multispinbox.cpp 0054 multispinboxsection.cpp 0055 perceptualsettings.cpp 0056 polarpointf.cpp 0057 rgbcolor.cpp 0058 rgbcolorspace.cpp 0059 rgbcolorspacefactory.cpp 0060 screencolorpicker.cpp 0061 settingbase.cpp 0062 settings.cpp 0063 settranslation.cpp 0064 staticasserts.cpp 0065 swatchbook.cpp 0066 version.cpp 0067 wheelcolorpicker.cpp 0068 ) 0069 qt_add_resources( 0070 library_SRC # existing source list 0071 resources.qrc # File with list of Qt resource to be added 0072 # NOTE Starting with Qt6, it will no longer be necessary to have a 0073 # .qrc file, but the list of files can be passed in the very same 0074 # qt_add_resources() command. 0075 ) 0076 # NOTE Keep the following list synchronized 0077 # between scripts/static-codecheck.sh and src/CMakeLists.txt 0078 set(lib_PUBLICHEADERS 0079 abstractdiagram.h 0080 chromahuediagram.h 0081 colordialog.h 0082 colorpatch.h 0083 colorwheel.h 0084 constpropagatinguniquepointer.h 0085 gradientslider.h 0086 importexport.h 0087 lchadouble.h 0088 lchdouble.h 0089 multispinbox.h 0090 multispinboxsection.h 0091 rgbcolorspacefactory.h 0092 settranslation.h 0093 wheelcolorpicker.h 0094 ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h 0095 ) 0096 # TODO Also explicitly list all private headers to get more stable CMake 0097 # and make sure these files pop up in IDEs. 0098 0099 0100 0101 0102 0103 ################# Translation ################# 0104 get_filename_component(absolute_poqm_directory "../poqm" ABSOLUTE) 0105 file( 0106 # TODO Is it possible to get rid of GLOB_RECURSE? 0107 GLOB_RECURSE po_file_list # Name of the output variable. 0108 LIST_DIRECTORIES FALSE 0109 # CMake will add logic to the main build system check target to 0110 # rerun the flagged GLOB commands at build time: 0111 CONFIGURE_DEPENDS 0112 # Examples of recursive globing include: 0113 # /dir/*.py - match all python files in /dir and subdirectories(!) 0114 "${absolute_poqm_directory}/*/perceptualcolor-0_qt.po" 0115 ) 0116 # Generate a .qrc file (list of .qm files to include) and the targets 0117 # that will produce the individual .qm files. 0118 set(qrc_file "${CMAKE_CURRENT_BINARY_DIR}/resourcelist.qrc") 0119 file( 0120 WRITE 0121 # Filename: 0122 ${qrc_file} 0123 # Content to write: 0124 "<!DOCTYPE RCC>\n" 0125 "<RCC version=\"1.0\">\n" 0126 " <qresource prefix=\"PerceptualColor/i18n\">\n") 0127 include(ECMPoQmTools) 0128 foreach(po_file_original ${po_file_list}) 0129 get_filename_component(po_dir ${po_file_original} DIRECTORY) 0130 get_filename_component(lang ${po_dir} NAME) 0131 # NOTE ECMPoQmTools provides also ecm_install_po_files_as_qm to 0132 # conveniently generate and install qm files as individual files, 0133 # and ecm_create_qm_loader to conveniently load the translations 0134 # automatically. However, currently we compile the translation 0135 # into the library binary itself. First, this avoids that 0136 # translations can ever be lost. Second, ecm_create_qm_loader does 0137 # not work on static libraries. So ecm_process_po_files_as_qm is a 0138 # safer choice. However, its API documentation does not explain in 0139 # which destination folder the generated qm files will be stored. 0140 # Indeed, the destination folder has changed in the past: 0141 # https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/351 0142 # Therefore, we use our own copy of ECMPoQmTools (located at 0143 # cmake/Modules) to make sure we get a defined behaviour. 0144 ecm_process_po_files_as_qm( 0145 ${lang} 0146 ALL # Add this target to the ALL target. 0147 PO_FILES ${po_file_original}) 0148 # The attributes threshold="100" compress-algo="none" will prevent these 0149 # files from being compressed. This is because there were discussions 0150 # that QTranslator does not load compressed resourced, but only 0151 # uncompressed resources (https://forum.qt.io/post/368666). As the 0152 # translations are not big anyway, we try to prevent problems and 0153 # disable the compression. 0154 file( 0155 APPEND ${qrc_file} 0156 " <file " 0157 "threshold=\"100\" " 0158 "compress-algo=\"none\" " 0159 "alias=\"localization.${lang}.qm\">" 0160 "ECMPoQm/${lang}/perceptualcolor-0_qt.qm" 0161 "</file>\n") 0162 endforeach() 0163 file( 0164 APPEND 0165 # File to which append some content: 0166 ${qrc_file} 0167 # Content to append: 0168 " </qresource>\n" 0169 "</RCC>\n") 0170 # Add all resources from the .qrt file to our C++ sources 0171 # so they will get compiled in. 0172 qt_add_resources( 0173 library_SRC # existing source list 0174 ${qrc_file} # File with list of Qt resource to be added 0175 # NOTE Starting with Qt6, it will no longer be necessary to have a 0176 # .qrc file, but the list of files can be passed in the very same 0177 # qt_add_resources() command. Problem: The attributes 0178 # threshold="100" compress-algo="none" (see explication above) 0179 # cannot be specified than. 0180 ) 0181 0182 0183 0184 0185 0186 ################# Build library ################# 0187 # For the library name, we follow the KDE policy: 0188 # https://community.kde.org/Policies/New_KDE_Library_API_Policy#Library_Naming 0189 set(LIBRARY_NAME "perceptualcolor-${MAJOR_VERSION}") 0190 # Add library. If it will build as STATIC or as SHARED library is not 0191 # hardcoded, so add_library() it use BUILD_SHARED_LIBS to decide. 0192 add_library(${LIBRARY_NAME}) 0193 # The headers have to be added here explicitly because otherwise Qt’s MOC 0194 # would not find them because they are not in the same directory as the 0195 # corresponding .cpp files 0196 # 0197 # target_sources should normally always use PRIVATE. Details: 0198 # crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources 0199 target_sources( 0200 ${LIBRARY_NAME} 0201 PRIVATE 0202 ${library_SRC} 0203 ${lib_PUBLICHEADERS}) 0204 # Setting the symbol visibility: 0205 if(BUILD_SHARED_LIBS) 0206 target_compile_definitions( 0207 ${LIBRARY_NAME} 0208 PRIVATE PERCEPTUALCOLORLIB_BUILD_DYNAMIC_LIBRARY) 0209 else() 0210 target_compile_definitions( 0211 ${LIBRARY_NAME} 0212 PUBLIC PERCEPTUALCOLORLIB_STATIC) 0213 endif() 0214 set_target_properties( 0215 ${LIBRARY_NAME} PROPERTIES 0216 # By default, on Windows all symbols are hidden except those that are 0217 # explicitly marked for export using the "__declspec(dllexport)" 0218 # or "__declspec(dllimport)" keywords in the code. On Unix-based systems, 0219 # however, all symbols are exported by default unless they are explicitly 0220 # marked as hidden. To achieve the same behavior as on Windows, set 0221 # the "CXX_VISIBILITY_PRESET" property to "hidden" in CMake to hide all 0222 # symbols by default, unless they are explicitly marked for export using 0223 # compiler-specific attributes. 0224 CXX_VISIBILITY_PRESET "hidden" 0225 VISIBILITY_INLINES_HIDDEN TRUE 0226 VERSION "${FULL_VERSION}" 0227 SOVERSION "${MAJOR_VERSION}" 0228 PUBLIC_HEADER "${lib_PUBLICHEADERS}") 0229 target_include_directories( 0230 ${LIBRARY_NAME} 0231 PUBLIC 0232 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/> 0233 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated/> 0234 $<INSTALL_INTERFACE:include/${LIBRARY_NAME}/> 0235 PRIVATE 0236 "${CMAKE_CURRENT_SOURCE_DIR}/" 0237 "${LCMS2_INCLUDE_DIRS}") 0238 # target_link_libraries, despite its name, does not only mean “link”, but 0239 # actually rather “use”. It uses transitive dependencies: 0240 # - If only our source files #include headers of the external library: PRIVATE 0241 # - If only our header files #include headers of the external library: INTERFACE 0242 # - If both (our source files AND our header files) #include headers of external 0243 # library: PUBLIC 0244 # Than, CMake will make sure that targets that depend on our library will 0245 # get the correct and necessary include directories and linking options 0246 # automatically. 0247 # For details, see https://cmake.org/pipermail/cmake/2016-May/063400.html 0248 target_link_libraries( 0249 ${LIBRARY_NAME} 0250 # TODO We could remove the Qt::Concurrent (only) if we were absolutely sure 0251 # that we will not need it in the future either. Otherwise, it’s better 0252 # to keep it, for future binary compatibility. 0253 PUBLIC 0254 Qt::Core Qt::Gui Qt::Widgets Qt::DBus Qt::Concurrent Qt::Svg 0255 PRIVATE 0256 ${LCMS2_LIBRARIES}) 0257 install( 0258 DIRECTORY 0259 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBRARY_NAME}") 0260 install( 0261 # On Linux, both STAIC and SHARED libraries go to the default library 0262 # directory. And in RPM, SHARED libraries are part of a normal package, 0263 # while STATIC libraries go to “%package devel”. 0264 TARGETS ${LIBRARY_NAME} 0265 EXPORT "${LIBRARY_NAME}" 0266 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBRARY_NAME}") 0267 install(EXPORT ${LIBRARY_NAME} 0268 FILE ${LIBRARY_NAME}.cmake 0269 NAMESPACE "PerceptualColor::" 0270 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIBRARY_NAME} 0271 ) 0272 include(CMakePackageConfigHelpers) 0273 write_basic_package_version_file( 0274 "${CMAKE_CURRENT_BINARY_DIR}/generated/${LIBRARY_NAME}-config-version.cmake" 0275 VERSION "${FULL_VERSION}" 0276 COMPATIBILITY AnyNewerVersion 0277 ) 0278 configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in 0279 "${CMAKE_CURRENT_BINARY_DIR}/generated/${LIBRARY_NAME}-config.cmake" 0280 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIBRARY_NAME} 0281 ) 0282 install( 0283 FILES 0284 "${CMAKE_CURRENT_BINARY_DIR}/generated/${LIBRARY_NAME}-config.cmake" 0285 "${CMAKE_CURRENT_BINARY_DIR}/generated/${LIBRARY_NAME}-config-version.cmake" 0286 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIBRARY_NAME} 0287 ) 0288 0289 0290 0291 0292 0293 ################# Build internal library ################# 0294 # The following library is like the normal library, with the 0295 # following difference: It exports all symbols (also private ones), and it 0296 # does not install. This is used for the unit testing, because exporting all 0297 # symbols is necessary for whitebox testing, which we actually do during 0298 # unit testing. 0299 # (This makes every cpp file to compile twice, which makes the build time 0300 # longer. It might be possible to avoid this by creating an OBJECT collection 0301 # with add_library(object_collection OBJECT 1.cpp 2.cpp …) to avoid double 0302 # compiling, but the resulting library has a bigger file size. Therefore, 0303 # this is not a good option.) 0304 set(INTERNAL_LIBRARY_NAME "perceptualcolorinternal-${MAJOR_VERSION}") 0305 # Add library. If it will build as STATIC or as SHARED library is not 0306 # hardcoded, so add_library() it use BUILD_SHARED_LIBS to decide. 0307 add_library(${INTERNAL_LIBRARY_NAME}) 0308 # target_sources should normally always use PRIVATE. Details: 0309 # crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources 0310 target_sources( 0311 ${INTERNAL_LIBRARY_NAME} 0312 PRIVATE 0313 ${library_SRC} 0314 ${lib_PUBLICHEADERS} 0315 # Add code that is currently not used, but that should be kept working 0316 # for possible use in the future. 0317 csscolor.cpp) 0318 target_compile_definitions( 0319 ${INTERNAL_LIBRARY_NAME} 0320 PRIVATE PERCEPTUALCOLORINTERNAL) 0321 if(BUILD_SHARED_LIBS) 0322 target_compile_definitions( 0323 ${INTERNAL_LIBRARY_NAME} 0324 PRIVATE PERCEPTUALCOLORLIB_BUILD_DYNAMIC_LIBRARY) 0325 else() 0326 target_compile_definitions( 0327 ${INTERNAL_LIBRARY_NAME} 0328 PUBLIC PERCEPTUALCOLORLIB_STATIC) 0329 endif() 0330 set_target_properties( 0331 ${INTERNAL_LIBRARY_NAME} PROPERTIES 0332 # We want all symbols to be publicly available. On Unix-based systems, this 0333 # is the default behavior, and no additional configuration is required. 0334 CXX_VISIBILITY_PRESET "default" 0335 VISIBILITY_INLINES_HIDDEN FALSE 0336 VERSION "${FULL_VERSION}" 0337 SOVERSION "${MAJOR_VERSION}") 0338 if(WIN32) 0339 set_target_properties(${INTERNAL_LIBRARY_NAME} PROPERTIES 0340 # However, on Windows, all symbols are hidden by default 0341 # except for those that are explicitly marked for export using 0342 # "__declspec(dllexport)" or "__declspec(dllimport)" keywords. 0343 # To achieve a similar behavior on Window as on Unix-based systems, 0344 # CMake provides the "WINDOWS_EXPORT_ALL_SYMBOLS" property, which 0345 # can be set to "TRUE" to automatically generate the necessary 0346 # export symbols for all classes and functions on Windows. However, 0347 # please note that this option does not work for global variables. 0348 # Note that this is incompatible with INTERPROCEDURAL_OPTIMIZATION. 0349 # See also https://stackoverflow.com/q/225432/5706738 0350 WINDOWS_EXPORT_ALL_SYMBOLS TRUE 0351 # WINDOWS_EXPORT_ALL_SYMBOLS is incompatible with the /GL option 0352 # for IPO/LTO (whole program optimization) on MSVC. And maybe also 0353 # with IPO/LTO on MinGW? 0354 INTERPROCEDURAL_OPTIMIZATION OFF) 0355 endif() 0356 # The automatic export of otherwise private symbols on MSVC 0357 # shared libraries via CMake's WINDOWS_EXPORT_ALL_SYMBOLS property 0358 # does not work well for Qt meta objects, resulting in non-functional 0359 # signals. Since some unit tests require signals, it is good to give 0360 # linker feedback in targets linking against this library (therefore PUBLIC). 0361 if(MSVC AND BUILD_SHARED_LIBS) 0362 target_link_options(${INTERNAL_LIBRARY_NAME} PUBLIC "/VERBOSE") 0363 endif() 0364 if(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 0365 # NOTE --export-all-symbols is necessary when using the GNU compiler 0366 # on Windows (MinGW), but is refused when using the GNU compiler on Linux. 0367 # NOTE Options like -rdynamic (for the compiler) or --export-dynamic 0368 # (directly for the GNU linker) respectively --export_dynamic (directly 0369 # for the Clang linker) only affect executables. --export-all-symbols 0370 # however affects also libraries. 0371 target_link_options(${INTERNAL_LIBRARY_NAME} 0372 # "-Wl," passes the following option to the linker. 0373 PRIVATE "-Wl,--export-all-symbols") 0374 endif() 0375 target_include_directories( 0376 ${INTERNAL_LIBRARY_NAME} 0377 PUBLIC 0378 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> 0379 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated/> 0380 # No $<INSTALL_INTERFACE:xxx> because this target is only meant to 0381 # be build as part of this project, and not by external projects. 0382 # NOTE It's necessary for LittleCMS to be marked as PUBLIC for the 0383 # internal build since users of the internal build have full access 0384 # to internal headers. These headers may include LittleCMS, and without 0385 # public access, users wouldn't be able to use the library as intended. 0386 ${LCMS2_INCLUDE_DIRS}) 0387 target_link_libraries( 0388 ${INTERNAL_LIBRARY_NAME} 0389 # TODO We could remove the Qt::Concurrent (only) if we were absolutely sure 0390 # that we will not need it in the future either. Otherwise, it’s better 0391 # to keep it, for future binary compatibility. 0392 # NOTE It's necessary for LittleCMS to be marked as PUBLIC for the 0393 # internal build since users of the internal build have full access 0394 # to internal headers. These headers may include LittleCMS, and without 0395 # public access, users wouldn't be able to use the library as intended. 0396 PUBLIC 0397 Qt::Core Qt::Gui Qt::Widgets Qt::DBus Qt::Concurrent Qt::Svg 0398 ${LCMS2_LIBRARIES} 0399 )