2020-05-01 08:32:12 +02:00
|
|
|
include(CMakeDependentOption)
|
|
|
|
|
|
2020-03-14 22:55:03 +01:00
|
|
|
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to be used")
|
|
|
|
|
set(CMAKE_C_STANDARD 99 CACHE STRING "C standard to be used")
|
2019-11-25 16:10:30 +01:00
|
|
|
|
|
|
|
|
# Export the compile_commands.json file
|
|
|
|
|
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
|
|
# Only install what's explicitely said
|
|
|
|
|
set (CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
|
2020-01-18 17:31:16 +01:00
|
|
|
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
set (CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
|
|
|
set (CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
2019-11-25 16:10:30 +01:00
|
|
|
|
2020-03-06 14:37:25 +01:00
|
|
|
# Set Windows compatibility level to 7
|
2020-01-31 18:25:51 +01:00
|
|
|
if (WIN32)
|
2020-03-06 14:37:25 +01:00
|
|
|
add_compile_definitions(_WIN32_WINNT=0x601)
|
2020-01-31 18:25:51 +01:00
|
|
|
endif()
|
|
|
|
|
|
2020-09-05 07:03:57 +02:00
|
|
|
# Set macOS compatibility level
|
|
|
|
|
if (APPLE)
|
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-08-29 04:54:18 +02:00
|
|
|
# Do not define macros `min` and `max`
|
|
|
|
|
if (WIN32)
|
|
|
|
|
add_compile_definitions(NOMINMAX)
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-09-07 05:52:18 -07:00
|
|
|
# Find macOS system libraries
|
|
|
|
|
if(APPLE)
|
|
|
|
|
find_library(APPLE_COREFOUNDATION_LIBRARY "CoreFoundation")
|
|
|
|
|
find_library(APPLE_FOUNDATION_LIBRARY "Foundation")
|
|
|
|
|
find_library(APPLE_COCOA_LIBRARY "Cocoa")
|
|
|
|
|
find_library(APPLE_CARBON_LIBRARY "Carbon")
|
|
|
|
|
find_library(APPLE_OPENGL_LIBRARY "OpenGL")
|
|
|
|
|
find_library(APPLE_ACCELERATE_LIBRARY "Accelerate")
|
|
|
|
|
find_library(APPLE_QUARTZCORE_LIBRARY "QuartzCore")
|
|
|
|
|
find_library(APPLE_AUDIOTOOLBOX_LIBRARY "AudioToolbox")
|
|
|
|
|
find_library(APPLE_AUDIOUNIT_LIBRARY "AudioUnit")
|
|
|
|
|
find_library(APPLE_COREAUDIO_LIBRARY "CoreAudio")
|
|
|
|
|
find_library(APPLE_COREMIDI_LIBRARY "CoreMIDI")
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-04-01 18:42:41 +02:00
|
|
|
# The variable CMAKE_SYSTEM_PROCESSOR is incorrect on Visual studio...
|
|
|
|
|
# see https://gitlab.kitware.com/cmake/cmake/issues/15170
|
|
|
|
|
|
2020-04-02 16:53:55 +02:00
|
|
|
if (NOT SFIZZ_SYSTEM_PROCESSOR)
|
|
|
|
|
if(MSVC)
|
|
|
|
|
set(SFIZZ_SYSTEM_PROCESSOR "${MSVC_CXX_ARCHITECTURE_ID}")
|
|
|
|
|
else()
|
|
|
|
|
set(SFIZZ_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
|
endif()
|
2020-04-01 18:42:41 +02:00
|
|
|
endif()
|
|
|
|
|
|
2019-11-25 16:10:30 +01:00
|
|
|
# Add required flags for the builds
|
2020-01-31 18:25:51 +01:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
2019-11-25 16:10:30 +01:00
|
|
|
add_compile_options(-Wall)
|
|
|
|
|
add_compile_options(-Wextra)
|
2020-10-10 16:15:41 +02:00
|
|
|
add_compile_options(-Wno-multichar)
|
2020-09-08 11:32:38 +02:00
|
|
|
add_compile_options(-Werror=return-type)
|
2020-04-04 19:50:45 +02:00
|
|
|
if (SFIZZ_SYSTEM_PROCESSOR MATCHES "^(i.86|x86_64)$")
|
2020-04-01 18:42:41 +02:00
|
|
|
add_compile_options(-msse2)
|
2020-09-18 22:04:13 +01:00
|
|
|
elseif(SFIZZ_SYSTEM_PROCESSOR MATCHES "^(arm.*)$")
|
2020-09-20 15:06:01 +01:00
|
|
|
add_compile_options(-mfpu=neon)
|
2020-09-18 22:04:13 +01:00
|
|
|
add_compile_options(-mfloat-abi=hard)
|
2020-04-01 18:42:41 +02:00
|
|
|
endif()
|
2020-01-31 18:25:51 +01:00
|
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2020-01-05 00:14:25 +01:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
add_compile_options(/Zc:__cplusplus)
|
2020-01-19 00:22:16 +01:00
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
2019-11-25 16:10:30 +01:00
|
|
|
endif()
|
|
|
|
|
|
2020-09-02 00:36:49 +02:00
|
|
|
function(sfizz_enable_fast_math NAME)
|
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
|
|
|
target_compile_options("${NAME}" PRIVATE "-ffast-math")
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2020-08-29 04:54:18 +02:00
|
|
|
# The sndfile library
|
2020-01-31 18:25:51 +01:00
|
|
|
add_library(sfizz-sndfile INTERFACE)
|
2019-11-25 16:10:30 +01:00
|
|
|
|
2020-09-19 15:39:46 +02:00
|
|
|
# The jsl utility library for C++
|
|
|
|
|
add_library(sfizz-jsl INTERFACE)
|
|
|
|
|
target_include_directories(sfizz-jsl INTERFACE "external/jsl/include")
|
|
|
|
|
|
2020-01-31 18:25:51 +01:00
|
|
|
if (SFIZZ_USE_VCPKG OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2020-08-31 10:53:16 +02:00
|
|
|
find_package(SndFile CONFIG REQUIRED)
|
2020-01-24 09:18:51 +01:00
|
|
|
find_path(SNDFILE_INCLUDE_DIR sndfile.hh)
|
2020-01-31 18:25:51 +01:00
|
|
|
target_include_directories(sfizz-sndfile INTERFACE "${SNDFILE_INCLUDE_DIR}")
|
2020-08-31 10:53:16 +02:00
|
|
|
target_link_libraries(sfizz-sndfile INTERFACE SndFile::sndfile)
|
2020-01-31 18:25:51 +01:00
|
|
|
else()
|
|
|
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
|
pkg_check_modules(SNDFILE "sndfile" REQUIRED)
|
|
|
|
|
target_include_directories(sfizz-sndfile INTERFACE ${SNDFILE_INCLUDE_DIRS})
|
2020-08-29 04:54:18 +02:00
|
|
|
if (SFIZZ_STATIC_DEPENDENCIES)
|
2020-02-26 16:10:35 +01:00
|
|
|
target_link_libraries(sfizz-sndfile INTERFACE ${SNDFILE_STATIC_LIBRARIES})
|
|
|
|
|
else()
|
|
|
|
|
target_link_libraries(sfizz-sndfile INTERFACE ${SNDFILE_LIBRARIES})
|
|
|
|
|
endif()
|
2020-08-29 04:54:18 +02:00
|
|
|
link_directories(${SNDFILE_LIBRARY_DIRS})
|
2020-01-24 09:18:51 +01:00
|
|
|
endif()
|
2020-01-24 11:15:11 +01:00
|
|
|
|
2020-03-03 13:11:31 +01:00
|
|
|
|
2020-05-01 08:32:12 +02:00
|
|
|
# If we build with Clang, optionally use libc++. Enabled by default on Apple OS.
|
|
|
|
|
cmake_dependent_option(USE_LIBCPP "Use libc++ with clang" "${APPLE}"
|
|
|
|
|
"CMAKE_CXX_COMPILER_ID MATCHES Clang" OFF)
|
2020-03-11 15:44:03 +01:00
|
|
|
if (USE_LIBCPP)
|
2020-05-01 08:32:12 +02:00
|
|
|
add_compile_options(-stdlib=libc++)
|
|
|
|
|
# Presumably need the above for linking too, maybe other options missing as well
|
|
|
|
|
add_link_options(-stdlib=libc++) # New command on CMake master, not in 3.12 release
|
|
|
|
|
add_link_options(-lc++abi) # New command on CMake master, not in 3.12 release
|
2020-03-11 15:44:03 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
add_library(sfizz-pugixml STATIC "src/external/pugixml/src/pugixml.cpp")
|
|
|
|
|
target_include_directories(sfizz-pugixml PUBLIC "src/external/pugixml/src")
|
2020-01-19 01:10:42 +01:00
|
|
|
|
2020-03-03 13:11:31 +01:00
|
|
|
add_library(sfizz-spline STATIC "src/external/spline/spline/spline.cpp")
|
|
|
|
|
target_include_directories(sfizz-spline PUBLIC "src/external/spline")
|
|
|
|
|
|
2020-05-19 14:51:33 +02:00
|
|
|
add_library(sfizz-tunings STATIC "src/external/tunings/src/Tunings.cpp")
|
|
|
|
|
target_include_directories(sfizz-tunings PUBLIC "src/external/tunings/include")
|
|
|
|
|
|
2020-03-07 14:18:47 +01:00
|
|
|
include (CheckLibraryExists)
|
2020-04-13 15:30:07 +02:00
|
|
|
add_library (sfizz-atomic INTERFACE)
|
2020-03-07 14:18:47 +01:00
|
|
|
if (UNIX AND NOT APPLE)
|
2020-04-13 15:30:07 +02:00
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/check_libatomic")
|
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/check_libatomic/check_libatomic.c" "int main() { return 0; }")
|
|
|
|
|
try_compile(SFIZZ_LINK_LIBATOMIC "${CMAKE_CURRENT_BINARY_DIR}/check_libatomic"
|
|
|
|
|
SOURCES "${CMAKE_CURRENT_BINARY_DIR}/check_libatomic/check_libatomic.c"
|
|
|
|
|
LINK_LIBRARIES "atomic")
|
|
|
|
|
if (SFIZZ_LINK_LIBATOMIC)
|
|
|
|
|
target_link_libraries (sfizz-atomic INTERFACE "atomic")
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
set(SFIZZ_LINK_LIBATOMIC FALSE)
|
2020-03-07 14:18:47 +01:00
|
|
|
endif()
|
|
|
|
|
|
2020-01-19 01:10:42 +01:00
|
|
|
# Don't show build information when building a different project
|
|
|
|
|
function (show_build_info_if_needed)
|
|
|
|
|
if (CMAKE_PROJECT_NAME STREQUAL "sfizz")
|
|
|
|
|
message (STATUS "
|
|
|
|
|
Project name: ${PROJECT_NAME}
|
|
|
|
|
Build type: ${CMAKE_BUILD_TYPE}
|
2020-04-02 16:30:37 +02:00
|
|
|
Build processor: ${SFIZZ_SYSTEM_PROCESSOR}
|
2020-01-19 01:10:42 +01:00
|
|
|
Build using LTO: ${ENABLE_LTO}
|
|
|
|
|
Build as shared library: ${SFIZZ_SHARED}
|
|
|
|
|
Build JACK stand-alone client: ${SFIZZ_JACK}
|
|
|
|
|
Build LV2 plug-in: ${SFIZZ_LV2}
|
2020-08-29 04:54:18 +02:00
|
|
|
Build LV2 user interface: ${SFIZZ_LV2_UI}
|
2020-03-14 21:08:39 +01:00
|
|
|
Build VST plug-in: ${SFIZZ_VST}
|
2020-05-13 04:10:16 -07:00
|
|
|
Build AU plug-in: ${SFIZZ_AU}
|
2020-01-19 01:10:42 +01:00
|
|
|
Build benchmarks: ${SFIZZ_BENCHMARKS}
|
|
|
|
|
Build tests: ${SFIZZ_TESTS}
|
2020-02-26 16:10:35 +01:00
|
|
|
Use vcpkg: ${SFIZZ_USE_VCPKG}
|
2020-08-29 04:54:18 +02:00
|
|
|
Statically link dependencies: ${SFIZZ_STATIC_DEPENDENCIES}
|
2020-04-13 15:30:07 +02:00
|
|
|
Link libatomic: ${SFIZZ_LINK_LIBATOMIC}
|
2020-05-01 08:32:12 +02:00
|
|
|
Use clang libc++: ${USE_LIBCPP}
|
2020-05-19 23:42:10 +02:00
|
|
|
Release asserts: ${SFIZZ_RELEASE_ASSERTS}
|
2020-01-19 01:10:42 +01:00
|
|
|
|
|
|
|
|
Install prefix: ${CMAKE_INSTALL_PREFIX}
|
|
|
|
|
LV2 destination directory: ${LV2PLUGIN_INSTALL_DIR}
|
|
|
|
|
|
|
|
|
|
Compiler CXX debug flags: ${CMAKE_CXX_FLAGS_DEBUG}
|
|
|
|
|
Compiler CXX release flags: ${CMAKE_CXX_FLAGS_RELEASE}
|
|
|
|
|
Compiler CXX min size flags: ${CMAKE_CXX_FLAGS_MINSIZEREL}
|
|
|
|
|
")
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2020-01-18 17:31:16 +01:00
|
|
|
find_package (Threads REQUIRED)
|