*/}}

CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. cmake_minimum_required(VERSION 3.1)
  2. project (lagui)
  3. if (POLICY CMP0072)
  4. set(OpenGL_GL_PREFERENCE GLVND)
  5. endif()
  6. SET(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to install lagui fonts")
  7. if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH})
  8. set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui)
  9. endif()
  10. SET(LAGUI_USE_GLES false CACHE BOOL "Whether to use GLES in LaGUI")
  11. if(${LAGUI_USE_GLES})
  12. add_definitions(-DLA_USE_GLES)
  13. endif()
  14. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
  15. if(NOT (${LAGUI_ANDROID}))
  16. find_package(OpenGL REQUIRED)
  17. find_package(X11 REQUIRED)
  18. find_package(Freetype REQUIRED)
  19. find_package(GLEW REQUIRED)
  20. find_package(LuaJIT)
  21. find_package(PNG)
  22. endif()
  23. SET(LAGUI_USE_LUAJIT true CACHE BOOL "Whether to use LuaJIT in LaGUI")
  24. if((${LuaJIT_FOUND}) AND (${LAGUI_USE_LUAJIT}))
  25. add_definitions(-DLA_WITH_LUAJIT)
  26. endif()
  27. SET(LAGUI_USE_PNG true CACHE BOOL "Whether to use PNG in LaGUI")
  28. if(${LAGUI_USE_PNG})
  29. add_definitions(-DLA_WITH_PNG)
  30. endif()
  31. if(${LAGUI_ANDROID})
  32. add_definitions(-DLAGUI_ANDROID)
  33. endif()
  34. set(CMAKE_THREAD_PREFER_PTHREAD ON)
  35. set(THREADS_PREFER_PTHREAD_FLAG ON)
  36. find_package(Threads REQUIRED)
  37. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  38. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  39. if((${LAGUI_ANDROID}))
  40. add_compile_options(-fpermissive
  41. -Wno-error=incompatible-function-pointer-types
  42. -Wno-error=int-conversion
  43. )
  44. endif()
  45. # embed func
  46. function(embed_resource resource_file_name source_file_name variable_name)
  47. if(EXISTS "${source_file_name}")
  48. if("${source_file_name}" IS_NEWER_THAN "${resource_file_name}")
  49. return()
  50. endif()
  51. endif()
  52. file(READ "${resource_file_name}" hex_content HEX)
  53. string(REPEAT "[0-9a-f]" 32 pattern)
  54. string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}")
  55. string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}")
  56. string(REGEX REPLACE ", $" "" content "${content}")
  57. set(array_definition "unsigned char ${variable_name}[] =\n{\n${content}\n};")
  58. set(source "// Auto generated file.\n${array_definition}\n")
  59. file(WRITE "${source_file_name}" "${source}")
  60. endfunction()
  61. file(MAKE_DIRECTORY "BuildResources")
  62. embed_resource("resources/soft_proof_table_sRGB.lagui.lut" "BuildResources/soft_proof_table_sRGB.lagui.lut.c" "DATA_LUT_PROOF_SRGB")
  63. embed_resource("resources/soft_proof_table_Clay.lagui.lut" "BuildResources/soft_proof_table_Clay.lagui.lut.c" "DATA_LUT_PROOF_CLAY")
  64. embed_resource("resources/soft_proof_table_D65P3.lagui.lut" "BuildResources/soft_proof_table_D65P3.lagui.lut.c" "DATA_LUT_PROOF_D65P3")
  65. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/std:c11>")
  66. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  67. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  68. file(GLOB SOURCE_FILES
  69. ./*.c ./*.cpp ./resources/*.c ./resources/*.cpp BuildResources/*.c)
  70. file(GLOB HEADER_FILES
  71. ./*.h ./*.hpp ./resources/*.h ./resources/*.hpp BuildResources/*.h)
  72. #add_definitions(-DLAGUI_FONT_CUSTOM_PATH=\"${LAGUI_FONT_CUSTOM_PATH}\")
  73. #add_definitions(-Wno-incompatible-pointer-types)
  74. #add_definitions(-Wno-int-conversion)
  75. #add_definitions(-Wno-discarded-qualifiers)
  76. #add_definitions(-Werror=implicit-function-declaration)
  77. add_definitions(-w)
  78. if(${LAGUI_ANDROID})
  79. INCLUDE_DIRECTORIES(${PNG_SRC_DIR})
  80. INCLUDE_DIRECTORIES(${FREETYPE_SRC_DIR}/include)
  81. INCLUDE_DIRECTORIES(${ANDROID_NDK}/sources/android/native_app_glue)
  82. endif()
  83. include_directories(
  84. ${CMAKE_SOURCE_DIR}
  85. ${X11_INCLUDE_DIR}
  86. ${GLEW_INCLUDE_PATH}
  87. ${GLM_INCLUDE_PATH}
  88. ${FREETYPE_INCLUDE_DIRS}
  89. lagui
  90. )
  91. if(${LuaJIT_FOUND})
  92. include_directories(${LUA_INCLUDE_DIR})
  93. endif()
  94. if(${PNG_FOUND})
  95. include_directories(${LUA_INCLUDE_DIR})
  96. endif()
  97. if(WIN32)
  98. list(APPEND SOURCE_FILES ./wintab/wintab_utils.c)
  99. file(GLOB wintabfiles ./wintab/*.h )
  100. list(APPEND HEADER_FILES ${wintabfiles})
  101. include_directories(wintab)
  102. endif()
  103. list(APPEND SOURCE_FILES ./nanovg/nanovg.c)
  104. file(GLOB nvgfiles ./nanovg/*.h )
  105. list(APPEND HEADER_FILES ${nvgfiles})
  106. include_directories(nanovg)
  107. set(LAGUI_FONTS
  108. "fonts/NotoEmoji-Regular.ttf"
  109. "fonts/NotoSansCJK-Regular.ttc"
  110. "fonts/NotoSansMono-Regular.ttf"
  111. "fonts/NotoSansSymbols-Regular.ttf"
  112. "fonts/NotoSansSymbols2-Regular.ttf"
  113. "fonts/NotoSansMath-Regular.ttf"
  114. )
  115. add_library(lagui ${HEADER_FILES} ${SOURCE_FILES})
  116. execute_process(
  117. COMMAND git rev-parse --abbrev-ref HEAD
  118. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  119. OUTPUT_VARIABLE LAGUI_GIT_BRANCH
  120. OUTPUT_STRIP_TRAILING_WHITESPACE)
  121. execute_process(
  122. COMMAND git rev-parse --short=12 HEAD
  123. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  124. OUTPUT_VARIABLE LAGUI_GIT_HASH
  125. OUTPUT_STRIP_TRAILING_WHITESPACE)
  126. target_compile_definitions(lagui PRIVATE "-DLAGUI_GIT_BRANCH=\"${LAGUI_GIT_BRANCH}\"")
  127. target_compile_definitions(lagui PRIVATE "-DLAGUI_GIT_HASH=\"${LAGUI_GIT_HASH}\"")
  128. install(FILES ${HEADER_FILES} DESTINATION include/lagui)
  129. install(TARGETS lagui EXPORT lagui-targets DESTINATION lib/lagui)
  130. install(EXPORT lagui-targets DESTINATION lib/lagui)
  131. install(FILES lagui-config.cmake DESTINATION lib/lagui)
  132. install(FILES FindLuaJIT.cmake DESTINATION lib/lagui)
  133. install(FILES ${LAGUI_FONTS} DESTINATION ${LAGUI_FONT_CUSTOM_PATH})