[CMake] Specifying libraries with a variable

John Drescher drescherjm at gmail.com
Tue Oct 2 09:13:57 EDT 2012


On Tue, Oct 2, 2012 at 9:11 AM, Arindam Mukherjee
<arindam.mukerjee at gmail.com> wrote:
> Hi,
>
> I want to define a single variable in a top-level CMakeLists.txt and
> use it in multiple CMakeLists.txt in sub-directories to specify
> target_link_libraries for executables built in these subdirectories. I
> tried defining a custom variable in the root CMakeLists.txt and using
> it in others but its value doesn't seem to be used.
>
> Tried something:
>
> src/CMakeLists.txt
> ------------------------
> set (MYPROJ_LINK_LIBS, "iconv perfstat mylib")
>
>
> src/cmd/dsbv/CMakeLists.txt
> --------------------------
> target_link_libraries(${PROJECT_NAME}, ${MYPROJ_LINK_LIBS})
>
> What's the right way to achieve this?
>

Get rid of the comma in both statements. Also get rid of the quotes in the set.

set (MYPROJ_LINK_LIBS iconv perfstat mylib)
target_link_libraries(${PROJECT_NAME} ${MYPROJ_LINK_LIBS})


John


More information about the CMake mailing list