[cmake-developers] Apple tests for target_link_libraries failing
Stephen Kelly
steveire at gmail.com
Wed Oct 12 02:22:01 EDT 2011
Bill Hoffman wrote:
> So, basically we this:
>
>
> set(CMAKE_LINK_INTERFACE_LIBRARIES "")
>
> add_library(libA SHARED classA.cpp)
> add_library(libB SHARED classB.cpp)
> add_library(libC SHARED classC.cpp)
>
> generate_export_header(libA)
> generate_export_header(libB)
> generate_export_header(libC)
>
> target_link_libraries(libB libA)
> target_link_libraries(libC libA libB)
>
> add_executable(exec
> "main.cpp"
> )
> target_link_libraries(exec libC )
>
>
> So, setting CMAKE_LINK_INTERFACE_LIBRARIES to "" is supposed to make the
> transitive linking of A and B not happen when linking C. I tried adding
> some print stuff in the code. But, I am not sure where to look.
>
> I added the following:
>
> void cmTarget::SetPropertyDefault(const char* property,
> const char* default_value)
> {
> + bool debug = false;
> + if(strcmp("LINK_INTERFACE_LIBRARIES", property) == 0)
> + debug = true;
> + if(debug) std::cerr << this->GetName() << "\n";
> // Compute the name of the variable holding the default value.
> std::string var = "CMAKE_";
> var += property;
> -
> + if(debug) std::cerr << var << "\n";
> if(const char* value = this->Makefile->GetDefinition(var.c_str()))
> {
> + if(debug) std::cerr << "found it " << value << "\n";
> this->SetProperty(property, value);
> }
> else if(default_value)
> {
> + if(debug) std::cerr << "not found " << default_value << "\n";
> this->SetProperty(property, default_value);
> }
> }
> diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLin
> kLibrariesCommand.cxx
> index 805959d..d2be3fa 100644
> --- a/Source/cmTargetLinkLibrariesCommand.cxx
> +++ b/Source/cmTargetLinkLibrariesCommand.cxx
> @@ -219,6 +219,7 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const cha
> r* lib,
> // Handle normal case first.
> if(!this->DoingInterface)
> {
> + std::cerr << this->Target->GetName() << " Not doing interface" << "\
> n";
> this->Makefile
>
>
> I ended up with this:
>
> libA
> CMAKE_LINK_INTERFACE_LIBRARIES
> found it
> libB
> CMAKE_LINK_INTERFACE_LIBRARIES
> found it
> libC
> CMAKE_LINK_INTERFACE_LIBRARIES
> found it
>
>
> libB Not doing interface
> libC Not doing interface
> libC Not doing interface
>
>
> Do you have other prints that I should add? How is this supposed to work?
>
> -Bill
>
How exactly it works I am not entirely certain. I followed the suggestion in
this thread:
http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/1865/focus=1868
and it just worked for me.
I assume the contents of LINK_INTERFACE_LIBRARIES gets read somewhere else
to create the actual link line. each of libA libB and libC do not get added
to the link_interfaces, and using set(CMAKE_LINK_INTERFACE_LIBRARIES "")
should be the same as using
target_link_libraries(libA LINK_INTERFACE_LIBRARIES "")
for each library.
It works for me, but I don't know why it doesn't work for you. Maybe Brad
can have some insight?
Thanks,
Steve.
More information about the cmake-developers
mailing list