cmake_minimum_required(VERSION 3.15) option(MSDFGEN_CORE_ONLY "Only build the core library with no dependencies" OFF) option(MSDFGEN_BUILD_STANDALONE "Build the msdfgen standalone executable" ON) option(MSDFGEN_USE_OPENMP "Build with OpenMP support for multithreaded code" OFF) option(MSDFGEN_USE_CPP11 "Build with C++11 enabled" ON) option(MSDFGEN_USE_SKIA "Build with the Skia library" OFF) option(MSDFGEN_INSTALL "Generate installation target" ON) if(MSDFGEN_CORE_ONLY AND MSDFGEN_BUILD_STANDALONE) message(WARNING "Option MSDFGEN_CORE_ONLY ignored - extensions are required for standalone executable") set(MSDFGEN_CORE_ONLY OFF) endif() project(msdfgen VERSION 1.9 LANGUAGES CXX) if(NOT CMAKE_MSVC_RUNTIME_LIBRARY) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") get_directory_property(MSDFGEN_HAS_PARENT PARENT_DIRECTORY) if(MSDFGEN_HAS_PARENT) set(CMAKE_MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY} PARENT_SCOPE) endif() endif() if(NOT TARGET Freetype::Freetype) find_package(Freetype REQUIRED) endif() file(GLOB_RECURSE MSDFGEN_CORE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "core/*.h" "core/*.hpp") file(GLOB_RECURSE MSDFGEN_CORE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "core/*.cpp") file(GLOB_RECURSE MSDFGEN_EXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ext/*.h" "ext/*.hpp") file(GLOB_RECURSE MSDFGEN_EXT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ext/*.cpp" "lib/*.cpp") # Core library add_library(msdfgen-core "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" ${MSDFGEN_CORE_HEADERS} ${MSDFGEN_CORE_SOURCES}) add_library(msdfgen::msdfgen-core ALIAS msdfgen-core) set_target_properties(msdfgen-core PROPERTIES PUBLIC_HEADER "${MSDFGEN_CORE_HEADERS}") #set_property(TARGET msdfgen-core PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") target_include_directories(msdfgen-core INTERFACE $ $ ) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen-core) if(MSDFGEN_USE_CPP11) target_compile_features(msdfgen-core PUBLIC cxx_std_11) target_compile_definitions(msdfgen-core PUBLIC MSDFGEN_USE_CPP11) endif() if(MSDFGEN_USE_OPENMP) # Note: Clang doesn't support OpenMP by default... find_package(OpenMP REQUIRED COMPONENTS CXX) target_compile_definitions(msdfgen-core PUBLIC MSDFGEN_USE_OPENMP) target_link_libraries(msdfgen-core PUBLIC OpenMP::OpenMP_CXX) endif() # Extensions library if(NOT MSDFGEN_CORE_ONLY) add_library(msdfgen-ext "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" ${MSDFGEN_EXT_HEADERS} ${MSDFGEN_EXT_SOURCES}) add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext) set_target_properties(msdfgen-ext PROPERTIES PUBLIC_HEADER "${MSDFGEN_EXT_HEADERS}") target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen-core Freetype::Freetype) target_include_directories(msdfgen-ext PUBLIC $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen-ext) if(MSDFGEN_USE_SKIA) find_package(Skia REQUIRED) target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_SKIA) target_link_libraries(msdfgen-ext PUBLIC Skia::Skia) endif() add_library(msdfgen-all INTERFACE) add_library(msdfgen::msdfgen ALIAS msdfgen-all) target_link_libraries(msdfgen-all INTERFACE msdfgen::msdfgen-core msdfgen::msdfgen-ext) endif() # Standalone executable if(MSDFGEN_BUILD_STANDALONE) set(MSDFGEN_STANDALONE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp") if(MSVC) set(MSDFGEN_STANDALONE_SOURCES ${MSDFGEN_STANDALONE_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.rc") endif() add_executable(msdfgen ${MSDFGEN_STANDALONE_SOURCES}) target_compile_definitions(msdfgen PUBLIC MSDFGEN_STANDALONE) target_link_libraries(msdfgen PUBLIC msdfgen::msdfgen) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen) endif() # Installation if(MSDFGEN_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) set(MSDFGEN_CONFIG_PATH "lib/cmake/msdfgen") # install tree package config write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) configure_package_config_file( cmake/msdfgenConfig.cmake.in ${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake INSTALL_DESTINATION ${MSDFGEN_CONFIG_PATH} NO_CHECK_REQUIRED_COMPONENTS_MACRO ) # build tree package config configure_file( cmake/msdfgenConfig.cmake.in msdfgenConfig.cmake @ONLY ) install(TARGETS msdfgen-core EXPORT msdfgenTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/msdfgen/core ) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" DESTINATION include/msdfgen) if(NOT MSDFGEN_CORE_ONLY) install(TARGETS msdfgen-ext EXPORT msdfgenTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/msdfgen/ext ) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" DESTINATION include/msdfgen) install(TARGETS msdfgen-all EXPORT msdfgenTargets) endif() export(EXPORT msdfgenTargets NAMESPACE msdfgen:: FILE "${CMAKE_CURRENT_BINARY_DIR}/msdfgenTargets.cmake") install(EXPORT msdfgenTargets FILE msdfgenTargets.cmake NAMESPACE msdfgen:: DESTINATION ${MSDFGEN_CONFIG_PATH}) if(MSDFGEN_BUILD_STANDALONE) install(TARGETS msdfgen EXPORT msdfgenBinaryTargets DESTINATION ${CMAKE_INSTALL_BINDIR}) export(EXPORT msdfgenBinaryTargets NAMESPACE msdfgen-standalone:: FILE "${CMAKE_CURRENT_BINARY_DIR}/msdfgenBinaryTargets.cmake") install(EXPORT msdfgenBinaryTargets FILE msdfgenBinaryTargets.cmake NAMESPACE msdfgen-standalone:: DESTINATION ${MSDFGEN_CONFIG_PATH}) endif() install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake" DESTINATION ${MSDFGEN_CONFIG_PATH} ) endif()