*/}}

CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. cmake_minimum_required(VERSION 3.1)
  2. project(OurPaint)
  3. IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  4. SET(CMAKE_INSTALL_PREFIX $ENV{HOME}/OurPaint CACHE PATH "Where to install Our Paint" FORCE)
  5. ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  6. set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")
  7. include (InstallRequiredSystemLibraries)
  8. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
  9. set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-no-pie")
  10. set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-no-pie")
  11. find_package(lagui REQUIRED)
  12. find_package(PNG REQUIRED)
  13. find_package(LCMS2 REQUIRED)
  14. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  15. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  16. add_definitions(-w)
  17. # embed_resource("data.dat" "data.h" "DATA")
  18. function(embed_resource resource_file_name source_file_name variable_name)
  19. if(EXISTS "${source_file_name}")
  20. if("${source_file_name}" IS_NEWER_THAN "${resource_file_name}")
  21. return()
  22. endif()
  23. endif()
  24. file(READ "${resource_file_name}" hex_content HEX)
  25. string(REPEAT "[0-9a-f]" 32 pattern)
  26. string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}")
  27. string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}")
  28. string(REGEX REPLACE ", $" "" content "${content}")
  29. set(array_definition "unsigned char ${variable_name}[] =\n{\n${content}\n};")
  30. set(source "// Auto generated file.\n${array_definition}\n")
  31. file(WRITE "${source_file_name}" "${source}")
  32. endfunction()
  33. file(MAKE_DIRECTORY "BuildResources")
  34. embed_resource("Resources/splash.png" "BuildResources/data_splash.c" "DATA_SPLASH")
  35. embed_resource("Resources/splash_highdpi.png" "BuildResources/data_splash_highdpi.c" "DATA_SPLASH_HIGHDPI")
  36. include_directories(
  37. ${LAGUI_INCLUDE_DIRS_ALL}
  38. )
  39. file(GLOB_RECURSE OurPaintFiles
  40. ourpaint.c ouroperations.c ournodes.c ourtranslations.c ourshader.cpp
  41. BuildResources/data_splash.c
  42. BuildResources/data_splash_highdpi.c
  43. )
  44. add_executable(OurPaint ${OurPaintFiles})
  45. execute_process(
  46. COMMAND git rev-parse --abbrev-ref HEAD
  47. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  48. OUTPUT_VARIABLE OURPAINT_GIT_BRANCH
  49. OUTPUT_STRIP_TRAILING_WHITESPACE)
  50. execute_process(
  51. COMMAND git rev-parse --short=12 HEAD
  52. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  53. OUTPUT_VARIABLE OURPAINT_GIT_HASH
  54. OUTPUT_STRIP_TRAILING_WHITESPACE)
  55. target_compile_definitions(OurPaint PRIVATE "-DOURPAINT_GIT_BRANCH=\"${OURPAINT_GIT_BRANCH}\"")
  56. target_compile_definitions(OurPaint PRIVATE "-DOURPAINT_GIT_HASH=\"${OURPAINT_GIT_HASH}\"")
  57. target_link_libraries(OurPaint
  58. ${LAGUI_SHARED_LIBS}
  59. ${PNG_LIBRARY}
  60. ${LCMS2_LIBRARIES}
  61. )
  62. SET(INSTALL_EXTRAS
  63. README.md default_brushes.udf COPYING COPYING_CC_BY_NC)
  64. SET(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to find lagui fonts")
  65. if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH})
  66. set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui)
  67. endif()
  68. set(INSTALL_PATH_BIN ".")
  69. if(${CMAKE_VERSION} VERSION_LESS "3.21")
  70. install(TARGETS OurPaint DESTINATION ${INSTALL_PATH_BIN})
  71. else()
  72. install(TARGETS OurPaint RUNTIME_DEPENDENCY_SET runtime_deps DESTINATION ${INSTALL_PATH_BIN})
  73. LIST(APPEND pre_exclude_regexes "api-ms-.*")
  74. LIST(APPEND pre_exclude_regexes "ext-ms-.*")
  75. LIST(APPEND post_exclude_regexes ".*WINDOWS[\\/]system32.*")
  76. LIST(APPEND post_exclude_regexes "^/lib" "^/usr" "^/bin")
  77. install(RUNTIME_DEPENDENCY_SET runtime_deps
  78. PRE_EXCLUDE_REGEXES ${pre_exclude_regexes}
  79. POST_EXCLUDE_REGEXES ${post_exclude_regexes}
  80. DESTINATION ${INSTALL_PATH_BIN}
  81. )
  82. endif()
  83. install(DIRECTORY "${LAGUI_FONT_CUSTOM_PATH}/" DESTINATION ${INSTALL_PATH_BIN}/fonts PATTERN "*.*")
  84. install(FILES ${INSTALL_EXTRAS} DESTINATION ${INSTALL_PATH_BIN})