Skip to content

Commit

Permalink
CMake: misc fixes, using new infra modules
Browse files Browse the repository at this point in the history
  • Loading branch information
redtide committed Mar 8, 2024
1 parent 9f57012 commit be7cf58
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 59 deletions.
89 changes: 45 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand Down
37 changes: 23 additions & 14 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 Expand Up @@ -429,5 +440,3 @@ if (ARTIST_SKIA)
"${ARTIST_DEPEPENDENCIES}"
)
endif()


0 comments on commit be7cf58

Please sign in to comment.