diff --git a/CMakeLists.txt b/CMakeLists.txt index e69e98eb..de5b69ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,6 +279,14 @@ target_include_directories( ) # Generate and install .pc file +# Stamp the AL version into consuming binaries via a linker-defined symbol. +# --defsym is specific to GNU-compatible linkers: Apple's ld64 and MSVC's +# link.exe reject it, so only emit the flag where it is supported. +if(APPLE OR WIN32) + set(AL_PC_VERSION_SYMBOL_FLAG "") +else() + set(AL_PC_VERSION_SYMBOL_FLAG " -Wl,--defsym,AL_VER_${PROJECT_VERSION}=0") +endif() configure_file(pkgconfig/al-core.pc.in al-core.pc @ONLY) include(GNUInstallDirs) install( diff --git a/pkgconfig/al-core.pc.in b/pkgconfig/al-core.pc.in index 4d9a0d16..5a90d4a7 100644 --- a/pkgconfig/al-core.pc.in +++ b/pkgconfig/al-core.pc.in @@ -8,4 +8,4 @@ Version: @PROJECT_VERSION@ Description: IMAS Access Layer core libraries for C. URL: https://imas.iter.org Cflags: -I${includedir} -Libs: -L${libdir} -lal -Wl,--defsym,AL_VER_@PROJECT_VERSION@=0 -Wl,-rpath,${libdir} +Libs: -L${libdir} -lal@AL_PC_VERSION_SYMBOL_FLAG@ -Wl,-rpath,${libdir}