Saturday, 15 September 2012

CMake: Linking multiple libraries to two executables in one command -



CMake: Linking multiple libraries to two executables in one command -

i've got 2 executables both of need linked n libraries same:

add_executable(myexe1 main1.cpp) add_executable(myexe2 main2.cpp) target_link_libraries(myexe1 lib1 lib2 lib3 ... libn) target_link_libraries(myexe2 lib1 lib2 lib3 ... libn)

so have write target_link_libraries twice; 1 time myexe1 , 1 time myexe2. there way shorten way mutual libraries linked 2 different executables? wondering if it's possible link lib1 ... libn libraries both myexe1 , myexe2 in 1 command avoid redundancy , create cmake file cleaner.

you can utilize set command set variable list of arguments:

add_executable(myexe1 main1.cpp) add_executable(myexe2 main2.cpp) set(libs lib1 lib2 lib3 ... libn) target_link_libraries(myexe1 ${libs}) target_link_libraries(myexe2 ${libs})

cmake

No comments:

Post a Comment