From be7cf582d514547da9074fa4bbfaf40c68c90f1e Mon Sep 17 00:00:00 2001 From: redtide Date: Fri, 8 Mar 2024 22:45:43 +0100 Subject: [PATCH] CMake: misc fixes, using new infra modules --- CMakeLists.txt | 89 +++++++++++++++++++++++----------------------- lib/CMakeLists.txt | 37 +++++++++++-------- lib/infra | 2 +- 3 files changed, 69 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e19867..ccf62e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,65 +3,57 @@ # # Distributed under the MIT License (https://opensource.org/licenses/MIT) ############################################################################### -cmake_minimum_required(VERSION 3.7.2...3.15.0) -include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) +cmake_minimum_required(VERSION 3.18) 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) +############################################################################### +# Settings +############################################################################### + +# 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() -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") +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() + 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.") +############################################################################### +# Module utilities +############################################################################### + +include(BuildType) # Default build type. +include(GitUtilities) # Ensure presence of Git submodules (when not using a source tarball). +include(OptionEx) # Conditional based options, adding a [default: ON/OFF] to the documentation. include(CheckIPOSupported) + +# TODO: 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() -if (APPLE) - option(ARTIST_QUARTZ_2D "build Artist using quartz 2d on MacOS" ON) - option(ARTIST_SKIA "build Artist using skia" OFF) -else() - option(ARTIST_SKIA "build Artist using skia" ON) -endif() - -if (ARTIST_SKIA) - set(ARTIST_QUARTZ_2D OFF) -endif() - -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.") +if (EXISTS "${CMAKE_SOURCE_DIR}/.git") + git_submodule_check(lib/external/libunibreak) endif() +# TODO: Move compiler settings to a settings module if (APPLE) if (NOT CMAKE_OSX_ARCHITECTURES) set(CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR}) @@ -74,13 +66,22 @@ if (APPLE) message(FATAL_ERROR "Unsupported MacOS compiler") endif() endif() - message(STATUS "Compiler: ${CMAKE_C_COMPILER_ID}") -add_subdirectory(lib) +############################################################################### +# Options +############################################################################### + +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) + +############################################################################### +# Sub projects +############################################################################### -option(ARTIST_BUILD_EXAMPLES "build Artist library examples" ON) -option(ARTIST_BUILD_TESTS "build Artist library tests" ON) +add_subdirectory(lib) if (ARTIST_BUILD_EXAMPLES) add_subdirectory(examples) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c2adb4c..0ce0d7b 100755 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -3,13 +3,9 @@ # # Distributed under the MIT License (https://opensource.org/licenses/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") @@ -429,5 +440,3 @@ if (ARTIST_SKIA) "${ARTIST_DEPEPENDENCIES}" ) endif() - - diff --git a/lib/infra b/lib/infra index bb9090c..a4909fe 160000 --- a/lib/infra +++ b/lib/infra @@ -1 +1 @@ -Subproject commit bb9090ceb0838e3f145c6e40b1cbc26fa48fd12e +Subproject commit a4909fe3b3bb6600556f666754f8e3c16a7e354f