[CMake] cmake trouble

Eric Clark eclark at ara.com
Mon Oct 22 12:04:22 EDT 2012


Hello,

First off, you cannot call both add_executable and add_library in the same CMakeLists file. Here is what I can say about your other questions:


1.       All commands that require a target have to come after you have created the target via add_executable or add_library. This is simply because you need to have a target before you can adds things to it.

2.       I am not real sure why this would work. But, for common practices, you should always call target_link_libraries after your call to add_library or add_executable for the reason stated above.

3.       Again, this is the same answer. It will work as long as you make the call to the command after add_library or add_executable.

Hope this helps.
Eric

From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of ??
Sent: Monday, October 22, 2012 10:25 AM
To: cmake at cmake.org
Subject: [CMake] cmake trouble

Hello:
      I am using cmake for three months now.
but was trouble in a situation 。for details bellow: (in Windows)

ADD_LIBRARY(test SHARED  ${LIBTEST_SRC} ${LIBHELLO_SRC})
#ADD_LIBRARY(test STATIC ${LIBTEST_SRC} ${LIBHELLO_SRC})

#add executable
AUX_SOURCE_DIRECTORY(. FAN_SRC)
TARGET_LINK_LIBRARIES(fan test)
ADD_EXECUTABLE(fan ${FAN_SRC})

1.if i put "TARGET_LINK_LIBRARIES(fan test)" before ADD_EXECUTABLE command,this does not work ,why??

2. but if i  ADD_LIBRARY(test STATIC ${LIBTEST_SRC} ${LIBHELLO_SRC}) ,it is  ok,why ??

3.if i put "TARGET_LINK_LIBRARIES(fan test)" after ADD_EXECUTABLE command,it works ,why ??

I am waiting for your help !!

With best wishes.<app:lj:%E6%AD%A4%E8%87%B4%E6%95%AC%E7%A4%BC?ljtype=blng&ljblngcont=0&ljtran=With%20best%20%20wishes.>




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121022/080d0f41/attachment.htm>


More information about the CMake mailing list