Get CMake build working under MinGW.

The MinGW linker does not like -VERSION: one little bit.

I rearranged the order of the ifs hoping that MinGW and friends would be a UNIX, but it was not to be.
This commit is contained in:
Jim Hague 2019-10-29 18:04:39 +00:00
parent ea09baf376
commit 633724327f
1 changed files with 9 additions and 9 deletions

View File

@ -1,13 +1,6 @@
# Add version to given shared library linkage.
function(target_shared_library_version lib version_current version_revision version_age)
if (WIN32)
set(rc_template "${CMAKE_CURRENT_SOURCE_DIR}/cmake/include/${lib}_version.rc.in")
if (EXISTS ${rc_template})
configure_file(${rc_template} ${lib}.rc @ONLY)
target_sources(${lib} PRIVATE ${lib}.rc)
endif ()
target_link_libraries(${lib} PRIVATE "-VERSION:${version_current}.${version_revision}")
elseif (APPLE)
if (APPLE)
# Follow libtool. Add one to major version, as version 0 doesn't work.
# But tag dynlib name with current-age.
math(EXPR major_version "${version_current}+1")
@ -15,10 +8,17 @@ function(target_shared_library_version lib version_current version_revision vers
set_target_properties(${lib} PROPERTIES VERSION "${dynlib_version}")
target_link_libraries(${lib} PRIVATE "-compatibility_version ${major_version}")
target_link_libraries(${lib} PRIVATE "-current_version ${major_version}.${version_revision}")
elseif (UNIX)
elseif (UNIX OR MINGW OR MSYS OR CYGWIN)
# Assume GNU ld, and again follow libtool. Major version is current-age.
math(EXPR compat_version "${version_current}-${version_age}")
set_target_properties(${lib} PROPERTIES VERSION "${compat_version}.${version_age}.${version_revision}" SOVERSION "${compat_version}")
elseif (WIN32)
set(rc_template "${CMAKE_CURRENT_SOURCE_DIR}/cmake/include/${lib}_version.rc.in")
if (EXISTS ${rc_template})
configure_file(${rc_template} ${lib}.rc @ONLY)
target_sources(${lib} PRIVATE ${lib}.rc)
endif ()
target_link_libraries(${lib} PRIVATE "-VERSION:${version_current}.${version_revision}")
else ()
message(WARNING "Unknown platform, ${lib} will not be versioned.")
endif ()