[CMake] Target Link Library

Nils Gladitz nilsgladitz at gmail.com
Wed Mar 12 05:41:32 EDT 2014


On 12.03.2014 09:58, Lloyd wrote:
> My cross platform project has a main module and a custom library. The 
> main module depends on the custom library. Both these projects need to 
> be built with cmake. At present the option I find to set this is to 
> using the 
> "target_link_library(MyExe ${CMAKE_CURRENT_BINARY_DIR}/myLib.lib)". 
> But this code makes my cmake file platform dependent, that is on 
> windows I need to use the "MyLib.lib" in CMake and on Linux I need to 
> use "MyLib.a" ! Is there a better alternative? (I went through the doc 
> of find_library(), but it doesn't seem to be suitable in this scenatio)

Assuming your library is being build by the project and not manually 
being copied into the binary directory you can use the target name 
instead of the filename of the library.

If you created the target with add_library(mylibrary ...)
target_link_library(MyExe mylibrary) should work.

CMake will fill in the actual full path to the library.

Nils


More information about the CMake mailing list