*/}}

CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. target_link_options(OurPaint PUBLIC "-Wl,--start-group")
  46. execute_process(
  47. COMMAND git rev-parse --abbrev-ref HEAD
  48. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  49. OUTPUT_VARIABLE OURPAINT_GIT_BRANCH
  50. OUTPUT_STRIP_TRAILING_WHITESPACE)
  51. execute_process(
  52. COMMAND git rev-parse --short=12 HEAD
  53. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  54. OUTPUT_VARIABLE OURPAINT_GIT_HASH
  55. OUTPUT_STRIP_TRAILING_WHITESPACE)
  56. target_compile_definitions(OurPaint PRIVATE "-DOURPAINT_GIT_BRANCH=\"${OURPAINT_GIT_BRANCH}\"")
  57. target_compile_definitions(OurPaint PRIVATE "-DOURPAINT_GIT_HASH=\"${OURPAINT_GIT_HASH}\"")
  58. target_link_libraries(OurPaint
  59. ${LAGUI_SHARED_LIBS}
  60. ${PNG_LIBRARY}
  61. ${LCMS2_LIBRARIES}
  62. )
  63. SET(INSTALL_EXTRAS
  64. README.md default_brushes.udf default_pallettes.udf COPYING COPYING_CC_BY_NC)
  65. SET(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to find lagui fonts")
  66. if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH})
  67. set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui)
  68. endif()
  69. set(INSTALL_PATH_BIN ".")
  70. if(${CMAKE_VERSION} VERSION_LESS "3.21")
  71. install(TARGETS OurPaint DESTINATION ${INSTALL_PATH_BIN})
  72. else()
  73. install(TARGETS OurPaint RUNTIME_DEPENDENCY_SET runtime_deps DESTINATION ${INSTALL_PATH_BIN})
  74. LIST(APPEND pre_exclude_regexes "api-ms-.*")
  75. LIST(APPEND pre_exclude_regexes "ext-ms-.*")
  76. LIST(APPEND post_exclude_regexes ".*WINDOWS[\\/]system32.*")
  77. LIST(APPEND post_exclude_regexes "^/lib" "^/usr" "^/bin")
  78. install(RUNTIME_DEPENDENCY_SET runtime_deps
  79. PRE_EXCLUDE_REGEXES ${pre_exclude_regexes}
  80. POST_EXCLUDE_REGEXES ${post_exclude_regexes}
  81. DESTINATION ${INSTALL_PATH_BIN}
  82. )
  83. endif()
  84. install(DIRECTORY "${LAGUI_FONT_CUSTOM_PATH}/" DESTINATION ${INSTALL_PATH_BIN}/fonts PATTERN "*.*")
  85. install(FILES ${INSTALL_EXTRAS} DESTINATION ${INSTALL_PATH_BIN})