[CMake] NMake Makefiles, 2.4.4 and target link libraries

Bill Hoffman bill.hoffman at kitware.com
Wed Nov 29 13:03:52 EST 2006


Patrick J. Franz -- ML wrote:
> Bill Hoffman wrote:
>
>> There must be something else going on how is my_library_dep defined?  
>> Is it a cmake target?
>
> Yes. It is built earlier via an include() command.
>
>> The following works fine:
>> add_library(bar SHARED bar.c)
>> add_library(foo SHARED foo.c)
>> target_link_libraries(foo bar)
>>
>> It also works if bar is not a cmake built library.   Can you post the 
>> CMakeCache.txt from that project?
>
> Sure. I've attached a sanitized version below of the top-level 
> CMakeLists.txt and the two that are pulled in via. include().
>
> TOP-LEVEL CMAKELISTS.TXT
> -------------------------
> project(set_of_libraries C)
>
> set(LIBRARY_OUTPUT_PATH lib)
>
> add_subdirectory(components/component1)
> add_subdirectory(components/component2)
>
> include_directories(
>   inc
>   components/inc
>   components/component2/src
>   components/component1/src)
>
> link_directories(
>   components/component2/lib
>   components/component1/lib
>   lib)
>
>
> include(cmake/my_library_dep.cmake)
> include(cmake/my_library.cmake)
>
>
> MY_LIBRARY_DEP.CMAKE
> --------------------
> set(my_library_dep_sources
>   src/my_library_dep.c)
> add_library(my_library_dep SHARED ${my_library_dep_sources})
> target_link_libraries(my_library_dep setupapi component1)
>
> set(my_library_dep_lib_name
> ${CMAKE_SHARED_LIBRARY_PREFIX}my_library_dep${CMAKE_SHARED_LIBRARY_SUFFIX}) 
>
> add_custom_command(TARGET my_library_dep POST_BUILD
>   COMMAND cmake -E copy
>   ARGS lib/${my_library_dep_lib_name} t_api/${my_library_dep_lib_name})
>
> MY_LIBRARY.CMAKE
> ----------------
> set(my_library_sources
>   src/my_library.c
>   src/md_library_foo.c)
> add_library(my_library SHARED ${my_library_sources})
> target_link_libraries(my_library component2 my_library_dep)
>
> set(my_library_lib_name
>  ${CMAKE_SHARED_LIBRARY_PREFIX}my_library${CMAKE_SHARED_LIBRARY_SUFFIX})
> add_custom_command(TARGET md POST_BUILD
>   COMMAND cmake -E copy
>   ARGS lib/${my_library_lib_name} t_api/${my_library_lib_name})
>
> Looking at this, I suppose that if ${my_library_dep_lib_name} was also 
> an internal variable, that could explain how the link library names 
> ends up as ${my_library_dep_lib_name}.lib -> my_library.dll.lib?
Can you create a working example of this that shows the problem? 
I have tried a few things, but am unable to see the problem.

This seems to work:

add_library(foo SHARED foo.c)
target_link_libraries(foo bar.dll)

Cmake correctly links to bar.lib.  

-Bill




More information about the CMake mailing list