From a8ee0b8c7c7081a5ac427b87e1dee13f75836364 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Sun, 23 Feb 2020 03:57:31 -0600 Subject: [PATCH] More cmake updates and cleanup Visual Studio NuGet package handling was redone to correct a chicken and egg situation. (See the nuget_package() function in audacity/CMakeLists.txt. Due to the change in NuGet handling, was finally able to make the Audacity target dependent on several other targets. This ensures the destination directory is populated correctly. Library handling for system packages reworked to ensure the correct libraries are used and to "workaround" an issue where the libraries weren't being included in the link command...no idea why. New way is better anyway. Don't allow a system library for SBSMS since it seems we have a unique (Audacity-only???) version. Don't define wxDEBUG_LEVEL. It's not needed and causes duplicate symbol warnings. A couple of small changes to config files to remove libmad and libsndfile warnings. Do not include serdi.c and sordi.c in the LV2 build. Fix handling of static Lame and linked FFmpeg libs. Use cmake file() instead of gcc/awk to extract version information from Audacity.h for the Mac Info.plist. Use "cmake -E tar" to zip artifacts in github action. --- .github/workflows/cmake_build.yml | 6 +- CMakeLists.txt | 102 ++++++++++++++----- cmake-proxies/CMakeLists.txt | 5 +- cmake-proxies/FileDialog/CMakeLists.txt | 1 - cmake-proxies/libmad/config.h.in | 2 +- cmake-proxies/libsndfile/config.h.in | 2 +- cmake-proxies/lv2/CMakeLists.txt | 2 - cmake-proxies/mod-null/CMakeLists.txt | 6 -- cmake-proxies/mod-nyq-bench/CMakeLists.txt | 6 -- cmake-proxies/mod-script-pipe/CMakeLists.txt | 1 - help/CMakeLists.txt | 6 +- locale/CMakeLists.txt | 5 +- src/CMakeLists.txt | 70 +++++-------- 13 files changed, 109 insertions(+), 105 deletions(-) diff --git a/.github/workflows/cmake_build.yml b/.github/workflows/cmake_build.yml index 489f8f31f..0a03c22bd 100644 --- a/.github/workflows/cmake_build.yml +++ b/.github/workflows/cmake_build.yml @@ -161,7 +161,7 @@ jobs: rm -f "${DEST}"/{*.iobj,*.ipdb} # Create artifact (zipped as Github actions don't preserve permissions) - powershell -Command "Compress-Archive '${DEST}' '${GITHUB_SHA}.zip'" + cmake -E tar c --format=zip "${GETHUB_SHA}.zip" "${DEST}" # ========================================================================= # MACOS: Build (for all versions of MacOS) @@ -235,7 +235,7 @@ jobs: cp -a build/bin/Release/ "${DEST}" # Create artifact (zipped as Github actions don't preserve permissions) - zip -ry9 "${GITHUB_SHA}.zip" "${DEST}" + cmake -E tar c --format=zip "${GETHUB_SHA}.zip" "${DEST}" # ========================================================================= # UBUNTU: Build (for all versions of Ubuntu) @@ -307,7 +307,7 @@ jobs: chmod +x "${DEST}/audacity" # Create artifact (zipped as Github actions don't preserve permissions) - zip -ry9 "${GITHUB_SHA}.zip" "${DEST}" + cmake -E tar c --format=zip "${GETHUB_SHA}.zip" "${DEST}" # ========================================================================= # SHARED: Attach the artifact to the workflow results diff --git a/CMakeLists.txt b/CMakeLists.txt index e0afcdca3..be5b63aa1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,14 +31,9 @@ cmake_policy( SET CMP0072 NEW ) # Include file check macros honor ``CMAKE_REQUIRED_LIBRARIES``. cmake_policy( SET CMP0075 NEW ) -if( WIN32 ) - # The NuGet packages that the Windows build requires - # (Only here for visibility) - set( GETTEXT_NAME "Gettext.Tools" ) - set( GETTEXT_VERSION "0.20.1.1" ) - set( PYTHON_NAME "python2" ) - set( PYTHON_VERSION "2.7.17" ) -elseif( APPLE ) +# Definitions that must happen before the project() command +if( APPLE ) + # Define the OSX compatibility parameters set( CMAKE_OSX_ARCHITECTURES x86_64 CACHE INTERNAL "" ) set( CMAKE_OSX_DEPLOYMENT_TARGET 10.7 CACHE INTERNAL "" ) @@ -52,9 +47,6 @@ elseif( APPLE ) string( APPEND CMAKE_CXX_FLAGS " -stdlib=libc++" ) endif() -# Define option() prefix -set( _OPT "audacity_" ) - # Add our module path set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake-proxies/cmake-modules) @@ -92,8 +84,11 @@ message( STATUS ) if( APPLE ) message( STATUS " Xcode Version: ${XCODE_VERSION}" ) message( STATUS " MacOS SDK: ${CMAKE_OSX_SYSROOT}" ) + message( STATUS ) endif() -message( STATUS ) + +# Define option() prefix +set( _OPT "audacity_" ) # Try to get the current commit hash find_package( Git QUIET ) @@ -103,6 +98,7 @@ if( GIT_FOUND ) ${GIT_EXECUTABLE} show -s --format='%h' OUTPUT_VARIABLE short_hash + OUTPUT_STRIP_TRAILING_WHITESPACE ) message( STATUS " Current Commit: ${short_hash}" ) message( STATUS ) @@ -402,23 +398,16 @@ macro( get_package_interface package ) ${${package}_INCLUDE_DIRS} ) - set( COPTS - ${${package}_CFLAGS} - ${${package}_CFLAGS_OTHER} - ) - - set( LOPTS - ${${package}_LDFLAGS} - ${${package}_LDFLAGS_OTHER} - ) - set( LINKDIRS - ${${package}_LIBRARY_DIRS} + ${${package}_LIBDIR} ) - set( LIBRARIES - ${${package}_LIBRARIES} - ) + # We resolve the full path of each library to ensure the + # correct one is referenced while linking + foreach( lib ${${package}_LIBRARIES} ) + find_library( LIB_${lib} ${lib} HINTS ${LINKDIRS} ) + list( APPEND LIBRARIES ${LIB_${lib}} ) + endforeach() endmacro() # Set the cache and context value @@ -481,6 +470,63 @@ function( cmd_option name desc ) set( ${name} "${${name}}" PARENT_SCOPE ) endfunction() +# Downloads NuGet packages +# +# Why this is needed... +# +# To get NuGet to work, you have to add the VS_PACKAGE_REFERENCES +# property to a target. This target must NOT be a UTILITY target, +# which is what we use to compile the message catalogs and assemble +# the manual. We could add that property to the Audacity target and +# CMake would add the required nodes to the VS project. And when the +# Audacity target is built, the NuGet packages would get automatically +# downloaded. This also means that the locale and manual targets +# must be dependent on the Audacity target so the packages would get +# downloaded before they execute. This would be handled by the CMake +# provided ALL_BUILD target which is, by default, set as the startup +# project in Visual Studio. Sweet right? Well, not quite... +# +# We want the Audacity target to be the startup project to provide +# eaiser debugging. But, if we do that, the ALL_BUILD target is no +# longer "in control" and any dependents of the Audacity target would +# not get built. So, targets like "nyquist" and "plug-ins" would have +# to be manually built. This is not what we want since Nyquist would +# not be available during Audacity debugging because the Nyquist runtime +# would not be copied into the destination folder alonside the Audacity +# executable. +# +# To remedy this conundrum, we simply download the NuGet packages +# ourselves and make the Audacity target dependent on the targets +# mentioned above. This ensures that the dest folder is populated +# and laid out like Audacity expects. +# +function( nuget_package dir name version ) + # Generate the full package directory name + set( pkgdir "${CMAKE_BINARY_DIR}/packages/${name}/${version}" ) + + # Don't download it again if the package directory already exists + if( NOT EXISTS "${pkgdir}" ) + set( pkgurl "https://www.nuget.org/api/v2/package/${name}/${version}" ) + + # Create the package directory + file( MAKE_DIRECTORY "${pkgdir}" ) + + # And download the package into the package directory + file( DOWNLOAD "${pkgurl}" "${pkgdir}/package.zip" ) + + # Extract the contents of the package into the package directory + execute_process( + COMMAND + ${CMAKE_COMMAND} -E tar x "${pkgdir}/package.zip" + WORKING_DIRECTORY + ${pkgdir} + ) + endif() + + # Return the package directory name to the caller + set( ${dir} "${pkgdir}" PARENT_SCOPE ) +endfunction() + # Add our children add_subdirectory( "cmake-proxies" ) add_subdirectory( "help" ) @@ -489,8 +535,8 @@ add_subdirectory( "locale" ) add_subdirectory( "nyquist" ) add_subdirectory( "plug-ins" ) add_subdirectory( "src" ) -add_subdirectory( "cmake-proxies/mod-null" EXCLUDE_FROM_ALL ) -add_subdirectory( "cmake-proxies/mod-nyq-bench" EXCLUDE_FROM_ALL ) +add_subdirectory( "cmake-proxies/mod-null" ) +add_subdirectory( "cmake-proxies/mod-nyq-bench" ) add_subdirectory( "cmake-proxies/mod-script-pipe" ) # Uncomment what follows for symbol values. diff --git a/cmake-proxies/CMakeLists.txt b/cmake-proxies/CMakeLists.txt index 62384cb10..e74bfe676 100644 --- a/cmake-proxies/CMakeLists.txt +++ b/cmake-proxies/CMakeLists.txt @@ -95,9 +95,6 @@ function( addlib dir name symbol required check ) # And add it to our target target_include_directories( ${TARGET} INTERFACE ${INCLUDES} ) - target_compile_options( ${TARGET} INTERFACE ${COPTS} ) - target_link_directories( ${TARGET} INTERFACE ${LINKDIRS} ) - target_link_options( ${TARGET} INTERFACE ${LOPTS} ) target_link_libraries( ${TARGET} INTERFACE ${LIBRARIES} ) else() set( ${use} "local" ) @@ -170,7 +167,7 @@ addlib( lv2 lv2 LV2 NO YES "lilv-0 >= 0.24.6 addlib( portmidi midi MIDI NO YES "portmidi >= 0.1" ) addlib( portmixer portmixer PORTMIXER NO YES "" ) addlib( portsmf portsmf PORTSMF NO YES "portsmf >= 0.1" ) -addlib( sbsms sbsms SBSMS NO YES "sbsms >= 2.0.2" ) +addlib( sbsms sbsms SBSMS NO YES "" ) addlib( soundtouch soundtouch SOUNDTOUCH NO YES "soundtouch >= 1.7.1" ) addlib( twolame twolame LIBTWOLAME NO YES "twolame >= 0.3.13" ) diff --git a/cmake-proxies/FileDialog/CMakeLists.txt b/cmake-proxies/FileDialog/CMakeLists.txt index 2b22a3f28..bfb96758c 100644 --- a/cmake-proxies/FileDialog/CMakeLists.txt +++ b/cmake-proxies/FileDialog/CMakeLists.txt @@ -18,7 +18,6 @@ list( APPEND INCLUDES list( APPEND DEFINES PRIVATE - wxDEBUG_LEVEL=0 $<$:__WIN32__> ) diff --git a/cmake-proxies/libmad/config.h.in b/cmake-proxies/libmad/config.h.in index ec0889887..97924a322 100644 --- a/cmake-proxies/libmad/config.h.in +++ b/cmake-proxies/libmad/config.h.in @@ -20,7 +20,7 @@ * $Id: acconfig.h,v 1.2 2001-10-21 22:26:32 dmazzoni Exp $ */ -# ifndef LIBMAD_CONFIG_H 1 +# ifndef LIBMAD_CONFIG_H # define LIBMAD_CONFIG_H 1 /***************************************************************************** diff --git a/cmake-proxies/libsndfile/config.h.in b/cmake-proxies/libsndfile/config.h.in index 9c24b947a..9bf5ed837 100644 --- a/cmake-proxies/libsndfile/config.h.in +++ b/cmake-proxies/libsndfile/config.h.in @@ -209,7 +209,7 @@ #cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" /* Set to maximum allowed value of sf_count_t type. */ -#cmakedefine SF_COUNT_MAX @SF_COUNT_MAX@ +/* unused #cmakedefine SF_COUNT_MAX @SF_COUNT_MAX@ */ /* The size of `double', as computed by sizeof. */ #define SIZEOF_DOUBLE @SIZEOF_DOUBLE@ diff --git a/cmake-proxies/lv2/CMakeLists.txt b/cmake-proxies/lv2/CMakeLists.txt index 653dc9191..9c394a8c1 100644 --- a/cmake-proxies/lv2/CMakeLists.txt +++ b/cmake-proxies/lv2/CMakeLists.txt @@ -30,7 +30,6 @@ list( APPEND SOURCES ${TARGET_ROOT}/serd/src/n3.c ${TARGET_ROOT}/serd/src/node.c ${TARGET_ROOT}/serd/src/reader.c - ${TARGET_ROOT}/serd/src/serdi.c ${TARGET_ROOT}/serd/src/string.c ${TARGET_ROOT}/serd/src/uri.c ${TARGET_ROOT}/serd/src/writer.c @@ -39,7 +38,6 @@ list( APPEND SOURCES ${TARGET_ROOT}/sord/src/sord.c ${TARGET_ROOT}/sord/src/sord_validate.c - ${TARGET_ROOT}/sord/src/sordi.c ${TARGET_ROOT}/sord/src/syntax.c ${TARGET_ROOT}/sord/src/zix/btree.c ${TARGET_ROOT}/sord/src/zix/digest.c diff --git a/cmake-proxies/mod-null/CMakeLists.txt b/cmake-proxies/mod-null/CMakeLists.txt index 2dc07b39a..aa55e4f9a 100644 --- a/cmake-proxies/mod-null/CMakeLists.txt +++ b/cmake-proxies/mod-null/CMakeLists.txt @@ -19,11 +19,6 @@ list( APPEND INCLUDES ${TARGET_ROOT} ) -list( APPEND DEFINES - PRIVATE - wxDEBUG_LEVEL=0 -) - list( APPEND LIBRARIES PRIVATE Audacity @@ -39,7 +34,6 @@ set_target_properties( ${TARGET} organize_source( "${TARGET_ROOT}" "" "${SOURCES}" ) target_sources( ${TARGET} PRIVATE ${SOURCES} ) -target_compile_definitions( ${TARGET} PRIVATE ${DEFINES} ) target_include_directories( ${TARGET} PRIVATE ${INCLUDES} ) target_link_libraries( ${TARGET} PRIVATE ${LIBRARIES} ) diff --git a/cmake-proxies/mod-nyq-bench/CMakeLists.txt b/cmake-proxies/mod-nyq-bench/CMakeLists.txt index eb0d774ef..afc4c11ba 100644 --- a/cmake-proxies/mod-nyq-bench/CMakeLists.txt +++ b/cmake-proxies/mod-nyq-bench/CMakeLists.txt @@ -19,11 +19,6 @@ list( APPEND INCLUDES ${TARGET_ROOT} ) -list( APPEND DEFINES - PRIVATE - wxDEBUG_LEVEL=0 -) - list( APPEND LIBRARIES PRIVATE Audacity @@ -41,7 +36,6 @@ set_target_properties( ${TARGET} organize_source( "${TARGET_ROOT}" "" "${SOURCES}" ) target_sources( ${TARGET} PRIVATE ${SOURCES} ) -target_compile_definitions( ${TARGET} PRIVATE ${DEFINES} ) target_include_directories( ${TARGET} PRIVATE ${INCLUDES} ) target_link_libraries( ${TARGET} PRIVATE ${LIBRARIES} ) diff --git a/cmake-proxies/mod-script-pipe/CMakeLists.txt b/cmake-proxies/mod-script-pipe/CMakeLists.txt index 1dc81585f..ba98f1583 100644 --- a/cmake-proxies/mod-script-pipe/CMakeLists.txt +++ b/cmake-proxies/mod-script-pipe/CMakeLists.txt @@ -22,7 +22,6 @@ list( APPEND INCLUDES list( APPEND DEFINES PRIVATE BUILDING_SCRIPT_PIPE - wxDEBUG_LEVEL=0 ) list( APPEND LIBRARIES diff --git a/help/CMakeLists.txt b/help/CMakeLists.txt index 3402a1e52..0200e2bd3 100755 --- a/help/CMakeLists.txt +++ b/help/CMakeLists.txt @@ -15,10 +15,8 @@ set( out_dir "${_INTDIR}" ) set( out "${out_dir}/${host}/index.html" ) if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) - file( TO_NATIVE_PATH - "${CMAKE_BINARY_DIR}/packages/${PYTHON_NAME}.${PYTHON_VERSION}/tools/python.exe" - python - ) + nuget_package( pkgdir "python2" "2.7.17" ) + file( TO_NATIVE_PATH "${pkgdir}/tools/python.exe" python ) else() find_package( Python2 ) if( Python2_FOUND ) diff --git a/locale/CMakeLists.txt b/locale/CMakeLists.txt index 3e10f3a09..893da3889 100755 --- a/locale/CMakeLists.txt +++ b/locale/CMakeLists.txt @@ -65,9 +65,8 @@ list( APPEND SOURCES ) if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) - - file( TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/packages/${GETTEXT_NAME}.${GETTEXT_VERSION}/tools/bin/msgfmt.exe" msgfmt ) - + nuget_package( pkgdir "Gettext.Tools" "0.20.1.1" ) + file( TO_NATIVE_PATH "${pkgdir}/tools/bin/msgfmt.exe" msgfmt ) elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) find_package( Gettext ) mark_as_advanced( FORCE GETTEXT_MSGFMT_EXECUTABLE ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 726f30b0f..9feaed57b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,9 @@ message( STATUS "========== Configuring ${TARGET} ==========" ) set( CMAKE_ENABLE_EXPORTS ON ) add_executable( ${TARGET} ) +add_dependencies( ${TARGET} locale ) +add_dependencies( ${TARGET} nyquist ) +add_dependencies( ${TARGET} plug-ins ) def_vars() @@ -1009,9 +1012,9 @@ list( APPEND RESOURCES list( APPEND DEFINES PRIVATE BUILDING_AUDACITY - wxDEBUG_LEVEL=0 WXINTL_NO_GETTEXT_MACRO WXUSINGDLL + CMAKE $<$: HAVE_LRINT > @@ -1095,50 +1098,38 @@ if( CMAKE_VERSION VERSION_GREATER_EQUAL "3.16" AND NOT CCACHE_PROGRAM ) endif() set( AUDACITY_NAME "Audacity" ) -set( BUILDING_AUDACITY 1 ) +set( BUILDING_AUDACITY YES ) set( INSTALL_PREFIX "${_PREFIX}" ) set( PKGLIBDIR "${_LIBDIR}" ) set( LIBDIR "${_LIBDIR}" ) set( HAVE_GTK ${GTK_FOUND} ) -set( DISABLE_DYNAMIC_LOADING_FFMPEG ${disable_dynamic_loading} ) + +if( "${${_OPT}use_lame}" STREQUAL "local" ) + set( DISABLE_DYNAMIC_LOADING_LAME YES ) +endif() + +if( "${${_OPT}use_ffmpeg}" STREQUAL "linked" ) + set( DISABLE_DYNAMIC_LOADING_FFMPEG YES ) +endif() if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) set( _EXE "Audacity" ) - set_directory_properties( - PROPERTIES - # Make sure Audacity is the startup project - VS_STARTUP_PROJECT "${TARGET}" - ) - - set( PACKAGES - "${GETTEXT_NAME}_${GETTEXT_VERSION}" - "${PYTHON_NAME}_${PYTHON_VERSION}" - ) - set_target_properties( ${TARGET} PROPERTIES # Make sure we're a GUI application and not a console tool WIN32_EXECUTABLE ON - - # These two are for auto-restoring gettext and python - VS_PACKAGE_REFERENCES "${PACKAGES}" - DOTNET_TARGET_FRAMEWORK_VERSION "v4.5" ) - # And copy the NuGet packages config - configure_file( ../win/packages.config packages.config COPYONLY ) - - # Create the config file - configure_file( audacity_config.h.in private/configwin.h ) - # Define the Windows specific resources list( APPEND WIN_RESOURCES ../win/audacity.rc - ../win/packages.config ) + # Create the config file + configure_file( audacity_config.h.in private/configwin.h ) + # Copy over the wxWidgets DLLs if( ${_OPT}use_wxwidgets STREQUAL "system" ) set( wxlibs "$ENV{WXWIN}" ) @@ -1235,7 +1226,7 @@ elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) endif() # Add our required frameworks - list(APPEND LIBRARIES + list( APPEND LIBRARIES PRIVATE "-framework AudioUnit" "-framework CoreAudio" @@ -1247,15 +1238,12 @@ elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) configure_file( audacity_config.h.in private/configmac.h ) # Extract the version information - execute_process( - COMMAND - gcc -E -dM ${_SRCDIR}/Audacity.h - COMMAND - awk "/#define *AUDACITY_(VERSION|RELEASE|REVISION|MODLEVEL) /{printf \"%s %s;\",$2,$3}" - OUTPUT_VARIABLE - output + file( STRINGS ${_SRCDIR}/Audacity.h output + REGEX + "^#define +AUDACITY_(VERSION|RELEASE|REVISION|MODLEVEL) +" ) + # And store as variables foreach( line ${output} ) string( REPLACE " " ";" line ${line}) list( GET line 0 name ) @@ -1278,22 +1266,15 @@ elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) endif() # Define the Wrapper target - add_executable( Wrapper ) + set( WRAPPER_ROOT "${TARGET_ROOT}/../mac" ) + set( WRAPPER_SOURCES "${WRAPPER_ROOT}/Wrapper.c" ) + + add_executable( Wrapper "${WRAPPER_SOURCES}" ) add_dependencies( Wrapper "${TARGET}" ) - set( WRAPPER_ROOT - ${TARGET_ROOT}/../mac - ) - - set( WRAPPER_SOURCES - ${WRAPPER_ROOT}/Wrapper.c - ) - set_target_property_all( "Wrapper" RUNTIME_OUTPUT_DIRECTORY "${_EXEDIR}" ) - organize_source( "${WRAPPER_ROOT}" "mac" "${WRAPPER_SOURCES}" ) - target_sources( "Wrapper" PRIVATE ${WRAPPER_SOURCES} ) elseif( CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD" ) set( _EXE "audacity" ) @@ -1358,7 +1339,6 @@ endif() set_target_property_all( ${TARGET} RUNTIME_OUTPUT_NAME ${_EXE} ) -find_package (Git) if (GIT_FOUND) execute_process( COMMAND