From 6a2c5e66d675c7fb7bed8e5d400d0f4b658dfe81 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 19 Jun 2019 09:04:41 -0400 Subject: [PATCH] Define version info in CMakeLists.txt * 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. --- CMakeLists.txt | 247 +++++++++++++++++++++++---------------------- include/Version.h | 76 -------------- src/CMakeLists.txt | 19 ++-- 3 files changed, 136 insertions(+), 206 deletions(-) delete mode 100644 include/Version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 410f4ade..aaefd6c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,18 +6,18 @@ # # Copyright (c) 2008-2019 OpenShot Studios, LLC # . 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 . # -# 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 @@ -30,8 +30,8 @@ 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 . -----------------------------------------------------------------") @@ -39,49 +39,45 @@ For more information, please visit . ################ 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 @@ -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}") @@ -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 @@ -182,34 +170,48 @@ 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) @@ -217,7 +219,8 @@ 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 ) diff --git a/include/Version.h b/include/Version.h deleted file mode 100644 index 81517990..00000000 --- a/include/Version.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file - * @brief Header file that includes the version number of libopenshot-audio - * @author Jonathan Thomas - * - * @section LICENSE - * - * Copyright (c) 2008-2016 OpenShot Studios, LLC - * . 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 world. For more - * information visit . - * - * 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 Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OpenShot Library. If not, see . - */ - -#ifndef OPENSHOT_AUDIO_VERSION_H -#define OPENSHOT_AUDIO_VERSION_H - -// Crazy c++ macro to convert an integer into a string -#ifndef STRINGIZE - #define STRINGIZE_(x) #x - #define STRINGIZE(x) STRINGIZE_(x) -#endif - -#define OPENSHOT_AUDIO_VERSION_MAJOR 0; /// Major version number is incremented when huge features are added or improved. -#define OPENSHOT_AUDIO_VERSION_MINOR 1; /// Minor version is incremented when smaller (but still very important) improvements are added. -#define OPENSHOT_AUDIO_VERSION_BUILD 8; /// Build number is incremented when minor bug fixes and less important improvements are added. -#define OPENSHOT_AUDIO_VERSION_SO 6; /// Shared object version number. This increments any time the API and ABI changes (so old apps will no longer link) -#define OPENSHOT_AUDIO_VERSION_MAJOR_MINOR STRINGIZE(OPENSHOT_AUDIO_VERSION_MAJOR) "." STRINGIZE(OPENSHOT_AUDIO_VERSION_MINOR); /// A string of the "Major.Minor" version -#define OPENSHOT_AUDIO_VERSION_ALL STRINGIZE(OPENSHOT_AUDIO_VERSION_MAJOR) "." STRINGIZE(OPENSHOT_AUDIO_VERSION_MINOR) "." STRINGIZE(OPENSHOT_AUDIO_VERSION_BUILD); /// A string of the entire version "Major.Minor.Build" - -#include - -/// This struct holds version number information. Use the GetVersion() method to access the current version of libopenshot. -struct OpenShotAudioVersion -{ - int major; /// Major version number - int minor; /// Minor version number - int build; /// Build number - int so; /// Shared Object Number (incremented when API or ABI changes) - - /// Get a string version of the version (i.e. "Major.Minor.Build") - string ToString() { - stringstream version_string; - version_string << major << "." << minor << "." << build; - return version_string.str(); - } -}; - -/// Get the current version number of libopenshot (major, minor, and build number) -static OpenShotAudioVersion GetVersion() -{ - OpenShotAudioVersion version; - - // Set version info - version.major = OPENSHOT_AUDIO_VERSION_MAJOR; - version.minor = OPENSHOT_AUDIO_VERSION_MINOR; - version.build = OPENSHOT_AUDIO_VERSION_BUILD; - version.so = OPENSHOT_AUDIO_VERSION_SO; - - return version; -} - -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 351ea837..a3148af7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,18 +6,18 @@ # # Copyright (c) 2008-2016 OpenShot Studios, LLC # . 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 . # -# 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 @@ -29,7 +29,10 @@ add_executable(openshot-audio-test-sound Main.cpp) target_link_libraries(openshot-audio-test-sound openshot-audio) set_target_properties(openshot-audio-test-sound PROPERTIES - CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS OFF + MACOSX_RPATH OFF ) # Install Test Executable -INSTALL(TARGETS openshot-audio-test-sound DESTINATION bin) +INSTALL(TARGETS openshot-audio-test-sound DESTINATION ${CMAKE_INSTALL_BINDIR})