From 521e5451fc2922e5e0137d0e4cdb2d00b9d0a413 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sun, 5 Aug 2018 17:55:07 +0200 Subject: [PATCH] remove cmake option enable-tests Always build unit tests instead and use cmakes OBJECT library to bypass visibility control and the value of BUILD_SHARED_LIBS. --- .appveyor-vcpkg.yml | 3 +-- .appveyor.yml | 6 ++---- .travis.yml | 5 +++-- CMakeLists.txt | 22 +++++++++------------- cmake_admin/FluidUnitTest.cmake | 2 +- src/CMakeLists.txt | 9 +++++---- test/README.md | 5 ++--- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/.appveyor-vcpkg.yml b/.appveyor-vcpkg.yml index 2fdf8b18..24645e58 100644 --- a/.appveyor-vcpkg.yml +++ b/.appveyor-vcpkg.yml @@ -57,8 +57,7 @@ build_script: - cd build - cmake -G "%generator%" %CMAKE_FLAGS% -Denable-pkgconfig=0 -DCMAKE_TOOLCHAIN_FILE=c:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake .. - cmake --build . --config Release # build libfluidsynth and fluidsynth exec - - cmake -Denable-tests=1 .. - - cmake --build . --config Release --target check # build unittests + - cmake --build . --config Release --target check # build and exec unittests after_build: - 7z a fluidsynth-vcpkg-%platform%.zip %APPVEYOR_BUILD_FOLDER%\build\src\Release\* diff --git a/.appveyor.yml b/.appveyor.yml index 1230535a..3f96c23c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -72,10 +72,8 @@ build_script: - mkdir build - cd build - cmake -G "%generator%" .. - - cmake --build . --config Release # build libfluidsynth and fluidsynth exec -# FIXME the linker doesnt find gthread-2.0.lib in the second run, why??? -# - cmake -Denable-tests=1 .. -# - cmake --build . --config Release --target check # build unittests + - cmake --build . --config Release + - cmake --build . --config Release --target check # build and exec unittests after_build: - 7z a fluidsynth-%platform%.zip %APPVEYOR_BUILD_FOLDER%\build\src\Release\* c:\deps\bin\libglib*.dll c:\deps\bin\libgthread*.dll c:\deps\bin\*intl*.dll diff --git a/.travis.yml b/.travis.yml index f1115842..82b3e1aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -220,6 +220,7 @@ before_script: - mkdir build && cd build script: - - cmake -DCMAKE_INSTALL_PREFIX=$HOME/fluidsynth_install ${CMAKE_FLAGS} "-Denable-portaudio=1" "-Denable-ladspa=1" "-DCMAKE_BUILD_TYPE=RelWithDebInfo" .. + - cmake -DCMAKE_INSTALL_PREFIX=$HOME/fluidsynth_install ${CMAKE_FLAGS} "-Denable-portaudio=1" "-Denable-ladspa=1" "-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=1" .. - make -j4 - - if [ $TRAVIS_OS_NAME = linux ]; then make install; cmake -Denable-tests=1 ..; make check; fi # install only on linux, as CMAKE_INSTALL_PREFIX is ignored for frameworks on macosx and I cant tell whether that's correct or a bug. also build unit test only on linux, as libintl is not found on macosx + - make check + - if [ $TRAVIS_OS_NAME = linux ]; then make install; fi # install only on linux, as CMAKE_INSTALL_PREFIX is ignored for frameworks on macosx and I cant tell whether that's correct or a bug. diff --git a/CMakeLists.txt b/CMakeLists.txt index cd6d728c..0eb07af9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,6 @@ option ( enable-fpe-check "enable Floating Point Exception checks and debug mess option ( enable-portaudio "compile PortAudio support" off ) option ( enable-profiling "profile the dsp code" off ) option ( enable-trap-on-fpe "enable SIGFPE trap on Floating Point Exceptions" off ) -option ( enable-tests "build unit tests (implicitly disables BUILD_SHARED_LIBS)" off ) # Options enabled by default option ( enable-aufile "compile support for sound file output" on ) @@ -107,6 +106,11 @@ mark_as_advanced ( LIB_SUFFIX ) # the default C standard to use for all targets set(CMAKE_C_STANDARD 90) +# Compile with position independent code if the user requested a shared lib, i.e. no PIC if static requested. +# This is cmakes default behavior, but here it's explicitly required due to the use of libfluidsynth-OBJ as object library, +# which would otherwise always be compiled without PIC. +set ( CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} ) + # the default global visibility level for all target # no visibility support on OS2 if ( NOT OS2 ) @@ -543,19 +547,11 @@ if ( OpenMP_FOUND OR OpenMP_C_FOUND ) endif() endif() +# manipulate some variables to setup a proper test env +set(TEST_SOUNDFONT "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf2") +set(TEST_SOUNDFONT_SF3 "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf3") -if(enable-tests) - # manipulate some variables to setup a proper test env - set(TEST_SOUNDFONT "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf2") - set(TEST_SOUNDFONT_SF3 "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf3") - - # force to build a static lib, in order to bypass the visibility control, allowing us - # to test fluidsynths private/internal functions - set(BUILD_SHARED_LIBS OFF) - - add_subdirectory ( test ) -endif(enable-tests) - +add_subdirectory ( test ) # General configuration file configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake diff --git a/cmake_admin/FluidUnitTest.cmake b/cmake_admin/FluidUnitTest.cmake index dcced0fd..1487c719 100644 --- a/cmake_admin/FluidUnitTest.cmake +++ b/cmake_admin/FluidUnitTest.cmake @@ -1,5 +1,5 @@ macro ( ADD_FLUID_TEST _test ) - ADD_EXECUTABLE(${_test} ${_test}.c) + ADD_EXECUTABLE(${_test} ${_test}.c $ ) TARGET_LINK_LIBRARIES(${_test} libfluidsynth) # use the local include path to look for fluidsynth.h, as we cannot be sure fluidsynth is already installed diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a365730e..4a4853bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -247,10 +247,7 @@ link_directories ( ${DBUS_LIBRARY_DIRS} ) - -# note: by default this target creates a shared object (or dll). To build a -# static library instead, set the option BUILD_SHARED_LIBS to FALSE. -add_library ( libfluidsynth +add_library ( libfluidsynth-OBJ OBJECT ${config_SOURCES} ${fluid_alsa_SOURCES} ${fluid_coreaudio_SOURCES} @@ -270,6 +267,10 @@ add_library ( libfluidsynth ${VersionFilesOutputVariable} ) +# note: by default this target creates a shared object (or dll). To build a +# static library instead, set the option BUILD_SHARED_LIBS to FALSE. +add_library ( libfluidsynth $ ) + if ( MACOSX_FRAMEWORK ) set_property ( SOURCE ${public_HEADERS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/fluidsynth diff --git a/test/README.md b/test/README.md index ad466b4a..518bbbc8 100644 --- a/test/README.md +++ b/test/README.md @@ -16,6 +16,5 @@ To add a unit test just duplicate an existing one, give it a unique name and upd * adding a call to `ADD_FLUID_TEST()` and * a dependency to the custom `check` target. -Make sure you call cmake with `-Denable-tests=1` to build and execute the tests via `make check`. Unit -tests should use the `VintageDreamsWaves-v2.sf2` as test soundfont. Use the `TEST_SOUNDFONT` macro to -access it. +Execute the tests via `make check`. Unit tests should use the `VintageDreamsWaves-v2.sf2` as test soundfont. +Use the `TEST_SOUNDFONT` macro to access it.