CMake 3.24 added Path Transformation generator expressions, so this can now be done with generators:
$<PATH:REMOVE_EXTENSION,$<TARGET_FILE_NAME:${lib}>>
In my case I wanted to change the extension, which is also easy to do now:
$<PATH:REPLACE_EXTENSION,$<TARGET_FILE_NAME:${lib}>,new_extension>