Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake set VisualStudion2010 parameters "Additional Library Directories"

How can I set with CMake in VisualStudio2010 the property "Additional Library Directories".

Example:

%(AdditionalLibraryDiretories) = "d:/librarys/wnt/i386/debug/"

enter image description here

configuration parameter -> linker -> general-> "Additional Library Directories"

I tried this and it doesn't work.

link_directories("d:/librarys/wnt/i386/debug/")
like image 456
post4dirk Avatar asked Oct 21 '15 07:10

post4dirk


1 Answers

Turning my comments into an answer

What does link_directories() cover?

I tested it with VS2012 / CMake 3.3.0 and if you put your link_directories(...) before your add_executable(...) call it seems to work fine.

link_directories("d:/librarys/wnt/i386")

get_directory_property(_my_link_dirs LINK_DIRECTORIES)
message(STATUS "_my_link_dirs = ${_my_link_dirs}") 

add_executable(...)

Everything you add with link_directories() will be appended to the directory property LINK_DIRECTORIES and assigned to whatever targets are listed afterwards.

In the upper example I get in Visual Studio "Additional Library Directories" property:

d:/librarys/wnt/i386;d:/librarys/wnt/i386/$(Configuration);%(AdditionalLibraryD‌​irectories)

CMake does - to cover libraries depending on Config - include two variants of what you have given in link_directories(): d:/librarys/wnt/i386 and d:/librarys/wnt/i386/$(Configuration).

What if you need more flexiblity?

If your debug/release path names are not matching the VS configuration name (e.g. fooba for debug), then you can't use link_directories(). One approach would be to extend the linker flags directly:

project(...)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:\"d:/librarys/wnt/i386/fooba\"") 

Then I get in the Debug config properties:

%(AdditionalLibraryDirectories);d:/librarys/wnt/i386/fooba

For the lack of flexibility of link_directories() I normally only use the target_link_libraries() command. E.g.:

target_link_libraries(MyExe debug "d:/librarys/wnt/i386/fooba/foo.lib")

would give in the Debug "Additional Dependencies" property:

kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;d:\librarys\wnt\i386\fooba\foo.lib

References

  • CMake link_directories from library
  • cmake - Global linker flag setting (for all targets in directory)
like image 60
Florian Avatar answered Oct 10 '22 04:10

Florian