Skip to content

Commit

Permalink
Add LIBSAMPLERATE_ENABLE_WARNINGS to generically enable warnings
Browse files Browse the repository at this point in the history
Useful for (and used in) CI
Some defines required to fix MSVC warnings
  • Loading branch information
Flamefire committed Aug 9, 2019
1 parent 2dbf029 commit b487324
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ env:
script:
- mkdir build
- cd build
- cmake -DBUILD_SHARED_LIBS=$CMAKE_SHARED -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="-Wall -Wextra -Werror" ..
- cmake -DBUILD_SHARED_LIBS=$CMAKE_SHARED -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DLIBSAMPLERATE_ENABLE_WARNINGS=ON ..
- cat config.h
- cmake --build . --config $BUILD_TYPE && ctest --output-on-failure -C $BUILD_TYPE
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ endif()
option(LIBSAMPLERATE_TESTS "Enable to generate test targets" ${IS_ROOT_PROJECT})
option(LIBSAMPLERATE_EXAMPLES "Enable to generate examples" ${IS_ROOT_PROJECT})
option(LIBSAMPLERATE_INSTALL "Enable to add install directives" ${IS_ROOT_PROJECT})
option(LIBSAMPLERATE_ENABLE_WARNINGS "Enable compiler warnings and fail compile if any triggers" OFF)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

Expand Down Expand Up @@ -106,6 +107,15 @@ target_include_directories(samplerate PUBLIC
${PROJECT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR})

if(LIBSAMPLERATE_ENABLE_WARNINGS)
if(MSVC)
target_compile_options(samplerate PUBLIC /W3 /WX)
target_compile_options(samplerate PUBLIC /wd4305 /wd4244) # Disable truncation warning double->float
else()
target_compile_options(samplerate PUBLIC -Wall -Wextra -pedantic -Werror)
endif()
endif()

if(NEED_MATH)
target_link_libraries(samplerate PUBLIC m)
endif()
Expand All @@ -126,6 +136,9 @@ if(LIBSAMPLERATE_TESTS)
if(FFTW_FOUND)
target_link_libraries(${testName} PUBLIC ${FFTW_LIBRARY})
endif()
if(MSVC)
target_compile_definitions(${testName} PUBLIC _CRT_SECURE_NO_WARNINGS _CRT_OBSOLETE_NO_WARNINGS)
endif()
add_test(NAME ${testName} COMMAND ${testName})
endforeach(testSrc)
endif()
Expand Down

0 comments on commit b487324

Please sign in to comment.