CMakeLists.txt 6.4 KB

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