#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( FreeType VERSION 2.12.1 DESCRIPTION "True Type font parsing and rendering library" ) include("../../BuildSystem/cmake/cplusplus.cmake") # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/freetype-VER-2-12-1.tar.gz) message(STATUS "Downloading FreeType sources") file( DOWNLOAD https://gitlab.freedesktop.org/freetype/freetype/-/archive/VER-2-12-1/freetype-VER-2-12-1.tar.gz ${PROJECT_SOURCE_DIR}/downloads/freetype-VER-2-12-1.tar.gz SHOW_PROGRESS EXPECTED_HASH SHA256=0e72cae32751598d126cfd4bceda909f646b7231ab8c52e28abb686c20a2bea1 STATUS DOWNLOAD_STATUS ) if(NOT DOWNLOAD_STATUS EQUAL 0) file(REMOVE ${PROJECT_SOURCE_DIR}/downloads/freetype-VER-2-12-1.tar.gz) message(FATAL_ERROR "Download failed, stopping build (error ${DOWNLOAD_STATUS})") endif() endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting FreeType sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/freetype-VER-2-12-1.tar.gz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/freetype-VER-2-12-1 ${PROJECT_SOURCE_DIR}/build ) endif() file( COPY "${PROJECT_SOURCE_DIR}/ftconfig.h" DESTINATION "${PROJECT_SOURCE_DIR}/build/include/freetype/config/" ) # ------------------------------------------------------------------------------------------------- set( sourceFiles "build/src/autofit/autofit.c" "build/src/base/ftbbox.c" "build/src/base/ftbase.c" "build/src/base/ftfstype.c" "build/src/base/ftcid.c" "build/src/base/ftbdf.c" "build/src/base/ftbitmap.c" "build/src/base/ftgasp.c" "build/src/base/ftgxval.c" "build/src/base/ftinit.c" "build/src/base/ftpatent.c" "build/src/base/ftotval.c" "build/src/base/ftpfr.c" "build/src/base/ftstroke.c" "build/src/base/ftmm.c" "build/src/base/ftglyph.c" "build/src/base/ftsynth.c" "build/src/base/ftwinfnt.c" "build/src/bdf/bdf.c" "build/src/bzip2/ftbzip2.c" "build/src/base/fttype1.c" "build/src/cache/ftcache.c" "build/src/cff/cff.c" "build/src/cid/type1cid.c" "build/src/gzip/ftgzip.c" "build/src/lzw/ftlzw.c" "build/src/pcf/pcf.c" "build/src/psaux/psaux.c" "build/src/pfr/pfr.c" "build/src/pshinter/pshinter.c" "build/src/psnames/psnames.c" "build/src/raster/raster.c" "build/src/sdf/sdf.c" "build/src/sfnt/sfnt.c" "build/src/smooth/smooth.c" "build/src/truetype/truetype.c" "build/src/svg/svg.c" "build/src/type1/type1.c" "build/src/type42/type42.c" "build/src/winfonts/winfnt.c" "build/src/base/ftdebug.c" ) set( windowsSourceFiles "build/builds/windows/ftsystem.c" ) set( linuxSourceFiles "build/builds/unix/ftsystem.c" ) file( GLOB_RECURSE headerFiles CONFIGURE_DEPENDS "build/include/*.h" ) # ------------------------------------------------------------------------------------------------- add_library(FreeType STATIC) add_library(FreeType::Static ALIAS FreeType) target_compile_definitions( FreeType PRIVATE FT2_BUILD_LIBRARY ) target_include_directories( FreeType PUBLIC "build/include/" PRIVATE "build/src/" ) target_sources( FreeType PUBLIC ${headerFiles} PRIVATE ${sourceFiles} ) if(WIN32) target_sources( FreeType PRIVATE ${windowsSourceFiles} ) else() target_sources( FreeType PRIVATE ${linuxSourceFiles} ) endif() #set_target_properties(FreeType PROPERTIES PREFIX "") set_target_properties(FreeType PROPERTIES OUTPUT_NAME "freetype") # ------------------------------------------------------------------------------------------------- #install( # DIRECTORY build/include/ # DESTINATION ${PROJECT_SOURCE_DIR}/Include #) install( TARGETS FreeType ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${NUCLEX_COMPILER_TAG} ) # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/FreeTypeConfig.cmake" "#!/usr/bin/cmake # Configuration to include FreeType in a CMake-based project. If you want to # reference FreeType as an externally compiled static library, do this: # # set(FreeType_DIR \"../ThirdParty/freetype\") # find_package(FreeType REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE GTest::Static # PRIVATE GTest::Main # ) # # Alternatively, if you want to build FreeType together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/freetype\" # \"\${CMAKE_BINARY_DIR}/freetype\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE FreeType # PRIVATE FreeTypeMain # ) # # ------------------------------------------------------------------------------------------------- if(NOT DEFINED NUCLEX_COMPILER_TAG) message( FATAL_ERROR \"NUCLEX_COMPILER_TAG not defined! Include cplusplus.cmake before importing this package \\ in order to generate a tag identifying the platform/compiler/architecture/variant!\" ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}\") # TODO: Warn and link release build when compiling in debug mode # TODO: Warn and link build for older compiler version if found message( FATAL_ERROR \"Directory '\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}' not found. \\ Please either build and install this project before importing it via \\ find_package() or use this project's main CMakeFiles.txt via add_subdirectory()!\" ) endif() # ------------------------------------------------------------------------------------------------- add_library(FreeType::Static STATIC IMPORTED) add_library(FreeType::Main STATIC IMPORTED) # This may cause warnings on recent GCC versions (10.0.0+?) with LTO because GCC detects # that the headers used during build (residing in build/) are not the same used when # linking the library (copies resising in Include/). # # CMake doesn't run the install step during build, so the only way to get the headers # in place before building would be by copying them rather than installing them. set_target_properties( FreeType::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"CXX\" ) set_target_properties( FreeType::Main PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"CXX\" ) if(WIN32) set_target_properties( FreeType::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/freetype.lib\" ) else() set_target_properties( FreeType::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libfreetype.a\" ) endif() message(STATUS \"Imported FreeType targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------