#StackBounty: #c++ #c #cmake CMake – Changing shared library link options

Bounty: 200

I want to manipulate the linker call in my linker trampoline python script, but for the life of me I cannot get CMake to respect the CMAKE_CXX_CREATE_SHARED_LIBRARY value. It always uses the CMAKE_CXX_COMPILER for linking. If I switch to an add_executable and instead use CMAKE_CXX_LINK_EXECUTABLE this works perfectly. Is there anyway to convince CMake to respect the setting of CMAKE_CXX_CREATE_SHARED_LIBRARY?

A trivial CMakeLists.txt

cmake_minimum_required( VERSION 3.12 )

project( mylib )

include( CMakePrintSystemInformation )

add_library( mylib SHARED mylib.cpp )

A toolchain excerpt

I’ve tried this in both a toolchain file and an -C pre-cache option.

set( CMAKE_LINKER "/path/to/linker_trampoline.py" )
set( CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_LINKER> --CMAKE_CXX_COMPILER <CMAKE_CXX_COMPILER> --CMAKE_SHARED_LIBRARY_CXX_FLAGS <CMAKE_SHARED_LIBRARY_CXX_FLAGS> --LANGUAGE_COMPILE_FLAGS <LANGUAGE_COMPILE_FLAGS> --LINK_FLAGS <LINK_FLAGS> --CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> --SONAME_FLAG <SONAME_FLAG> --TARGET_SONAME <TARGET_SONAME> --TARGET <TARGET> --OBJECTS <OBJECTS> --LINK_LIBRARIES <LINK_LIBRARIES>" CACHE STRING "" FORCE )


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.