*/}}

CMakeLists.txt 4.2 KB

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