add cmake option enable-tests

forces a static build and sets up test env
This commit is contained in:
derselbst 2018-04-06 22:52:54 +02:00
parent 17204a26d6
commit de68492710
4 changed files with 26 additions and 7 deletions

View file

@ -55,6 +55,7 @@ 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 and overrides DEFAULT_SOUNDFONT)" off )
# Options enabled by default
option ( enable-aufile "compile support for sound file output" on )
@ -500,16 +501,27 @@ else ( enable-readline )
endif ( enable-readline )
if(enable-tests)
# manipulate some variables to setup a proper test env
set(DEFAULT_SOUNDFONT "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf2")
# 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)
# General configuration file
configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake
${CMAKE_BINARY_DIR}/config.h )
# Process subdirectories
add_subdirectory ( src )
add_subdirectory ( doc )
add_subdirectory ( test )
# pkg-config support
set ( prefix "${CMAKE_INSTALL_PREFIX}" )
set ( exec_prefix "\${prefix}" )

View file

@ -5,8 +5,10 @@ macro ( ADD_FLUID_TEST _test )
# use the local include path to look for fluidsynth.h, as we cannot be sure fluidsynth is already installed
target_include_directories(${_test}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>)
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> # include auto generated headers
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include> # include "normal" public (sub-)headers
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src> # include private headers
)
ADD_TEST(NAME ${_test} COMMAND ${_test})
endmacro ( ADD_FLUID_TEST )

View file

@ -4,9 +4,12 @@ project(fluidsynth-test)
ENABLE_TESTING()
include ( FluidUnitTest )
## add unit tests here ##
ADD_FLUID_TEST(test_sample_cache)
# make test only runs tests, but doesnt build them
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_sample_cache)
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> --verbose --output-on-failure
DEPENDS
test_sample_cache
)

View file

@ -23,6 +23,8 @@ int main()
TEST_ASSERT_NEQ(s[0], '\0');
printf("Attempt to open %s\n", s);
// load a sfont to synth1
TEST_SUCCESS(fluid_synth_sfload(synth1, s, 1));