cmake_minimum_required(VERSION 3.1) project (lagui) if (POLICY CMP0072) set(OpenGL_GL_PREFERENCE GLVND) endif() SET(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to install lagui fonts") if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH}) set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui) endif() SET(LAGUI_USE_GLES false CACHE BOOL "Whether to use GLES in LaGUI") if(${LAGUI_USE_GLES}) add_definitions(-DLA_USE_GLES) endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) if(NOT (${LAGUI_ANDROID})) find_package(OpenGL REQUIRED) find_package(X11 REQUIRED) find_package(Freetype REQUIRED) find_package(GLEW REQUIRED) find_package(LuaJIT) find_package(PNG) endif() SET(LAGUI_USE_LUAJIT true CACHE BOOL "Whether to use LuaJIT in LaGUI") if((${LuaJIT_FOUND}) AND (${LAGUI_USE_LUAJIT})) add_definitions(-DLA_WITH_LUAJIT) endif() SET(LAGUI_USE_PNG true CACHE BOOL "Whether to use PNG in LaGUI") if(${LAGUI_USE_PNG}) add_definitions(-DLA_WITH_PNG) endif() if(${LAGUI_ANDROID}) add_definitions(-DLAGUI_ANDROID) endif() set(CMAKE_THREAD_PREFER_PTHREAD ON) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) add_compile_options("$<$:/utf-8>") add_compile_options("$<$:/utf-8>") if((${LAGUI_ANDROID})) add_compile_options(-fpermissive -Wno-error=incompatible-function-pointer-types -Wno-error=int-conversion ) endif() # embed func function(embed_resource resource_file_name source_file_name variable_name) if(EXISTS "${source_file_name}") if("${source_file_name}" IS_NEWER_THAN "${resource_file_name}") return() endif() endif() file(READ "${resource_file_name}" hex_content HEX) string(REPEAT "[0-9a-f]" 32 pattern) string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}") string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}") string(REGEX REPLACE ", $" "" content "${content}") set(array_definition "unsigned char ${variable_name}[] =\n{\n${content}\n};") set(source "// Auto generated file.\n${array_definition}\n") file(WRITE "${source_file_name}" "${source}") endfunction() file(MAKE_DIRECTORY "BuildResources") embed_resource("resources/soft_proof_table_sRGB.lagui.lut" "BuildResources/soft_proof_table_sRGB.lagui.lut.c" "DATA_LUT_PROOF_SRGB") embed_resource("resources/soft_proof_table_Clay.lagui.lut" "BuildResources/soft_proof_table_Clay.lagui.lut.c" "DATA_LUT_PROOF_CLAY") embed_resource("resources/soft_proof_table_D65P3.lagui.lut" "BuildResources/soft_proof_table_D65P3.lagui.lut.c" "DATA_LUT_PROOF_D65P3") file(GLOB SOURCE_FILES ./*.c ./*.cpp ./resources/*.c ./resources/*.cpp BuildResources/*.c) file(GLOB HEADER_FILES ./*.h ./*.hpp ./resources/*.h ./resources/*.hpp BuildResources/*.h) add_definitions(-DLAGUI_FONT_CUSTOM_PATH=\"${LAGUI_FONT_CUSTOM_PATH}\") add_definitions(-w) if(${LAGUI_ANDROID}) INCLUDE_DIRECTORIES(${PNG_SRC_DIR}) INCLUDE_DIRECTORIES(${FREETYPE_SRC_DIR}/include) INCLUDE_DIRECTORIES(${ANDROID_NDK}/sources/android/native_app_glue) endif() include_directories( ${CMAKE_SOURCE_DIR} ${X11_INCLUDE_DIR} ${GLEW_INCLUDE_PATH} ${GLM_INCLUDE_PATH} ${FREETYPE_INCLUDE_DIRS} lagui ) if(${LuaJIT_FOUND}) include_directories(${LUA_INCLUDE_DIR}) endif() if(${PNG_FOUND}) include_directories(${LUA_INCLUDE_DIR}) endif() if(WIN32) list(APPEND SOURCE_FILES ./wintab/wintab_utils.c) file(GLOB wintabfiles ./wintab/*.h ) list(APPEND HEADER_FILES ${wintabfiles}) include_directories(wintab) endif() list(APPEND SOURCE_FILES ./nanovg/nanovg.c) file(GLOB nvgfiles ./nanovg/*.h ) list(APPEND HEADER_FILES ${nvgfiles}) include_directories(nanovg) set(LAGUI_FONTS "fonts/NotoEmoji-Regular.ttf" "fonts/NotoSansCJK-Regular.ttc" "fonts/NotoSansMono-Regular.ttf" "fonts/NotoSansSymbols-Regular.ttf" "fonts/NotoSansSymbols2-Regular.ttf" ) add_library(lagui ${HEADER_FILES} ${SOURCE_FILES}) execute_process( COMMAND git rev-parse --abbrev-ref HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE LAGUI_GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process( COMMAND git rev-parse --short=12 HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE LAGUI_GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE) target_compile_definitions(lagui PRIVATE "-DLAGUI_GIT_BRANCH=\"${LAGUI_GIT_BRANCH}\"") target_compile_definitions(lagui PRIVATE "-DLAGUI_GIT_HASH=\"${LAGUI_GIT_HASH}\"") install(FILES ${HEADER_FILES} DESTINATION include/lagui) install(TARGETS lagui EXPORT lagui-targets DESTINATION lib/lagui) install(EXPORT lagui-targets DESTINATION lib/lagui) install(FILES lagui-config.cmake DESTINATION lib/lagui) install(FILES FindLuaJIT.cmake DESTINATION lib/lagui) install(FILES ${LAGUI_FONTS} DESTINATION ${LAGUI_FONT_CUSTOM_PATH})