[CMake] Testing shared library

2006-07-24 Thread Flávio P. Duarte
Hi,
  I am trying to test a shared library using cmake. In my top level
directory, I have the source directory (src), which contains the source
files to build the library, and a test directory (test), which contains
the source files to build the binaries that will be used to test the
shared library. The problem is the binaries in the test diretory are not
being compiled properly, i. e., they are not being linked against the
shared library in the src directory. In autotools, the shared library
was added as one obj file, like:
g++ -o test1 obj1.o obj2.o ../src/libmylib.so
  I was not able to configure CMake to produce a similar command line.
How can I achieve this ?

I am using the following piece of code:

SET( SRC test1.cpp test2.cpp test3.cpp )

ENABLE_TESTING()

MACRO( ADD_TESTS SRC_LIST )
  FOREACH( IN_FILE ${SRC_LIST} )
STRING( REGEX REPLACE ".cpp" ""  TARGET_NAME "${IN_FILE}" )
ADD_EXECUTABLE( ${TARGET_NAME} ${IN_FILE} test.cpp )
TARGET_LINK_LIBRARIES( ${TARGET_NAME} mylib )
ADD_TEST( ${TARGET_NAME} ${TARGET_NAME} )
  ENDFOREACH( IN_FILE )
ENDMACRO( ADD_TESTS )

LINK_DIRECTORIES( ../src )
ADD_TESTS( "${SRC}" )


Flavio
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Testing shared library

2006-07-24 Thread Brad King
Flávio P. Duarte wrote:
> Hi,
>   I am trying to test a shared library using cmake. In my top level
> directory, I have the source directory (src), which contains the source
> files to build the library, and a test directory (test), which contains
> the source files to build the binaries that will be used to test the
> shared library. The problem is the binaries in the test diretory are not
> being compiled properly, i. e., they are not being linked against the
> shared library in the src directory. In autotools, the shared library
> was added as one obj file, like:
> g++ -o test1 obj1.o obj2.o ../src/libmylib.so
>   I was not able to configure CMake to produce a similar command line.
> How can I achieve this ?

CMake will generate a command line like

  g++ -o test1 obj1.o obj2.o -L../src -lmylib

What problem are you having with this version?

Note also that when linking to another target in the same project with
TARGET_LINK_LIBRARIES you do not need to add the LINK_DIRECTORIES
explicitly.

-Brad
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Testing shared library

2006-07-25 Thread Flávio P. Duarte
It looks like CMake is prependind LD_LIBRARY_PATH before ../src and in
LD_LIBRARY_PATH there is an older version of mylib.
The CMake command line looks like:
/usr/bin/c++   -g -Wall   -fPIC -L/home/user/lib/
"CMakeFiles/test1.dir/obj1.o" "CMakeFiles/test1.dir/obj2.o"   -o test1
-rdynamic -L/home/user/test/src
 I think the first -L is being added to CMake to correspond to
LD_LIBRARY_PATH environment variable. The easiest solution would be get
rid of LD_LIBRARY_PATH, but I consider it as a last option. And if the
first -L corresponds to LD_LIBRARY_PATH, it might be a bug. People will
not be able to test their libraries without changing this variable first.
As an alternative, I thought change the command line, but I open to
suggestions.

Flavio


Brad King wrote:
> Flávio P. Duarte wrote:
>> Hi,
>>   I am trying to test a shared library using cmake. In my top level
>> directory, I have the source directory (src), which contains the source
>> files to build the library, and a test directory (test), which contains
>> the source files to build the binaries that will be used to test the
>> shared library. The problem is the binaries in the test diretory are not
>> being compiled properly, i. e., they are not being linked against the
>> shared library in the src directory. In autotools, the shared library
>> was added as one obj file, like:
>> g++ -o test1 obj1.o obj2.o ../src/libmylib.so
>>   I was not able to configure CMake to produce a similar command line.
>> How can I achieve this ?
> 
> CMake will generate a command line like
> 
>   g++ -o test1 obj1.o obj2.o -L../src -lmylib
> 
> What problem are you having with this version?
> 
> Note also that when linking to another target in the same project with
> TARGET_LINK_LIBRARIES you do not need to add the LINK_DIRECTORIES
> explicitly.
> 
> -Brad
> 
> 

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Testing shared library

2006-07-25 Thread William A. Hoffman
At 02:19 PM 7/25/2006, Flávio P. Duarte wrote:
>It looks like CMake is prependind LD_LIBRARY_PATH before ../src and in
>LD_LIBRARY_PATH there is an older version of mylib.
>The CMake command line looks like:
>/usr/bin/c++   -g -Wall   -fPIC -L/home/user/lib/
>"CMakeFiles/test1.dir/obj1.o" "CMakeFiles/test1.dir/obj2.o"   -o test1
>-rdynamic -L/home/user/test/src
> I think the first -L is being added to CMake to correspond to
>LD_LIBRARY_PATH environment variable. The easiest solution would be get
>rid of LD_LIBRARY_PATH, but I consider it as a last option. And if the
>first -L corresponds to LD_LIBRARY_PATH, it might be a bug. People will
>not be able to test their libraries without changing this variable first.
>As an alternative, I thought change the command line, but I open to
>suggestions.
>
>Flavio

CMake is not looking at LD_LIBRARY_PATH.  You must be doing an in-source
build and creating a library that is being put in /home/user/test/src which
is why cmake is adding the -L.

-Bill

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Testing shared library

2006-07-25 Thread Flávio P. Duarte
William A. Hoffman wrote:
> At 02:19 PM 7/25/2006, Flávio P. Duarte wrote:
>> It looks like CMake is prependind LD_LIBRARY_PATH before ../src and in
>> LD_LIBRARY_PATH there is an older version of mylib.
>> The CMake command line looks like:
>> /usr/bin/c++   -g -Wall   -fPIC -L/home/user/lib/
>> "CMakeFiles/test1.dir/obj1.o" "CMakeFiles/test1.dir/obj2.o"   -o test1
>> -rdynamic -L/home/user/test/src
>> I think the first -L is being added to CMake to correspond to
>> LD_LIBRARY_PATH environment variable. The easiest solution would be get
>> rid of LD_LIBRARY_PATH, but I consider it as a last option. And if the
>> first -L corresponds to LD_LIBRARY_PATH, it might be a bug. People will
>> not be able to test their libraries without changing this variable first.
>>As an alternative, I thought change the command line, but I open to
>> suggestions.
>>
>> Flavio
> 
> CMake is not looking at LD_LIBRARY_PATH.  You must be doing an in-source
> build and creating a library that is being put in /home/user/test/src which
> is why cmake is adding the -L.
The /home/user/test/src directory is ok. You are right about your
statement: It is where the new mylib is located. The problem is
/home/user/lib. This directory should not be there. CMake should place
the project paths before LDFLAGS.

  Apparently I forgot to paste the end of the compiler line, so I am
repeating it:
/usr/bin/c++   -g -Wall   -fPIC -L/home/user/lib/
"CMakeFiles/test1.dir/obj1.o" "CMakeFiles/test1.dir/obj2.o"   -o test1
-rdynamic -L/home/user/test/src -lmylib

Flavio
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake