CMake to create -L <path> -l <lib> link flags for static libraries

I am using CMake 2.8 to create an application based on MQX OS (using CodeWarrior).
The CMake project basically creates a set of static libraries (say, LIB1 and LIB2).
Then I refer to these libraries in the last cmake rule that is executed:

target_add_executable(X ${some_sources})
target_link_libraries(X LIB1 LIB2)

My problem is that some characters are defined in most of the same library.
Thus, a communication command is like:

mwldarm <args> -o <output> <objects> /path/to1/libLIB1.a /path/to2/libLIB2.a

will lead to multiple character error detection. Instead, I would like CMake to generate a communication command, for example:

mwldarm <args> -o <output> <objects> -L/path/to1 -L/path/to2 -lLIB -lLIB2

Question: How to get the following variables from CMAKE?

  • Flags libraries libraries (eg: -L/path/to1 -L/path/to2)
  • (: -lLIB -lLIB2)

RPATH, , , . ?

.
.

+5
3

, CMP0003 , .

, CMakeLists.txt:

CMAKE_POLICY( SET CMP0003 OLD )

- , . , liba.a libb.a, :

LINK_DIRECTORIES( ${paths_to_search_for} )
TARGET_ADD_EXECUTABLE(X ${some_sources} )
ADD_DEPENDENCIES(X LIB1 LIB2)
TARGET_LINK_LIBRARIES(X a b )

, a b , .

+1

, CMP0003 / ,

, , .

-l.

, CMake , CMake -l -l . . . , , , -, -l `-l ', .

# Find out the link.txt      
set(LINK_TXT "${CMAKE_BINARY_DIR}/${ToLinkLib}/CMakeFiles/${ToLinkLIb}.dir/link.txt")

# Add the searching path into link command
add_custom_command(TARGET ${YourTarget} PRE_BUILD
  COMMAND sed ARGS -ie "\"s;[[:blank:]]-l; -L${LIBRARY_OUTPUT_PATH} -l;\"" ${LINK_TXT}
  DEPENDS ${LINK_TXT}
  COMMENT "Hacking CMake: edit __link.txt__ to use -l instead of path to link internal library ...")

# NOTE: Dont't missing the `-l'. 
target_link_libraries(${YourTarget} -l${ToLinkLib})

, , CMake.


: ?

When I run the cross executable compiled for android, which links the shared library created using the same CMake scripts, I encounter a communication failure problem. After I used the aforementioned hacking method to get a new version, I can run my executable with the command as shown below

 $ LD_LIBRARY_PATH=. ./the_exe opts
-1
source

All Articles