*/}}

CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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>:/std:c11>")
  15. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  16. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  17. add_definitions(-w)
  18. # embed_resource("data.dat" "data.h" "DATA")
  19. function(embed_resource resource_file_name source_file_name variable_name)
  20. if(EXISTS "${source_file_name}")
  21. if("${source_file_name}" IS_NEWER_THAN "${resource_file_name}")
  22. return()
  23. endif()
  24. endif()
  25. file(READ "${resource_file_name}" hex_content HEX)
  26. string(REPEAT "[0-9a-f]" 32 pattern)
  27. string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}")
  28. string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}")
  29. string(REGEX REPLACE ", $" "" content "${content}")
  30. set(array_definition "unsigned char ${variable_name}[] =\n{\n${content}\n};")
  31. set(source "// Auto generated file.\n${array_definition}\n")
  32. file(WRITE "${source_file_name}" "${source}")
  33. endfunction()
  34. file(MAKE_DIRECTORY "BuildResources")
  35. embed_resource("Resources/splash.png" "BuildResources/data_splash.c" "DATA_SPLASH")
  36. embed_resource("Resources/splash_highdpi.png" "BuildResources/data_splash_highdpi.c" "DATA_SPLASH_HIGHDPI")
  37. include_directories(
  38. ${LAGUI_INCLUDE_DIRS_ALL}
  39. )
  40. file(GLOB_RECURSE OurPaintFiles
  41. ourpaint.c ouroperations.c ournodes.c ourtranslations.c ourshader.cpp ourstrings.cpp
  42. BuildResources/data_splash.c
  43. BuildResources/data_splash_highdpi.c
  44. )
  45. add_executable(OurPaint ${OurPaintFiles})
  46. target_link_options(OurPaint PUBLIC "-Wl,--start-group")
  47. execute_process(
  48. COMMAND git rev-parse --abbrev-ref HEAD
  49. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  50. OUTPUT_VARIABLE OURPAINT_GIT_BRANCH
  51. OUTPUT_STRIP_TRAILING_WHITESPACE)
  52. execute_process(
  53. COMMAND git rev-parse --short=12 HEAD
  54. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  55. OUTPUT_VARIABLE OURPAINT_GIT_HASH
  56. OUTPUT_STRIP_TRAILING_WHITESPACE)
  57. target_compile_definitions(OurPaint PRIVATE "-DOURPAINT_GIT_BRANCH=\"${OURPAINT_GIT_BRANCH}\"")
  58. target_compile_definitions(OurPaint PRIVATE "-DOURPAINT_GIT_HASH=\"${OURPAINT_GIT_HASH}\"")
  59. target_link_libraries(OurPaint
  60. ${LAGUI_SHARED_LIBS}
  61. ${PNG_LIBRARY}
  62. ${LCMS2_LIBRARIES}
  63. )
  64. SET(INSTALL_EXTRAS
  65. README.md default_brushes.udf default_pallettes.udf COPYING COPYING_CC_BY_NC)
  66. SET(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to find lagui fonts")
  67. if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH})
  68. set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui)
  69. endif()
  70. set(INSTALL_PATH_BIN ".")
  71. if(${CMAKE_VERSION} VERSION_LESS "3.21")
  72. install(TARGETS OurPaint DESTINATION ${INSTALL_PATH_BIN})
  73. else()
  74. install(TARGETS OurPaint RUNTIME_DEPENDENCY_SET runtime_deps DESTINATION ${INSTALL_PATH_BIN})
  75. LIST(APPEND pre_exclude_regexes "api-ms-.*")
  76. LIST(APPEND pre_exclude_regexes "ext-ms-.*")
  77. list(APPEND post_exclude_regexes ".*[Ww][Ii][Nn][Dd][Oo][Ww][Ss][\\/][Ss][Yy][Ss][Tt][Ee][Mm]32.*")
  78. list(APPEND post_exclude_regexes ".*[Ww][Ii][Nn][Dd][Oo][Ww][Ss][\\/][Ss][Yy][Ss][Ww][Oo][Ww]64.*")
  79. LIST(APPEND post_exclude_regexes "^/lib" "^/usr" "^/bin")
  80. install(RUNTIME_DEPENDENCY_SET runtime_deps
  81. PRE_EXCLUDE_REGEXES ${pre_exclude_regexes}
  82. POST_EXCLUDE_REGEXES ${post_exclude_regexes}
  83. DESTINATION ${INSTALL_PATH_BIN}
  84. )
  85. endif()
  86. install(DIRECTORY "${LAGUI_FONT_CUSTOM_PATH}/" DESTINATION ${INSTALL_PATH_BIN}/fonts PATTERN "*.*")
  87. install(FILES ${INSTALL_EXTRAS} DESTINATION ${INSTALL_PATH_BIN})