Skip to content

Commit

Permalink
Define version info in CMakeLists.txt
Browse files Browse the repository at this point in the history
* Version information is now _defined_ at the top of the root
  `CMakeLists.txt` file, which is now the primary source of that
  data. Other instances of version information will consume the
  CMake-defined version information via the appropriate variables.

* `include/Version.h` is eliminated, as it was never used for
  any purpose other than to set the version information for CMake.

* Those GLOBAL PROPERTY entries for JUCE_WINDOWS, JUCE_LINUX, etc.
  Are removed. Those never had any effect, as CMake properties are
  not defined during the build. The Juce header files automatically
  determine the value of the JUCE_ defines.

* The source file globbing (which was always fragile) is replaced
  by a list of modules, from which filenames are generated.

* "-DDEBUG" is added to the CXX_FLAGS for debug builds, and
  CMAKE_BUILD_TYPE is set to "Debug" if not set by the user
  (A comment in the CMakeLists.txt explains in more detail)

* The CMakeLists files are also updated to...
  - Use GnuInstallDirs
  - Be less deeply nested, e.g.
    IF(WIN32)
    ELSEIF(UNIX)
      IF(APPLE)
      ELSE()
      ENDIF()
    ENDIF()

    is replaced by

    if(WIN32)
    endif()
    if(UNIX AND APPLE)
    endif()
    if(UNIX AND NOT APPLE)
    endif()

    as in practice, at most one of those will ever be true.
  • Loading branch information
ferdnyc committed Jun 19, 2019
1 parent 77edb1f commit 6a2c5e6
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 206 deletions.
247 changes: 125 additions & 122 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
#
# Copyright (c) 2008-2019 OpenShot Studios, LLC
# <http://www.openshotstudios.com/>. This file is part of
# OpenShot Audio Library (libopenshot-audio), an open-source project dedicated
# to delivering high quality audio editing and playback solutions to the
# OpenShot Audio Library (libopenshot-audio), an open-source project dedicated
# to delivering high quality audio editing and playback solutions to the
# world. For more information visit <http://www.openshot.org/>.
#
# OpenShot Audio Library (libopenshot-audio) is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# OpenShot Audio Library (libopenshot-audio) is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OpenShot Audio Library (libopenshot-audio) is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License
Expand All @@ -30,58 +30,54 @@ message("\
-----------------------------------------------------------------
Welcome to the OpenShot Build System!
CMake will now check libopenshot's build dependencies and inform
you of any missing files or other issues.
CMake will now check libopenshot-audio's build dependencies and
inform you of any missing files or other issues.
For more information, please visit <http://www.openshot.org/>.
-----------------------------------------------------------------")

################ ADD CMAKE MODULES ##################
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

################ GET VERSION INFORMATION FROM VERSION.H ##################
message(STATUS "Determining Version Number (from Version.h file)")
################ PROJECT VERSION ####################
set(PROJECT_VERSION_FULL "0.1.8-dev1")
set(PROJECT_SO_VERSION 6)

#### Get the lines related to libopenshot version from the Version.h header
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/include/Version.h
OPENSHOT_AUDIO_VERSION_LINES
REGEX "#define[ ]+OPENSHOT_AUDIO_VERSION_.*[0-9]+;.*")

#### Set each line into it's own variable
list (GET OPENSHOT_AUDIO_VERSION_LINES 0 LINE_MAJOR)
list (GET OPENSHOT_AUDIO_VERSION_LINES 1 LINE_MINOR)
list (GET OPENSHOT_AUDIO_VERSION_LINES 2 LINE_BUILD)
list (GET OPENSHOT_AUDIO_VERSION_LINES 3 LINE_SO)

#### Get the version number out of each line
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_AUDIO_VERSION_MAJOR.*([0-9])+;(.*)" "\\1" MAJOR_VERSION "${LINE_MAJOR}")
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_AUDIO_VERSION_MINOR.*([0-9])+;(.*)" "\\1" MINOR_VERSION "${LINE_MINOR}")
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_AUDIO_VERSION_BUILD.*([0-9])+;(.*)" "\\1" BUILD_VERSION "${LINE_BUILD}")
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_AUDIO_VERSION_SO.*([0-9])+;(.*)" "\\1" SO_VERSION "${LINE_SO}")

message(STATUS "MAJOR Version: ${MAJOR_VERSION}")
message(STATUS "MINOR Version: ${MINOR_VERSION}")
message(STATUS "BUILD Version: ${BUILD_VERSION}")
message(STATUS "SO/API/ABI Version: ${SO_VERSION}")
message(STATUS "Determining Version Number - done")
# Remove the dash and anything following, to get the #.#.# version for project()
STRING(REGEX REPLACE "\-.*$" "" VERSION_NUM "${PROJECT_VERSION_FULL}")

################### SETUP PROJECT ###################
project(libopenshot-audio LANGUAGES CXX
VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_VERSION})
# This will define the following variables
# PROJECT_NAME
# PROJECT_VERSION, libopenshot-audio_VERSION
# PROJECT_VERSION_MAJOR, libopenshot-audio_VERSION_MAJOR
# PROJECT_VERSION_MINOR, libopenshot-audio_VERSION_MINOR
# PROJECT_VERSION_PATCH, libopenshot-audio_VERSION_PATCH
PROJECT(libopenshot-audio LANGUAGES C CXX VERSION ${VERSION_NUM})

message("
Generating build files for OpenShot
Building ${PROJECT_NAME} (version ${PROJECT_VERSION})
SO/API/ABI Version: ${SO_VERSION}
SO/API/ABI Version: ${PROJECT_SO_VERSION}
")

#### Enable C++11 (for JUCE)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

#### Enable C Language
ENABLE_LANGUAGE(C)
# Define install paths according to system conventions
# XXX: This must be AFTER THE PROJECT() COMMAND w/ languages enabled,
# in order to properly configure CMAKE_INSTALL_LIBDIR path
include(GNUInstallDirs)


# Juce requires either DEBUG or NDEBUG to be defined on MacOS.
# -DNDEBUG is set by cmake for all release configs, so add
# -DDEBUG for debug builds. We'll do this for all OSes, even
# though only MacOS requires it.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
# Make sure we've picked some build type, default to debug
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()


# Enable stack-unwinding support in c objects on gcc-based platforms.
# Failing to do so will cause your program to be terminated when a png
Expand All @@ -90,17 +86,9 @@ IF (CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
ENDIF(CMAKE_COMPILER_IS_GNUCC)


IF (WIN32)
SET_PROPERTY(GLOBAL PROPERTY JUCE_WINDOWS "JUCE_WINDOWS")
SET_PROPERTY(GLOBAL PROPERTY JUCE_MINGW "JUCE_MINGW")
SET(EXTENSION "cpp")
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})

# Find the base directory of the ASIO SDK (if any)
find_path(ASIO_SDK_DIR iasiodrv.h
PATHS $ENV{ASIO_SDK_DIR} )
find_path(ASIO_SDK_DIR iasiodrv.h PATHS $ENV{ASIO_SDK_DIR} )

IF (ASIO_SDK_DIR)
MESSAGE("FOUND ASIO_SDK_DIR: ${ASIO_SDK_DIR}")
Expand All @@ -110,66 +98,66 @@ IF (WIN32)
MESSAGE("ASIO_SDK_DIR NOT FOUND")
ADD_DEFINITIONS(-DJUCE_ASIO=0)
ENDIF (ASIO_SDK_DIR)

ADD_DEFINITIONS(-DDONT_AUTOLINK_TO_JUCE_LIBRARY)

SET(JUCE_PLATFORM_SPECIFIC_LIBRARIES
${ZLIB_LIBRARIES}
advapi32.lib
comdlg32.lib
gdi32.lib
GlU32.lib
Imm32.dll
kernel32.lib
ole32.lib
OpenGL32.lib
rpcrt4.lib
shell32.lib
Shlwapi.dll
user32.lib
vfw32.lib
version.lib
winmm.lib
wininet.lib
ws2_32.lib
)
ELSE (WIN32)
IF (UNIX)
IF (APPLE)
SET_PROPERTY(GLOBAL PROPERTY JUCE_MAC "JUCE_MAC")
ADD_DEFINITIONS(-DNDEBUG)
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})

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 -lz -framework Accelerate")
SET(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -flax-vector-conversions")

ELSE (APPLE)
SET_PROPERTY(GLOBAL PROPERTY JUCE_LINUX "JUCE_LINUX")
SET(EXTENSION "cpp")

find_package(ZLIB REQUIRED)
find_package(ALSA REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR} ${ALSA_INCLUDE_DIR})
ADD_DEFINITIONS(-DLINUX)
SET(JUCE_PLATFORM_SPECIFIC_LIBRARIES ${ZLIB_LIBRARIES} ${ALSA_LIBRARIES})
SET(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -std=c++11")
ENDIF(APPLE)
ENDIF(UNIX)
ENDIF(WIN32)

# List of modules to build (Extension based on OS)
FILE(GLOB JUCE_SOURCES
JuceLibraryCode/include_juce_*.${EXTENSION})

# Disable RPATH
SET(CMAKE_MACOSX_RPATH 0)

ADD_LIBRARY(openshot-audio SHARED
${JUCE_SOURCES}
advapi32.lib
comdlg32.lib
gdi32.lib
GlU32.lib
Imm32.dll
kernel32.lib
ole32.lib
OpenGL32.lib
rpcrt4.lib
shell32.lib
Shlwapi.dll
user32.lib
vfw32.lib
version.lib
winmm.lib
wininet.lib
ws2_32.lib
)
endif()

if(UNIX AND APPLE)
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 -lz -framework Accelerate")
SET(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -flax-vector-conversions")
endif()

if(UNIX AND NOT APPLE) #Linux
find_package(ALSA REQUIRED)
include_directories(${ALSA_INCLUDE_DIR})
ADD_DEFINITIONS(-DLINUX)
SET(JUCE_PLATFORM_SPECIFIC_LIBRARIES ${ALSA_LIBRARIES})
endif()

# Default extension for source files
if(UNIX AND APPLE)
SET(SOURCE_EXTENSION "mm")
else ()
SET(SOURCE_EXTENSION "cpp")
endif()


# List of modules to build
set(JUCE_MODULES
audio_basics
audio_devices
audio_formats
core
data_structures
events )
# Convert to list of source files (extension based on OS)
foreach(j_module IN LISTS JUCE_MODULES)
list(APPEND JUCE_SOURCES
JuceLibraryCode/include_juce_${j_module}.${SOURCE_EXTENSION} )
endforeach()

ADD_LIBRARY(openshot-audio SHARED ${JUCE_SOURCES} )

# Include header directories
target_include_directories(openshot-audio PUBLIC
Expand All @@ -182,42 +170,57 @@ target_include_directories(openshot-audio PUBLIC
set_target_properties(openshot-audio
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${SO_VERSION}
SOVERSION ${PROJECT_SO_VERSION}
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF
MACOSX_RPATH OFF
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")

# Find threading library
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
TARGET_LINK_LIBRARIES(openshot-audio
target_link_libraries(openshot-audio PUBLIC ${CMAKE_THREAD_LIBS_INIT})

# ZLIB
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
target_link_libraries(openshot-audio PUBLIC ${ZLIB_LIBRARIES})

target_link_libraries(openshot-audio PUBLIC
${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT}
${JUCE_PLATFORM_SPECIFIC_LIBRARIES}
)
${JUCE_PLATFORM_SPECIFIC_LIBRARIES} )

# PROCESS SUB-DIRECTORIES
add_subdirectory(src)

# Determine correct lib folder
set(LIB_INSTALL_DIR lib${LIB_SUFFIX})

# Install Files
#################### INSTALLATION #####################

# Install Header Files
INSTALL(FILES
${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode/JuceHeader.h
${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode/AppConfig.h
DESTINATION include/libopenshot-audio)
${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode/JuceHeader.h
${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode/AppConfig.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot-audio )

INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode/modules/
DESTINATION include/libopenshot-audio
FILES_MATCHING PATTERN "*.h")
INSTALL(TARGETS openshot-audio DESTINATION ${LIB_INSTALL_DIR})
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot-audio
FILES_MATCHING PATTERN "*.h" )

# Install library
INSTALL(TARGETS openshot-audio
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library )

################### DOCUMENTATION ###################
# Find Doxygen (used for documentation)
include(cmake/Modules/UseDoxygen.cmake)

# Install Doxygen html documentation
file(GLOB_RECURSE doc_files ${CMAKE_CURRENT_BINARY_DIR}/doc/html/*.*)
INSTALL(FILES ${doc_files} DESTINATION share/doc/libopenshot-audio)
INSTALL(FILES ${doc_files} DESTINATION ${CMAKE_INSTALL_DOCDIR})

# Install manpage
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/openshot-audio-test-sound.1 DESTINATION share/man/man1)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/openshot-audio-test-sound.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
Loading

0 comments on commit 6a2c5e6

Please sign in to comment.