diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e19867..f9c473e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,86 +1,91 @@ ############################################################################### -# Copyright (c) 2016-2023 Joel de Guzman -# -# Distributed under the MIT License (https://opensource.org/licenses/MIT) +# SPDX-FileCopyrightText: 2016-2024 Joel de Guzman +# SPDX-FileContributor: Modified by Andrea Zanellato +# SPDX-License-Identifier: MIT ############################################################################### -cmake_minimum_required(VERSION 3.7.2...3.15.0) -include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) +cmake_minimum_required(VERSION 3.18.0) project(artist LANGUAGES C CXX) -set(CMAKE_CXX_STANDARD 17) if (POLICY CMP0135) cmake_policy(SET CMP0135 NEW) endif() -# Ensure presence of Git submodules (when not using a source tarball) -if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") - find_package(Git REQUIRED) - function(git_submodule_check dir) - if (NOT EXISTS "${dir}/CMakeLists.txt") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${dir} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMAND_ERROR_IS_FATAL ANY) - endif() - endfunction() - git_submodule_check(lib/external/libunibreak) - git_submodule_check(lib/infra) -endif() +############################################################################### +# Settings +############################################################################### -set(DEFAULT_BUILD_TYPE "Release") -if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") - set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE - STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +# Add our CMake modules to path +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/lib/infra/cmake" + "${CMAKE_SOURCE_DIR}/cmake" +) +if(CMAKE_CXX_STANDARD LESS 17) + set(CMAKE_CXX_STANDARD 17) endif() -include(CheckIPOSupported) -check_ipo_supported(RESULT IPO_SUPPORTED) -if (IPO_SUPPORTED) - message(STATUS "Link-time optimization supported. Will be enabled in Release build type") +# TODO: Move compiler settings to a settings module +if (APPLE) + if (NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR}) + endif() + if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "arm64") + message(STATUS "Artist lib macOS target processor: arm64.") + elseif (${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64") + message(STATUS "Artist lib macOS target processor: x86_64.") + else() + message(FATAL_ERROR "Unsupported macOS compiler") + endif() endif() +message(STATUS "Compiler: ${CMAKE_C_COMPILER_ID}") -if (APPLE) - option(ARTIST_QUARTZ_2D "build Artist using quartz 2d on MacOS" ON) - option(ARTIST_SKIA "build Artist using skia" OFF) +set(ARTIST_HOST_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME}) +if (ARTIST_HOST_SYSTEM_NAME STREQUAL "Darwin") + set(ARTIST_HOST_SYSTEM_NAME "macOS") + set(ARTIST_BACKEND_NAME "Quartz2D") else() - option(ARTIST_SKIA "build Artist using skia" ON) + set(ARTIST_BACKEND_NAME "Skia") endif() +message(STATUS "Building Artist library for ${ARTIST_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION}\ + using ${ARTIST_BACKEND_NAME} backend.") -if (ARTIST_SKIA) - set(ARTIST_QUARTZ_2D OFF) -endif() +############################################################################### +# Module utilities +############################################################################### -if (ARTIST_SKIA AND WIN32) - message(STATUS "Building Artist lib for Win32 with Skia.") -elseif (ARTIST_SKIA AND APPLE) - message(STATUS "Building Artist lib for MacOS with Skia.") -elseif (ARTIST_QUARTZ_2D AND APPLE) - message(STATUS "Building Artist lib for MacOS with Quartz2D.") -endif() +include(BuildType) # Default build type. +include(OptionEx) # Conditional based options, adding a [default: ON/OFF] to the documentation. +include(CheckIPOSupported) -if (APPLE) - if (NOT CMAKE_OSX_ARCHITECTURES) - set(CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR}) +if (CYCFI_ENABLE_GIT_SUBMODULE_CHECK) + if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") + include(GitUtilities) + git_submodule_check(lib/external/libunibreak) + git_submodule_check(lib/infra) endif() - if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "arm64") - message(STATUS "Artist lib MacOS target processor: arm64.") - elseif (${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64") - message(STATUS "Artist lib MacOS target processor: x86_64.") - else() - message(FATAL_ERROR "Unsupported MacOS compiler") +endif() + +if (CYCFI_ENABLE_LTO) + check_ipo_supported(RESULT IPO_SUPPORTED) + if (IPO_SUPPORTED) + message(STATUS "Link-time optimization supported. Will be enabled in Release build type") endif() endif() -message(STATUS "Compiler: ${CMAKE_C_COMPILER_ID}") +############################################################################### +# Options +############################################################################### -add_subdirectory(lib) +option_ex(ARTIST_QUARTZ_2D "Build Artist using Quartz 2D on macOS." APPLE) +option_ex(ARTIST_SKIA "Build Artist using Skia." NOT APPLE) +option_ex(ARTIST_BUILD_EXAMPLES "Build Artist library examples." ON) +option_ex(ARTIST_BUILD_TESTS "Build Artist library tests." ON) -option(ARTIST_BUILD_EXAMPLES "build Artist library examples" ON) -option(ARTIST_BUILD_TESTS "build Artist library tests" ON) +############################################################################### +# Sub projects +############################################################################### + +add_subdirectory(lib) if (ARTIST_BUILD_EXAMPLES) add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1fc8b41..970415b 100755 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,6 @@ ############################################################################### -# Copyright (c) 2016-2023 Joel de Guzman -# -# Distributed under the MIT License (https://opensource.org/licenses/MIT) +# SPDX-FileCopyrightText: 2016-2024 Joel de Guzman +# SPDX-License-Identifier: MIT ############################################################################### project(examples) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c2adb4c..4b8b587 100755 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,15 +1,11 @@ ############################################################################### -# Copyright (c) 2016-2023 Joel de Guzman -# -# Distributed under the MIT License (https://opensource.org/licenses/MIT) +# SPDX-FileCopyrightText: 2016-2024 Joel de Guzman +# SPDX-FileContributor: Modified by Andrea Zanellato +# SPDX-License-Identifier: MIT ############################################################################### -cmake_minimum_required(VERSION 3.7.2...3.15.0) +add_subdirectory(infra) -if (POLICY CMP0135) - cmake_policy(SET CMP0135 NEW) -endif() - -add_library(libunibreak +set(LIBUNIBREAK_FILES external/libunibreak/src/emojidef.c external/libunibreak/src/graphemebreak.c external/libunibreak/src/linebreak.c @@ -19,6 +15,11 @@ add_library(libunibreak external/libunibreak/src/unibreakdef.c external/libunibreak/src/wordbreak.c ) +add_library(libunibreak ${LIBUNIBREAK_FILES}) + +if(CYCFI_USE_EMPTY_SOURCE_GROUPS) + source_group("" FILES ${LIBUNIBREAK_FILES}) +endif() target_include_directories( libunibreak @@ -46,6 +47,8 @@ endif() if (ARTIST_SKIA) + include(ExternalProject) + ############################################################################ # Prebuilt binaries ############################################################################ @@ -217,7 +220,7 @@ set(ARTIST_HEADERS include/artist/canvas.hpp include/artist/circle.hpp include/artist/color.hpp - include/artist/detail + include/artist/detail/canvas_impl.hpp include/artist/font.hpp include/artist/image.hpp include/artist/path.hpp @@ -265,17 +268,27 @@ if (ARTIST_SKIA) ) endif() -source_group("Source Files\\artist" +if(CYCFI_USE_EMPTY_SOURCE_GROUPS) + set(_artist_hdr "") + set(_artist_src "") + set(_artist_impl "") +else() + set(_artist_hdr "Header Files\\artist") + set(_artist_src "Source Files\\artist") + set(_artist_impl "Source Files\\impl") +endif() + +source_group("${_artist_src}" FILES ${ARTIST_SOURCES} ) -source_group("Source Files\\impl" +source_group("${_artist_impl}" FILES ${ARTIST_IMPL} ) -source_group("Header Files\\artist" +source_group("${_artist_hdr}" FILES ${ARTIST_HEADERS} ) @@ -400,8 +413,6 @@ elseif (WIN32) MSVC_RUNTIME_LIBRARY "MultiThreadedDebug" ) endif() - - endif() if (CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/lib/infra b/lib/infra index bb9090c..c52c3fe 160000 --- a/lib/infra +++ b/lib/infra @@ -1 +1 @@ -Subproject commit bb9090ceb0838e3f145c6e40b1cbc26fa48fd12e +Subproject commit c52c3fed4bf4cdc243800d84a0c0f43942cf5923 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3f9afb9..4740b21 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,6 @@ ############################################################################### -# Copyright (c) 2016-2023 Joel de Guzman -# -# Distributed under the MIT License (https://opensource.org/licenses/MIT) +# SPDX-FileCopyrightText: 2016-2024 Joel de Guzman +# SPDX-License-Identifier: MIT ############################################################################### project(artist_test)