CMake fixes

* Set static runtime by default for MinGW

  Autotools does the same. Also fixes bug - compiler flags for MinGW were
  cleared by when ENABLE_STATIC_RUNTIME is OFF (default).

  Also ENABLE_STATIC_RUNTIME option disabled for MinGW.

* Better CMake policies handling
* Add SndFile::sndfile alias library
* Don not add programs to package config-file
* Update README.md
* Fix generator expression with src/version-metadata.rc
This commit is contained in:
evpobr 2020-08-03 14:11:31 +05:00
parent 676eb28fc2
commit af49a5021c
3 changed files with 20 additions and 24 deletions

View File

@ -1,8 +1,4 @@
cmake_minimum_required (VERSION 3.1.3)
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif ()
cmake_minimum_required (VERSION 3.1..3.18)
project(sndfile VERSION 1.0.29)
@ -49,7 +45,7 @@ option (BUILD_EXAMPLES "Build examples" ON)
option (ENABLE_CPACK "Enable CPack support" ON)
option (ENABLE_EXPERIMENTAL "Enable experimental code" OFF)
option (ENABLE_BOW_DOCS "Enable black-on-white html docs" OFF)
if (MSVC OR MINGW)
if (MSVC)
option (ENABLE_STATIC_RUNTIME "Enable static runtime" OFF)
endif ()
option (ENABLE_PACKAGE_CONFIG "Generate and install package config file" ON)
@ -94,7 +90,7 @@ if (WIN32 AND (NOT MINGW) AND BUILD_SHARED_LIBS)
add_feature_info (ENABLE_COMPATIBLE_LIBSNDFILE_NAME ENABLE_COMPATIBLE_LIBSNDFILE_NAME "Set DLL name to libsndfile-1.dll (canonical name), sndfile.dll otherwise")
endif ()
if (MSVC OR MINGW)
if (MSVC)
add_feature_info (ENABLE_STATIC_RUNTIME ENABLE_STATIC_RUNTIME "Enable static runtime")
endif ()
@ -213,7 +209,7 @@ add_library (sndfile
src/chanmap.c
src/id3.c
$<$<BOOL:${WIN32}>:src/windows.c>
$<$<AND:$<BOOL:${WIN32}>,$<BOOL:${WIN32}>>:src/version-metadata.rc>
$<$<AND:$<BOOL:${WIN32}>,$<BOOL:${BUILD_SHARED_LIBS}>>:src/version-metadata.rc>
src/sndfile.c
src/aiff.c
src/au.c
@ -296,6 +292,8 @@ add_library (sndfile
${CMAKE_CURRENT_BINARY_DIR}/src/config.h
)
add_library (SndFile::sndfile ALIAS sndfile)
target_include_directories(sndfile
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
@ -610,8 +608,11 @@ if (ENABLE_PACKAGE_CONFIG)
set (CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/SndFile)
endif()
install (TARGETS ${SNDFILE_PROGRAM_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install (TARGETS sndfile ${SNDFILE_PROGRAM_TARGETS}
install (TARGETS sndfile
EXPORT SndFileTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

View File

@ -162,9 +162,9 @@ Deprecated options:
### Linking from CMake projects
First you need to add `FindOgg.cmake`, `FindVorbis.cmake`, `FindVorbisEnc.cmake`,
`FindFLAC.cmake` and `FindOpus.cmake` files to some directory inside your CMake
project (usually `cmake`) and add it to `CMAKE_MODULE_PATH`:
First you need to add `FindOgg.cmake`, `FindVorbis.cmake`, `FindFLAC.cmake` and
`FindOpus.cmake` files to some directory inside your CMake project (usually
`cmake`) and add it to `CMAKE_MODULE_PATH`:
project(SomeApplication)

View File

@ -213,6 +213,13 @@ if (MSVC)
add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
endif (MSVC)
if (MINGW)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -s")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++ -s")
endif ()
if (ENABLE_STATIC_RUNTIME)
if (MSVC)
foreach (flag_var
@ -226,12 +233,6 @@ if (ENABLE_STATIC_RUNTIME)
endif ()
endforeach (flag_var)
endif (MSVC)
if (MINGW)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -s")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++ -s")
endif (MINGW)
elseif (NOT ENABLE_STATIC_RUNTIME)
if (MSVC)
foreach (flag_var
@ -245,12 +246,6 @@ elseif (NOT ENABLE_STATIC_RUNTIME)
endif (${flag_var} MATCHES "/MT")
endforeach (flag_var)
endif ()
if (MINGW)
set (CMAKE_C_FLAGS "")
set (CMAKE_CXX_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
endif ()
endif ( )
if (BUILD_SHARED_LIBS)