CMakeLists.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. cmake_minimum_required(VERSION 3.10)
  2. project(msdfgen VERSION 1.8 LANGUAGES CXX)
  3. option(MSDFGEN_BUILD_MSDFGEN_STANDALONE "Build the msdfgen standalone executable" ON)
  4. option(MSDFGEN_USE_OPENMP "Build with OpenMP support for multithreaded code" OFF)
  5. option(MSDFGEN_USE_CPP11 "Build with C++11 enabled" ON)
  6. option(MSDFGEN_USE_SKIA "Build with the Skia library" OFF)
  7. option(FREETYPE_WITH_PNG "Link libpng and zlib because FreeType is configured to require it" OFF)
  8. option(FREETYPE_WITH_HARFBUZZ "Link HarfBuzz because FreeType is configured to require it" OFF)
  9. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  10. find_package(Freetype REQUIRED)
  11. #----------------------------------------------------------------
  12. # Gathering File
  13. #----------------------------------------------------------------
  14. file(GLOB_RECURSE msdfgen_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  15. "core/*.h"
  16. "core/*.hpp"
  17. )
  18. file(GLOB_RECURSE msdfgen_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  19. "core/*.cpp"
  20. )
  21. file(GLOB_RECURSE msdfgen-ext_PUBLIC_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  22. "ext/*.h"
  23. "ext/*.hpp"
  24. )
  25. file(GLOB_RECURSE msdfgen-ext_PRIVATE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  26. "include/*.h"
  27. )
  28. file(GLOB_RECURSE msdfgen-ext_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  29. "ext/*.cpp"
  30. "lib/*.cpp"
  31. "lib/*.cpp"
  32. )
  33. # Build the library (aliased name because it's the same target name the exe)
  34. include(folderize)
  35. folderize_sources(msdfgen_HEADERS ${CMAKE_SOURCE_DIR})
  36. folderize_sources(msdfgen_SOURCES ${CMAKE_SOURCE_DIR})
  37. folderize_sources(msdfgen-ext_PUBLIC_HEADERS ${CMAKE_SOURCE_DIR})
  38. folderize_sources(msdfgen-ext_PRIVATE_HEADERS ${CMAKE_SOURCE_DIR})
  39. folderize_sources(msdfgen-ext_SOURCES ${CMAKE_SOURCE_DIR})
  40. #----------------------------------------------------------------
  41. # Target configuration
  42. #----------------------------------------------------------------
  43. add_library(msdfgen ${msdfgen_SOURCES} ${msdfgen_HEADERS} "./msdfgen.h")
  44. add_library(msdfgen::msdfgen ALIAS msdfgen)
  45. set_target_properties(msdfgen PROPERTIES PUBLIC_HEADER "${msdfgen_HEADERS}")
  46. target_include_directories(msdfgen INTERFACE
  47. $<INSTALL_INTERFACE:include>
  48. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
  49. )
  50. if(MSDFGEN_USE_CPP11)
  51. target_compile_features(msdfgen PUBLIC cxx_std_11)
  52. target_compile_definitions(msdfgen PUBLIC MSDFGEN_USE_CPP11)
  53. endif()
  54. if(MSDFGEN_USE_OPENMP)
  55. # Note: Clang doesn't support OpenMP by default...
  56. find_package(OpenMP REQUIRED COMPONENTS CXX)
  57. target_link_libraries(msdfgen PRIVATE OpenMP::OpenMP_CXX)
  58. target_compile_definitions(msdfgen PRIVATE MSDFGEN_USE_OPENMP)
  59. endif()
  60. if(MSDFGEN_USE_SKIA)
  61. find_package(Skia REQUIRED)
  62. target_link_libraries(msdfgen-ext PRIVATE Skia::Skia)
  63. target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_SKIA)
  64. endif()
  65. add_library(msdfgen-ext ${msdfgen-ext_SOURCES} ${msdfgen-ext_PUBLIC_HEADERS} ${msdfgen-ext_PRIVATE_HEADERS} "./msdfgen-ext.h")
  66. add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext)
  67. set_target_properties(msdfgen-ext PROPERTIES
  68. PUBLIC_HEADER "${msdfgen-ext_PUBLIC_HEADERS}"
  69. )
  70. target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen Freetype::Freetype)
  71. target_include_directories(msdfgen-ext
  72. PUBLIC
  73. $<INSTALL_INTERFACE:include>
  74. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
  75. PRIVATE
  76. ${CMAKE_CURRENT_SOURCE_DIR}/include
  77. )
  78. if(MSDFGEN_USE_CPP11)
  79. target_compile_features(msdfgen-ext PUBLIC cxx_std_11)
  80. target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_CPP11)
  81. endif()
  82. # Build the executable if requested
  83. if(MSDFGEN_BUILD_MSDFGEN_STANDALONE)
  84. add_executable(msdfgen-standalone main.cpp)
  85. set_target_properties(msdfgen-standalone PROPERTIES ARCHIVE_OUTPUT_DIRECTORY archive OUTPUT_NAME msdfgen)
  86. target_compile_definitions(msdfgen-standalone PRIVATE MSDFGEN_STANDALONE)
  87. target_link_libraries(msdfgen-standalone PRIVATE msdfgen::msdfgen msdfgen::msdfgen-ext)
  88. if(FREETYPE_WITH_PNG)
  89. find_package(ZLIB REQUIRED)
  90. find_package(PNG REQUIRED)
  91. target_link_libraries(msdfgen-standalone PRIVATE ZLIB::ZLIB PNG::PNG)
  92. endif()
  93. if(FREETYPE_WITH_HARFBUZZ)
  94. # No FindHarfBuzz.cmake available so falling back to CMAKE_LIBRARY_PATH
  95. find_library(FREETYPE_HARFBUZZ_LIB "harfbuzz")
  96. target_link_libraries(msdfgen-standalone PRIVATE "${FREETYPE_HARFBUZZ_LIB}")
  97. endif()
  98. endif()
  99. #----------------------------------------------------------------
  100. # Installation and exportation of the libraries
  101. #----------------------------------------------------------------
  102. include(CMakePackageConfigHelpers)
  103. set(MSDFGEN_CONFIG_PATH "lib/cmake/msdfgen")
  104. # install tree package config
  105. write_basic_package_version_file(
  106. "${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake"
  107. VERSION ${PROJECT_VERSION}
  108. COMPATIBILITY SameMajorVersion
  109. )
  110. configure_package_config_file(
  111. cmake/msdfgenConfig.cmake.in
  112. ${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake
  113. INSTALL_DESTINATION ${MSDFGEN_CONFIG_PATH}
  114. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  115. )
  116. # build tree package config
  117. configure_file(
  118. cmake/msdfgenConfig.cmake.in
  119. msdfgenConfig.cmake
  120. @ONLY
  121. )
  122. install(TARGETS msdfgen EXPORT msdfgenTargets
  123. RUNTIME DESTINATION bin
  124. LIBRARY DESTINATION lib
  125. ARCHIVE DESTINATION lib
  126. FRAMEWORK DESTINATION lib
  127. PUBLIC_HEADER DESTINATION include/msdfgen/core
  128. )
  129. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" DESTINATION include/msdfgen)
  130. install(TARGETS msdfgen-ext EXPORT msdfgenTargets
  131. RUNTIME DESTINATION bin
  132. LIBRARY DESTINATION lib
  133. ARCHIVE DESTINATION lib
  134. FRAMEWORK DESTINATION lib
  135. PUBLIC_HEADER DESTINATION include/msdfgen/ext
  136. )
  137. if(MSDFGEN_BUILD_MSDFGEN_STANDALONE)
  138. install(TARGETS msdfgen-standalone EXPORT msdfgenTargets RUNTIME DESTINATION bin)
  139. endif()
  140. install(
  141. FILES
  142. "${CMAKE_CURRENT_BINARY_DIR}/${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake"
  143. "${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake"
  144. DESTINATION ${MSDFGEN_CONFIG_PATH}
  145. )
  146. export(
  147. EXPORT msdfgenTargets
  148. NAMESPACE msdfgen::
  149. FILE "${CMAKE_CURRENT_BINARY_DIR}/msdfgenTargets.cmake"
  150. )
  151. install(
  152. EXPORT msdfgenTargets FILE msdfgenTargets.cmake
  153. NAMESPACE msdfgen::
  154. DESTINATION ${MSDFGEN_CONFIG_PATH}
  155. )