Make building examples and tests optional

This commit is contained in:
hasufell 2015-09-05 14:07:22 +02:00
parent 9d3c08fa3f
commit a3dd080fda
No known key found for this signature in database
GPG key ID: 220CD1C5BDEED020

View file

@ -25,6 +25,8 @@ set(LIBSOUNDIO_VERSION "${LIBSOUNDIO_VERSION_MAJOR}.${LIBSOUNDIO_VERSION_MINOR}.
message("Configuring libsoundio version ${LIBSOUNDIO_VERSION}") message("Configuring libsoundio version ${LIBSOUNDIO_VERSION}")
option(BUILD_STATIC_LIBS "Build static libraries" ON) option(BUILD_STATIC_LIBS "Build static libraries" ON)
option(BUILD_EXAMPLE_PROGRAMS "Build example programs" ON)
option(BUILD_TESTS "Build tests" ON)
option(ENABLE_JACK "Enable JACK backend" ON) option(ENABLE_JACK "Enable JACK backend" ON)
option(ENABLE_PULSEAUDIO "Enable PulseAudio backend" ON) option(ENABLE_PULSEAUDIO "Enable PulseAudio backend" ON)
option(ENABLE_ALSA "Enable ALSA backend" ON) option(ENABLE_ALSA "Enable ALSA backend" ON)
@ -254,80 +256,88 @@ install(FILES
# Example Programs # Example Programs
add_executable(sio_sine example/sio_sine.c) if(BUILD_EXAMPLE_PROGRAMS)
set_target_properties(sio_sine PROPERTIES add_executable(sio_sine example/sio_sine.c)
LINKER_LANGUAGE C set_target_properties(sio_sine PROPERTIES
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) LINKER_LANGUAGE C
target_link_libraries(sio_sine libsoundio_shared) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
install(TARGETS sio_sine DESTINATION ${CMAKE_INSTALL_BINDIR}) target_link_libraries(sio_sine libsoundio_shared)
install(TARGETS sio_sine DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(sio_list_devices example/sio_list_devices.c) add_executable(sio_list_devices example/sio_list_devices.c)
set_target_properties(sio_list_devices PROPERTIES set_target_properties(sio_list_devices PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(sio_list_devices libsoundio_shared) target_link_libraries(sio_list_devices libsoundio_shared)
install(TARGETS sio_list_devices DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS sio_list_devices DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(sio_microphone example/sio_microphone.c) add_executable(sio_microphone example/sio_microphone.c)
set_target_properties(sio_microphone PROPERTIES set_target_properties(sio_microphone PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(sio_microphone libsoundio_shared) target_link_libraries(sio_microphone libsoundio_shared)
install(TARGETS sio_microphone DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS sio_microphone DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(sio_record example/sio_record.c) add_executable(sio_record example/sio_record.c)
set_target_properties(sio_record PROPERTIES set_target_properties(sio_record PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(sio_record libsoundio_shared) target_link_libraries(sio_record libsoundio_shared)
install(TARGETS sio_record DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS sio_record DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(BUILD_TESTS)
include_directories(
"${CMAKE_SOURCE_DIR}/test"
)
add_executable(unit_tests "${CMAKE_SOURCE_DIR}/test/unit_tests.cpp" ${LIBSOUNDIO_SOURCES}) add_executable(unit_tests "${CMAKE_SOURCE_DIR}/test/unit_tests.cpp" ${LIBSOUNDIO_SOURCES})
target_link_libraries(unit_tests LINK_PUBLIC ${LIBSOUNDIO_LIBS}) target_link_libraries(unit_tests LINK_PUBLIC ${LIBSOUNDIO_LIBS})
set_target_properties(unit_tests PROPERTIES set_target_properties(unit_tests PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${TEST_CFLAGS} COMPILE_FLAGS ${TEST_CFLAGS}
LINK_FLAGS ${TEST_LDFLAGS} LINK_FLAGS ${TEST_LDFLAGS}
) )
add_executable(latency "${CMAKE_SOURCE_DIR}/test/latency.cpp" ${LIBSOUNDIO_SOURCES}) add_executable(latency "${CMAKE_SOURCE_DIR}/test/latency.cpp" ${LIBSOUNDIO_SOURCES})
target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS}) target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS})
set_target_properties(latency PROPERTIES set_target_properties(latency PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${LIB_CFLAGS} COMPILE_FLAGS ${LIB_CFLAGS}
) )
add_executable(underflow test/underflow.c) add_executable(underflow test/underflow.c)
set_target_properties(underflow PROPERTIES set_target_properties(underflow PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(underflow libsoundio_shared) target_link_libraries(underflow libsoundio_shared)
add_executable(backend_disconnect_recover test/backend_disconnect_recover.c) add_executable(backend_disconnect_recover test/backend_disconnect_recover.c)
set_target_properties(backend_disconnect_recover PROPERTIES set_target_properties(backend_disconnect_recover PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(backend_disconnect_recover libsoundio_shared) target_link_libraries(backend_disconnect_recover libsoundio_shared)
add_executable(overflow test/overflow.c) add_executable(overflow test/overflow.c)
set_target_properties(overflow PROPERTIES set_target_properties(overflow PROPERTIES
LINKER_LANGUAGE C LINKER_LANGUAGE C
COMPILE_FLAGS ${EXAMPLE_CFLAGS}) COMPILE_FLAGS ${EXAMPLE_CFLAGS})
target_link_libraries(overflow libsoundio_shared) target_link_libraries(overflow libsoundio_shared)
add_custom_target(coverage add_custom_target(coverage
DEPENDS unit_tests DEPENDS unit_tests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND lcov --directory . --zerocounters --rc lcov_branch_coverage=1 COMMAND lcov --directory . --zerocounters --rc lcov_branch_coverage=1
COMMAND ./unit_tests COMMAND ./unit_tests
COMMAND lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1 COMMAND lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1
COMMAND lcov --remove coverage.info '/usr/*' --output-file coverage.info.cleaned --rc lcov_branch_coverage=1 COMMAND lcov --remove coverage.info '/usr/*' --output-file coverage.info.cleaned --rc lcov_branch_coverage=1
COMMAND genhtml -o coverage coverage.info.cleaned --rc lcov_branch_coverage=1 COMMAND genhtml -o coverage coverage.info.cleaned --rc lcov_branch_coverage=1
COMMAND rm coverage.info coverage.info.cleaned COMMAND rm coverage.info coverage.info.cleaned
) )
endif()
add_custom_target(doc add_custom_target(doc
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
@ -342,6 +352,8 @@ message("\n"
"* Install Directory : ${CMAKE_INSTALL_PREFIX}\n" "* Install Directory : ${CMAKE_INSTALL_PREFIX}\n"
"* Build Type : ${CMAKE_BUILD_TYPE}\n" "* Build Type : ${CMAKE_BUILD_TYPE}\n"
"* Build static libs : ${BUILD_STATIC_LIBS}\n" "* Build static libs : ${BUILD_STATIC_LIBS}\n"
"* Build examples : ${BUILD_EXAMPLE_PROGRAMS}\n"
"* Build tests : ${BUILD_TESTS}\n"
) )
message( message(