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

Update CMake scripts #1365

Merged
merged 14 commits into from May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
342 changes: 157 additions & 185 deletions CMakeLists.txt

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions builds/cmake/Modules/ConfigureWindows.cmake
@@ -0,0 +1,44 @@
if(WIN32)
option(SHARED_RUNTIME "Windows: Build using the shared runtime library (/MD), disable for static runtime (/MT)" ON)

# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(SHARED_RUNTIME)
message(STATUS "Windows: Using dynamic runtime library (/MD)")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS "Windows: Using static runtime library (/MT)")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
endif()

# Target Unicode API
add_definitions(-D_UNICODE)
add_definitions(-DUNICODE)

# Disable API deprecation warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

if(MSVC)
option(MSVC_MULTICORE "MSVC: Build using multiple cores (/MP)" ON)
if (MSVC_MULTICORE)
add_compile_options(/MP)
endif()
endif()
64 changes: 59 additions & 5 deletions builds/cmake/Modules/FindFluidSynth.cmake
@@ -1,10 +1,64 @@
find_library(FLUIDSYNTH_LIBRARY "fluidsynth")
find_path(FLUIDSYNTH_INCLUDE_DIR "fluidsynth.h")
#.rst:
# FindFluidSynth
# -----------
#
# Find the FluidSynth Library
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``fluidsynth::fluidsynth``
# The ``FluidSynth`` library, if found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``FLUIDSYNTH_INCLUDE_DIRS``
# where to find FluidSynth headers.
# ``FLUIDSYNTH_LIBRARIES``
# the libraries to link against to use FluidSynth.
# ``FLUIDSYNTH_FOUND``
# true if the FluidSynth headers and libraries were found.

find_package(PkgConfig QUIET)

pkg_check_modules(PC_FLUIDSYNTH QUIET fluidsynth)

# Look for the header file.
find_path(FLUIDSYNTH_INCLUDE_DIR
NAMES fluidsynth.h
PATH_SUFFIXES libfluidsynth fluidsynth
HINTS ${PC_FLUIDSYNTH_INCLUDE_DIRS})

# Look for the library.
# Allow FLUIDSYNTH_LIBRARY to be set manually, as the location of the FluidSynth library
if(NOT FLUIDSYNTH_LIBRARY)
find_library(FLUIDSYNTH_LIBRARY
NAMES libfluidsynth fluidsynth
HINTS ${PC_FLUIDSYNTH_LIBRARY_DIRS})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FluidSynth DEFAULT_MSG FLUIDSYNTH_LIBRARY FLUIDSYNTH_INCLUDE_DIR)
find_package_handle_standard_args(FluidSynth
REQUIRED_VARS FLUIDSYNTH_LIBRARY FLUIDSYNTH_INCLUDE_DIR)

if(FLUIDSYNTH_FOUND)
set(FLUIDSYNTH_INCLUDE_DIRS ${FLUIDSYNTH_INCLUDE_DIR})

if(NOT FLUIDSYNTH_LIBRARIES)
set(FLUIDSYNTH_LIBRARIES ${FLUIDSYNTH_LIBRARIES})
endif()

set(FLUIDSYNTH_INCLUDE_DIRS ${FLUIDSYNTH_INCLUDE_DIR})
set(FLUIDSYNTH_LIBRARIES ${FLUIDSYNTH_LIBRARY})
if(NOT TARGET fluidsynth::fluidsynth)
add_library(fluidsynth::fluidsynth UNKNOWN IMPORTED)
set_target_properties(fluidsynth::fluidsynth PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FLUIDSYNTH_INCLUDE_DIRS}"
IMPORTED_LOCATION "${FLUIDSYNTH_LIBRARY}")
endif()
endif()

mark_as_advanced(FLUIDSYNTH_INCLUDE_DIR FLUIDSYNTH_LIBRARY)
205 changes: 205 additions & 0 deletions builds/cmake/Modules/FindFreetype.cmake
@@ -0,0 +1,205 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#.rst:
# FindFreetype
# ------------
#
# Find the FreeType font renderer includes and library.
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following :prop_tgt:`IMPORTED` target:
#
# ``Freetype::Freetype``
# The Freetype ``freetype`` library, if found
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``FREETYPE_FOUND``
# true if the Freetype headers and libraries were found
# ``FREETYPE_INCLUDE_DIRS``
# directories containing the Freetype headers. This is the
# concatenation of the variables:
#
# ``FREETYPE_INCLUDE_DIR_ft2build``
# directory holding the main Freetype API configuration header
# ``FREETYPE_INCLUDE_DIR_freetype2``
# directory holding Freetype public headers
# ``FREETYPE_LIBRARIES``
# the library to link against
# ``FREETYPE_VERSION_STRING``
# the version of freetype found (since CMake 2.8.8)
#
# Hints
# ^^^^^
#
# The user may set the environment variable ``FREETYPE_DIR`` to the root
# directory of a Freetype installation.

# Created by Eric Wing.
# Modifications by Alexander Neundorf.
# This file has been renamed to "FindFreetype.cmake" instead of the correct
# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex.

# Ugh, FreeType seems to use some #include trickery which
# makes this harder than it should be. It looks like they
# put ft2build.h in a common/easier-to-find location which
# then contains a #include to a more specific header in a
# more specific location (#include <freetype/config/ftheader.h>).
# Then from there, they need to set a bunch of #define's
# so you can do something like:
# #include FT_FREETYPE_H
# Unfortunately, using CMake's mechanisms like include_directories()
# wants explicit full paths and this trickery doesn't work too well.
# I'm going to attempt to cut out the middleman and hope
# everything still works.

set(FREETYPE_FIND_ARGS
HINTS
ENV FREETYPE_DIR
PATHS
ENV GTKMM_BASEPATH
[HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
)

find_path(
FREETYPE_INCLUDE_DIR_ft2build
ft2build.h
${FREETYPE_FIND_ARGS}
PATH_SUFFIXES
include/freetype2
include
freetype2
)

find_path(
FREETYPE_INCLUDE_DIR_freetype2
NAMES
freetype/config/ftheader.h
config/ftheader.h
${FREETYPE_FIND_ARGS}
PATH_SUFFIXES
include/freetype2
include
freetype2
)

if(NOT FREETYPE_LIBRARY)
find_library(FREETYPE_LIBRARY_RELEASE
NAMES
freetype
libfreetype
freetype219
${FREETYPE_FIND_ARGS}
PATH_SUFFIXES
lib
)
find_library(FREETYPE_LIBRARY_DEBUG
NAMES
freetyped
libfreetyped
freetype219d
${FREETYPE_FIND_ARGS}
PATH_SUFFIXES
lib
)
include(SelectLibraryConfigurations)
select_library_configurations(FREETYPE)
else()
# on Windows, ensure paths are in canonical format (forward slahes):
file(TO_CMAKE_PATH "${FREETYPE_LIBRARY}" FREETYPE_LIBRARY)
endif()

unset(FREETYPE_FIND_ARGS)

# set the user variables
if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS)
endif()
set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")

if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
endif()

if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H)
file(STRINGS "${FREETYPE_H}" freetype_version_str
REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")

unset(FREETYPE_VERSION_STRING)
foreach(VPART MAJOR MINOR PATCH)
foreach(VLINE ${freetype_version_str})
if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$")
set(FREETYPE_VERSION_PART "${CMAKE_MATCH_1}")
if(FREETYPE_VERSION_STRING)
string(APPEND FREETYPE_VERSION_STRING ".${FREETYPE_VERSION_PART}")
else()
set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
endif()
unset(FREETYPE_VERSION_PART)
endif()
endforeach()
endforeach()
endif()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
Freetype
REQUIRED_VARS
FREETYPE_LIBRARY
FREETYPE_INCLUDE_DIRS
VERSION_VAR
FREETYPE_VERSION_STRING
)

mark_as_advanced(
FREETYPE_INCLUDE_DIR_freetype2
FREETYPE_INCLUDE_DIR_ft2build
)

if(Freetype_FOUND)
if(NOT TARGET Freetype::Freetype)
add_library(Freetype::Freetype UNKNOWN IMPORTED)
set_target_properties(Freetype::Freetype PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FREETYPE_INCLUDE_DIRS}")

# Handle circular dependency on harfbuzz
find_package(Harfbuzz QUIET)
if(HARFBUZZ_FOUND)
set_target_properties(Freetype::Freetype PROPERTIES
INTERFACE_LINK_LIBRARIES Harfbuzz::Harfbuzz)
endif()

if(FREETYPE_LIBRARY_RELEASE)
set_property(TARGET Freetype::Freetype APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(Freetype::Freetype PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
IMPORTED_LOCATION_RELEASE "${FREETYPE_LIBRARY_RELEASE}")
endif()

if(FREETYPE_LIBRARY_DEBUG)
set_property(TARGET Freetype::Freetype APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(Freetype::Freetype PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
IMPORTED_LOCATION_DEBUG "${FREETYPE_LIBRARY_DEBUG}")
endif()

if(NOT FREETYPE_LIBRARY_RELEASE AND NOT FREETYPE_LIBRARY_DEBUG)
set_target_properties(Freetype::Freetype PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${FREETYPE_LIBRARY}")
endif()
endif()
endif()
69 changes: 58 additions & 11 deletions builds/cmake/Modules/FindHarfbuzz.cmake
@@ -1,19 +1,66 @@
# HARFBUZZ_INCLUDE_DIR - harfbuzz include directory
# Harfbuzz_FOUND - wether harfbuzz is found
# HARFBUZZ_LIBRARY - harfbuzz library
#.rst:
# FindHarfbuzz
# -----------
#
# Find the Harfbuzz Library
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``Harfbuzz::Harfbuzz``
# The ``Harfbuzz`` library, if found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``HARFBUZZ_INCLUDE_DIRS``
# where to find Harfbuzz headers.
# ``HARFBUZZ_LIBRARIES``
# the libraries to link against to use Harfbuzz.
# ``HARFBUZZ_FOUND``
# true if the Harfbuzz headers and libraries were found.

include(FindPackageHandleStandardArgs)
find_package(PkgConfig QUIET)

pkg_check_modules(PC_HARFBUZZ QUIET harfbuzz)

find_path(HARFBUZZ_INCLUDE_DIR_INTERNAL harfbuzz/hb.h)
find_library(HARFBUZZ_LIBRARY harfbuzz)
if(EXISTS "${HARFBUZZ_INCLUDE_DIR_INTERNAL}")
set(HARFBUZZ_INCLUDE_DIR "${HARFBUZZ_INCLUDE_DIR_INTERNAL}/harfbuzz")
# Look for the header file.
find_path(HARFBUZZ_INCLUDE_DIR
NAMES hb.h
PATH_SUFFIXES libharfbuzz harfbuzz
HINTS ${PC_HARFBUZZ_INCLUDE_DIRS})

# Look for the library.
# Allow HARFBUZZ_LIBRARY to be set manually, as the location of the Harfbuzz library
if(NOT HARFBUZZ_LIBRARY)
find_library(HARFBUZZ_LIBRARY
NAMES libharfbuzz harfbuzz
HINTS ${PC_HARFBUZZ_LIBRARY_DIRS})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Harfbuzz
REQUIRED_VARS HARFBUZZ_INCLUDE_DIR HARFBUZZ_LIBRARY)
REQUIRED_VARS HARFBUZZ_LIBRARY HARFBUZZ_INCLUDE_DIR)

set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR})
set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY})
if(HARFBUZZ_FOUND)
set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR})

if(NOT HARFBUZZ_LIBRARIES)
set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARIES})
endif()

if(NOT TARGET Harfbuzz::Harfbuzz)
add_library(Harfbuzz::Harfbuzz UNKNOWN IMPORTED)
find_library(Freetype REQUIRED)
set_target_properties(Harfbuzz::Harfbuzz PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${HARFBUZZ_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES Freetype::Freetype
IMPORTED_LOCATION "${HARFBUZZ_LIBRARY}")
endif()
endif()

mark_as_advanced(HARFBUZZ_INCLUDE_DIR HARFBUZZ_LIBRARY)