[CMake] cmake trouble

2012-10-22 Thread 张峰
Hello:
  I am using cmake for three months now.
but was trouble in a situation 。for details bellow: (in Windows,using Microsoft 
Visual Studio 2008)
 
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.
 
 
 


--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Klaim - Joël Lamotte
Hi,

On Mon, Oct 22, 2012 at 5:35 PM, 张峰 fangler2...@126.com wrote:


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


Because until yout call add_executable(), the target name doesn't exist.
You have to use the target name as first parameter of
target_link_libraries().



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



I don't understand the question.



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



For the reason I explained in 1.

Joel Lamotte
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

[CMake] cmake trouble

2012-10-22 Thread 张峰
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.
 
 
 --

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Eric Clark
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-boun...@cmake.org [mailto:cmake-boun...@cmake.org] On Behalf Of ??
Sent: Monday, October 22, 2012 10:25 AM
To: cmake@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=blngljblngcont=0ljtran=With%20best%20%20wishes.




--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Andreas Pakulat
Hi,

On Mon, Oct 22, 2012 at 6:04 PM, Eric Clark ecl...@ara.com wrote:

 First off, you cannot call both add_executable and add_library in the same
 CMakeLists file.

I think there's something missing here, but its perfectly possible to
have one or more library and executable targets specified in the same
cmake file. So this works just fine:

add_library(foo bar.cpp)
add_executable(bar foo.cpp)

There are build-systems that have such limitations, but cmake is not one.

Andreas
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake trouble

2012-10-22 Thread Rolf Eike Beer
Eric Clark wrote:
 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:

Of course you can.

 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.
 
That is indeed correct.

Eike

-- 


signature.asc
Description: This is a digitally signed message part.
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Eric Clark
 -Original Message-
 From: cmake-boun...@cmake.org [mailto:cmake-boun...@cmake.org] On
 Behalf Of Rolf Eike Beer
 Sent: Monday, October 22, 2012 12:11 PM
 To: cmake@cmake.org
 Subject: Re: [CMake] cmake trouble
 
 Eric Clark wrote:
  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:
 
 Of course you can.

Yes, but only if you call project() twice, correct? Maybe I should have been 
more specific. What I meant was that you cannot create two targets for the same 
project (i.e you cannot build an executable and a dll in the same project). In 
the code that was posted, there was no call to project between the call to 
add_library and add_executable. Certainly there is nothing wrong with calling 
project more than once in a list file, but I have found that it is a rare case 
that you want to do this... This could be just my experience, but I can only 
speak for what I know.

I should have been more specific, but if you are going to say of course you 
can, you should probably also explain that this means you need two calls to 
project() as well because the code that was posted did not have two calls to 
project as far as what he posted...

Please, feel free to correct me if I am wrong here... But, I tried this once 
and it did not work and after seeing what I had done, it didn't make sense 
either...

Thanks,
Eric

 
  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.
 
 That is indeed correct.
 
 Eike
 
 --
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake trouble

2012-10-22 Thread Eric Clark
Andreas,

I just replied to a message from another gentleman on here and I may be way off 
base. But, I tried to do this once and it did not work. The only way that I 
could get it to work was to add another project() call between the two... I 
could have had some other issues because it has been quite a while since I had 
this problem and I do not remember the specific error that I got, so I am by no 
means saying anyone is wrong because I am sure that many of you are way more 
familiar with CMake than I am, this is a learning experience for me as well. I 
was just trying to help the guy out and when I looked at his original posting I 
saw test as the same name being passed to add_executable and add_library... I 
went back to look at the code again and he did have one called test and the 
other called fan that was my mistake and my misreading it.

My apologies for saying the wrong thing, I was only trying to help...

Eric

 -Original Message-
 From: Andreas Pakulat [mailto:ap...@gmx.de]
 Sent: Monday, October 22, 2012 12:17 PM
 To: Eric Clark
 Cc: 张峰; cmake@cmake.org
 Subject: Re: [CMake] cmake trouble
 
 Hi,
 
 On Mon, Oct 22, 2012 at 6:04 PM, Eric Clark ecl...@ara.com wrote:
 
  First off, you cannot call both add_executable and add_library in the
  same CMakeLists file.
 
 I think there's something missing here, but its perfectly possible to have one
 or more library and executable targets specified in the same cmake file. So
 this works just fine:
 
 add_library(foo bar.cpp)
 add_executable(bar foo.cpp)
 
 There are build-systems that have such limitations, but cmake is not one.
 
 Andreas
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Eric Clark
 -Original Message-
 From: Andreas Pakulat [mailto:ap...@gmx.de]
 Sent: Monday, October 22, 2012 12:17 PM
 To: Eric Clark
 Cc: 张峰; cmake@cmake.org
 Subject: Re: [CMake] cmake trouble
 
 Hi,
 
 On Mon, Oct 22, 2012 at 6:04 PM, Eric Clark ecl...@ara.com wrote:
 
  First off, you cannot call both add_executable and add_library in the
  same CMakeLists file.
 
 I think there's something missing here, but its perfectly possible to have one
 or more library and executable targets specified in the same cmake file. So
 this works just fine:
 
 add_library(foo bar.cpp)
 add_executable(bar foo.cpp) 

Sorry, me again, but I have a question... If I do use the above code using a 
Visual Studio generator, will this create to separate projects in Visual Studio?

 
 There are build-systems that have such limitations, but cmake is not one.

 
 Andreas
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Rolf Eike Beer
Eric Clark wrote:
  From: Andreas Pakulat [mailto:ap...@gmx.de]
  On Mon, Oct 22, 2012 at 6:04 PM, Eric Clark ecl...@ara.com wrote:

   First off, you cannot call both add_executable and add_library in the
   same CMakeLists file.
  
  I think there's something missing here, but its perfectly possible to have
  one or more library and executable targets specified in the same cmake
  file. So this works just fine:
  
  add_library(foo bar.cpp)
  add_executable(bar foo.cpp) 
 
 
 Sorry, me again, but I have a question... If I do use the above code using a
 Visual Studio generator, will this create to separate projects in Visual
 Studio?

You will have one solution file, but 2 projects in it.

Eike
-- 


signature.asc
Description: This is a digitally signed message part.
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Rolf Eike Beer
Eric Clark wrote:
  Eric Clark wrote:
   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:
  Of course you can.
 
 Yes, but only if you call project() twice, correct?

No, even if you don't call project at all (but you need to call project() in a 
higher level CMakeLists.txt then).

 Maybe I should have been
 more specific. What I meant was that you cannot create two targets for the
 same project (i.e you cannot build an executable and a dll in the same
 project). In the code that was posted, there was no call to project between
 the call to add_library and add_executable. Certainly there is nothing
 wrong with calling project more than once in a list file, but I have found
 that it is a rare case that you want to do this... This could be just my
 experience, but I can only speak for what I know.

The only thing that does not work then is the projectname_SOURCE_DIR variable 
that is set by CMake when you call project(). But otherwise everything is 
fine.

Eike
-- 


signature.asc
Description: This is a digitally signed message part.
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Eric Clark
 -Original Message-
 From: cmake-boun...@cmake.org [mailto:cmake-boun...@cmake.org] On
 Behalf Of Rolf Eike Beer
 Sent: Monday, October 22, 2012 12:48 PM
 To: cmake@cmake.org
 Subject: Re: [CMake] cmake trouble
 
 Eric Clark wrote:
   From: Andreas Pakulat [mailto:ap...@gmx.de] On Mon, Oct 22, 2012 at
   6:04 PM, Eric Clark ecl...@ara.com wrote:
 
First off, you cannot call both add_executable and add_library in
the same CMakeLists file.
  
   I think there's something missing here, but its perfectly possible
   to have one or more library and executable targets specified in the
   same cmake file. So this works just fine:
  
   add_library(foo bar.cpp)
   add_executable(bar foo.cpp)
 
 
  Sorry, me again, but I have a question... If I do use the above code
  using a Visual Studio generator, will this create to separate projects
  in Visual Studio?
 
 You will have one solution file, but 2 projects in it.

Thank you Eike! Forgive my ignorance here... but what will it use to name the 
two projects?

 
 Eike
 --
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake trouble

2012-10-22 Thread Rolf Eike Beer
Eric Clark wrote:
  -Original Message-
  From: cmake-boun...@cmake.org [mailto:cmake-boun...@cmake.org] On
  Behalf Of Rolf Eike Beer
  Sent: Monday, October 22, 2012 12:48 PM
  To: cmake@cmake.org
  Subject: Re: [CMake] cmake trouble
  
  Eric Clark wrote:
From: Andreas Pakulat [mailto:ap...@gmx.de] On Mon, Oct 22, 2012 at

6:04 PM, Eric Clark ecl...@ara.com wrote:
 First off, you cannot call both add_executable and add_library in
 the same CMakeLists file.

I think there's something missing here, but its perfectly possible
to have one or more library and executable targets specified in the
same cmake file. So this works just fine:

add_library(foo bar.cpp)
add_executable(bar foo.cpp)
   
   Sorry, me again, but I have a question... If I do use the above code
   using a Visual Studio generator, will this create to separate projects
   in Visual Studio?
  
  You will have one solution file, but 2 projects in it.
 
 Thank you Eike! Forgive my ignorance here... but what will it use to name
 the two projects?

The name of the target, i.e. the first argument to add_library() and 
add_executable().

Eike
-- 


signature.asc
Description: This is a digitally signed message part.
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] cmake trouble

2012-10-22 Thread Eric Clark
 -Original Message-
 From: cmake-boun...@cmake.org [mailto:cmake-boun...@cmake.org] On
 Behalf Of Rolf Eike Beer
 Sent: Monday, October 22, 2012 12:51 PM
 To: cmake@cmake.org
 Subject: Re: [CMake] cmake trouble
 
 Eric Clark wrote:
   -Original Message-
   From: cmake-boun...@cmake.org [mailto:cmake-boun...@cmake.org]
 On
   Behalf Of Rolf Eike Beer
   Sent: Monday, October 22, 2012 12:48 PM
   To: cmake@cmake.org
   Subject: Re: [CMake] cmake trouble
  
   Eric Clark wrote:
 From: Andreas Pakulat [mailto:ap...@gmx.de] On Mon, Oct 22, 2012
 at

 6:04 PM, Eric Clark ecl...@ara.com wrote:
  First off, you cannot call both add_executable and add_library
  in the same CMakeLists file.

 I think there's something missing here, but its perfectly
 possible to have one or more library and executable targets
 specified in the same cmake file. So this works just fine:

 add_library(foo bar.cpp)
 add_executable(bar foo.cpp)
   
Sorry, me again, but I have a question... If I do use the above
code using a Visual Studio generator, will this create to separate
projects in Visual Studio?
  
   You will have one solution file, but 2 projects in it.
 
  Thank you Eike! Forgive my ignorance here... but what will it use to
  name the two projects?
 
 The name of the target, i.e. the first argument to add_library() and
 add_executable().

Awesome! Thank you for the answers and the quick reply! I have only been using 
CMake for a little over a year and again I am sorry for posting an incorrect 
answer. I always thought that I had to have one project() call for each 
add_executable and/or add_library. It is very good to know that that is not the 
case. However, I am curious if you think it is good practice to do such a thing?

 
 Eike
 --
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake