Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: misc fixes, using new infra modules #22

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 63 additions & 58 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 2 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
41 changes: 26 additions & 15 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -46,6 +47,8 @@ endif()

if (ARTIST_SKIA)

include(ExternalProject)

############################################################################
# Prebuilt binaries
############################################################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
)
Expand Down Expand Up @@ -400,8 +413,6 @@ elseif (WIN32)
MSVC_RUNTIME_LIBRARY "MultiThreadedDebug"
)
endif()


endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
5 changes: 2 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down