Skip to content

Commit

Permalink
Use new OpenShot::Audio target in CMakeLists.txt
Browse files Browse the repository at this point in the history
FindOpenShotAudio.cmake: Enhance with targets

- Also, migrate as much config as possible from CMakeLists.txt files
  to properties of IMPORTED OpenShot::Audio target (including platform-
  specific configs)
  • Loading branch information
ferdnyc committed Oct 18, 2020
1 parent 990155a commit 630e7ac
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 69 deletions.
101 changes: 80 additions & 21 deletions cmake/Modules/FindOpenShotAudio.cmake
Expand Up @@ -11,12 +11,14 @@ endif()

# Find the libopenshot-audio header files (check env/cache vars first)
find_path(
LIBOPENSHOT_AUDIO_INCLUDE_DIR
OpenShotAudio_INCLUDE_DIR
JuceHeader.h
HINTS
ENV LIBOPENSHOT_AUDIO_DIR
PATHS
${LIBOPENSHOT_AUDIO_DIR}
${OpenShotAudio_ROOT}
${OpenShotAudio_INCLUDE_DIR}
PATH_SUFFIXES
include/libopenshot-audio
libopenshot-audio
Expand All @@ -26,12 +28,14 @@ find_path(

# Find the libopenshot-audio header files (fallback to std. paths)
find_path(
LIBOPENSHOT_AUDIO_INCLUDE_DIR
OpenShotAudio_INCLUDE_DIR
JuceHeader.h
HINTS
ENV LIBOPENSHOT_AUDIO_DIR
PATHS
${LIBOPENSHOT_AUDIO_DIR}
${OpenShotAudio_ROOT}
${OpenShotAudio_INCLUDE_DIR}
PATH_SUFFIXES
include/libopenshot-audio
libopenshot-audio
Expand All @@ -40,14 +44,16 @@ find_path(

# Find libopenshot-audio.so / libopenshot-audio.dll (check env/cache vars first)
find_library(
LIBOPENSHOT_AUDIO_LIBRARY
OpenShotAudio_LIBRARY
NAMES
libopenshot-audio
openshot-audio
HINTS
ENV LIBOPENSHOT_AUDIO_DIR
PATHS
${LIBOPENSHOT_AUDIO_DIR}
${OpenShotAudio_ROOT}
${OpenShotAudio_LIBRARY}
PATH_SUFFIXES
lib/libopenshot-audio
libopenshot-audio
Expand All @@ -57,60 +63,113 @@ find_library(

# Find libopenshot-audio.so / libopenshot-audio.dll (fallback)
find_library(
LIBOPENSHOT_AUDIO_LIBRARY
OpenShotAudio_LIBRARY
NAMES
libopenshot-audio
openshot-audio
HINTS
ENV LIBOPENSHOT_AUDIO_DIR
PATHS
${LIBOPENSHOT_AUDIO_DIR}
${OpenShotAudio_ROOT}
${OpenShotAudio_LIBRARY}
PATH_SUFFIXES
lib/libopenshot-audio
libopenshot-audio
lib
)

set(LIBOPENSHOT_AUDIO_LIBRARIES "${LIBOPENSHOT_AUDIO_LIBRARY}")
set(LIBOPENSHOT_AUDIO_LIBRARY "${LIBOPENSHOT_AUDIO_LIBRARIES}")
set(LIBOPENSHOT_AUDIO_INCLUDE_DIRS "${LIBOPENSHOT_AUDIO_INCLUDE_DIR}")
set(OpenShotAudio_LIBRARIES "${OpenShotAudio_LIBRARY}")
set(OpenShotAudio_LIBRARY "${OpenShotAudio_LIBRARIES}")
set(OpenShotAudio_INCLUDE_DIRS "${OpenShotAudio_INCLUDE_DIR}")

if(LIBOPENSHOT_AUDIO_INCLUDE_DIR AND EXISTS "${LIBOPENSHOT_AUDIO_INCLUDE_DIR}/JuceHeader.h")
file(STRINGS "${LIBOPENSHOT_AUDIO_INCLUDE_DIR}/JuceHeader.h" libosa_version_str
if(OpenShotAudio_INCLUDE_DIR AND EXISTS "${OpenShotAudio_INCLUDE_DIR}/JuceHeader.h")
file(STRINGS "${OpenShotAudio_INCLUDE_DIR}/JuceHeader.h" libosa_version_str
REGEX "versionString.*=.*\"[^\"]+\"")
if(libosa_version_str MATCHES "versionString.*=.*\"([^\"]+)\"")
set(LIBOPENSHOT_AUDIO_VERSION_STRING ${CMAKE_MATCH_1})
set(OpenShotAudio_VERSION_STRING ${CMAKE_MATCH_1})
endif()
unset(libosa_version_str)
string(REGEX REPLACE "^([0-9]+\.[0-9]+\.[0-9]+).*$" "\\1"
LIBOPENSHOT_AUDIO_VERSION "${LIBOPENSHOT_AUDIO_VERSION_STRING}")
OpenShotAudio_VERSION "${OpenShotAudio_VERSION_STRING}")
endif()

# If we couldn't parse M.N.B version, don't keep any of it
if(NOT LIBOPENSHOT_AUDIO_VERSION)
unset(LIBOPENSHOT_AUDIO_VERSION)
unset(LIBOPENSHOT_AUDIO_VERSION_STRING)
if(NOT OpenShotAudio_VERSION)
unset(OpenShotAudio_VERSION)
unset(OpenShotAudio_VERSION_STRING)
endif()

# Determine compatibility with requested version in find_package()
if(OpenShotAudio_FIND_VERSION AND LIBOPENSHOT_AUDIO_VERSION)
if("${OpenShotAudio_FIND_VERSION}" STREQUAL "${LIBOPENSHOT_AUDIO_VERSION}")
if(OpenShotAudio_FIND_VERSION AND OpenShotAudio_VERSION)
if("${OpenShotAudio_FIND_VERSION}" STREQUAL "${OpenShotAudio_VERSION}")
set(OpenShotAudio_VERSION_EXACT TRUE)
endif()
if("${OpenShotAudio_FIND_VERSION}" VERSION_GREATER "${LIBOPENSHOT_AUDIO_VERSION}")
if("${OpenShotAudio_FIND_VERSION}" VERSION_GREATER "${OpenShotAudio_VERSION}")
set(OpenShotAudio_VERSION_COMPATIBLE FALSE)
else()
set(OpenShotAudio_VERSION_COMPATIBLE TRUE)
endif()
endif()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBOPENSHOT_AUDIO_FOUND to TRUE
# handle the QUIETLY and REQUIRED arguments and set OpenShotAudio_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(OpenShotAudio
REQUIRED_VARS
LIBOPENSHOT_AUDIO_LIBRARY
LIBOPENSHOT_AUDIO_INCLUDE_DIRS
OpenShotAudio_LIBRARIES
OpenShotAudio_INCLUDE_DIRS
VERSION_VAR
LIBOPENSHOT_AUDIO_VERSION_STRING
OpenShotAudio_VERSION_STRING
)

if(OpenShotAudio_FOUND)
set(OpenShotAudio_INCLUDE_DIRS "${OpenShotAudio_INCLUDE_DIRS}"
CACHE PATH "The paths to libopenshot-audio's header files" FORCE)
set(OpenShotAudio_LIBRARIES "${OpenShotAudio_LIBRARIES}"
CACHE STRING "The libopenshot-audio library to link with" FORCE)
if(DEFINED OpenShotAudio_VERSION)
set(OpenShotAudio_VERSION ${OpenShotAudio_VERSION}
CACHE STRING "The version of libopenshot-audio detected" FORCE)
endif()
endif()

if(OpenShotAudio_FOUND AND NOT TARGET OpenShot::Audio)
message(STATUS "Creating IMPORTED target OpenShot::Audio")
if(WIN32)
add_library(OpenShot::Audio UNKNOWN IMPORTED)
else()
add_library(OpenShot::Audio SHARED IMPORTED)
endif()

set_property(TARGET OpenShot::Audio APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${OpenShotAudio_INCLUDE_DIRS}")

if(WIN32)
set_property(TARGET OpenShot::Audio APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS -DIGNORE_JUCE_HYPOT=1)
set_property(TARGET OpenShot::Audio APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS -include cmath)
elseif(APPLE)
# Prevent compiling with __cxx11
set_property(TARGET OpenShot::Audio APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS -D_GLIBCXX_USE_CXX11_ABI=0)
list(APPEND framework_deps
"-framework Carbon"
"-framework Cocoa"
"-framework CoreFoundation"
"-framework CoreAudio"
"-framework CoreMidi"
"-framework IOKit"
"-framework AGL"
"-framework AudioToolbox"
"-framework QuartzCore"
"-lobjc"
"-framework Accelerate"
)
target_link_libraries(OpenShot::Audio PRIVATE ${framework_deps})
endif()

set_property(TARGET OpenShot::Audio APPEND PROPERTY
IMPORTED_LOCATION "${OpenShotAudio_LIBRARIES}")
endif()
35 changes: 7 additions & 28 deletions src/CMakeLists.txt
Expand Up @@ -44,25 +44,6 @@ if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()

################ WINDOWS ##################
# Set some compiler options for Windows
# required for libopenshot-audio headers
if (WIN32)
add_definitions( -DIGNORE_JUCE_HYPOT=1 )
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -include cmath")
endif()

if (APPLE)
# If you still get errors compiling with GCC 4.8, mac headers need to be patched: http://hamelot.co.uk/programming/osx-gcc-dispatch_block_t-has-not-been-declared-invalid-typedef/
set_property(GLOBAL PROPERTY JUCE_MAC "JUCE_MAC")
set(EXTENSION "mm")
set(JUCE_PLATFORM_SPECIFIC_DIR build/macosx/platform_specific_code)
set(JUCE_PLATFORM_SPECIFIC_LIBRARIES "-framework Carbon -framework Cocoa -framework CoreFoundation -framework CoreAudio -framework CoreMidi -framework IOKit -framework AGL -framework AudioToolbox -framework QuartzCore -lobjc -framework Accelerate")

# Prevent compiling with __cxx11
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()

################ IMAGE MAGICK ##################
# Set the Quantum Depth that ImageMagick was built with (default to 16 bits)
if(ENABLE_MAGICK)
Expand Down Expand Up @@ -92,12 +73,6 @@ if(ENABLE_MAGICK)
endif()
endif()

################# LIBOPENSHOT-AUDIO ###################
# Find JUCE-based openshot Audio libraries
find_package(OpenShotAudio 0.2.0 REQUIRED)

# Include Juce headers (needed for compile)
include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})
############### PROFILING #################
#set(PROFILER "/usr/lib/libprofiler.so.0.3.2")
#set(PROFILER "/usr/lib/libtcmalloc.so.4")
Expand Down Expand Up @@ -237,6 +212,10 @@ target_include_directories(openshot
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libopenshot>)

################# LIBOPENSHOT-AUDIO ###################
# Find JUCE-based openshot Audio libraries
find_package(OpenShotAudio 0.2.0 REQUIRED)
target_link_libraries(openshot PUBLIC OpenShot::Audio)

################### JSONCPP #####################
# Include jsoncpp headers (needed for JSON parsing)
Expand Down Expand Up @@ -380,9 +359,9 @@ endif()

############### LINK LIBRARY #################
# Link remaining dependency libraries
target_link_libraries(openshot PUBLIC
${LIBOPENSHOT_AUDIO_LIBRARIES}
${PROFILER})
if(DEFINED PROFILER)
target_link_libraries(openshot PUBLIC ${PROFILER})
endif()

if(ImageMagick_FOUND)
target_link_libraries(openshot PUBLIC ${ImageMagick_LIBRARIES})
Expand Down
20 changes: 0 additions & 20 deletions tests/CMakeLists.txt
Expand Up @@ -28,19 +28,6 @@
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/src/examples/" TEST_MEDIA_PATH)
add_definitions( -DTEST_MEDIA_PATH="${TEST_MEDIA_PATH}" )

################ WINDOWS ##################
# Set some compiler options for Windows
# required for libopenshot-audio headers
if(WIN32)
add_definitions( -DIGNORE_JUCE_HYPOT=1 )
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -include cmath")
endif()

if (APPLE)
# Prevent compiling with __cxx11
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()

################### UNITTEST++ #####################
# Find UnitTest++ libraries (used for unit testing)
find_package(UnitTest++)
Expand Down Expand Up @@ -88,13 +75,6 @@ if(ENABLE_MAGICK)
add_definitions( -DUSE_IMAGEMAGICK=1 )
endif()
endif()
################# LIBOPENSHOT-AUDIO ###################
# Find JUCE-based openshot Audio libraries
find_package(OpenShotAudio 0.2.0 REQUIRED)

# Include Juce headers (needed for compile)
include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})


################# BLACKMAGIC DECKLINK ###################
if(ENABLE_BLACKMAGIC)
Expand Down

0 comments on commit 630e7ac

Please sign in to comment.