[CMake] Makefile to CMakeLists.txt (GTEST)

Kevyn-Alexandre Paré kapare at rogue-research.com
Wed Dec 1 10:59:21 EST 2010


Philip,

Thx for the reply. Neither of these solutions change a thing.

I try to play with ADD_CUSTOM_TARGET but same error...

ADD_CUSTOM_TARGET(RRThread.o ALL COMMAND ${CMAKE_C_COMPILER} -I
${MICRONTRACKER_COMMON_PATH} -I${GTEST_HEADER_PATH} -lpthread -c
${MICRONTRACKER_COMMON_PATH}RRThread.c
${UNIT_TEST_PATH}common/UT_RRThread.cc)

ADD_CUSTOM_TARGET(UT_RRThread ALL COMMAND ${CMAKE_CXX_COMPILER} -I
${MICRONTRACKER_COMMON_PATH} -I${GTEST_HEADER_PATH} -lpthread RRThread.o
UT_RRThread.o ${GTEST_LIB_PATH}gtest.a ${GTEST_LIB_PATH}gtest_main.a -o
UT_RRThread)

Result:
UT_RRThread.o: In function `thread_proc(void*)':
UT_RRThread.cc:(.text+0x28): undefined reference to `exitThread()'
...

I pretty sure that I'm missing little detail. How can I implicitly add
dependency to the object during the linking?

Regards

--
Kevyn-Alexandre Paré


On Mon, 2010-11-29 at 18:17 -0500, Philip Lowman wrote:
> Try adding the "gtest.a" library as well.  Also, order does matter
> when you are linking static libraries so you might need to play with
> the ordering.
> 
> 
> Also, when you get some time, have a look at FindGTest.cmake.  It may
> help you simplify adding your tests.
> 
> On Mon, Nov 29, 2010 at 5:55 PM, Kevyn-Alexandre Paré
> <kapare at rogue-research.com> wrote:
>         Hi,
>         
>         /// -> What I trying to do is to compile my unit test with
>         google test
>         with cmake from a working Makefile.
>         
>         /// -> Here the Makefile::::
>         
>         RRThread.o : $(USER_DIR)/RRThread.c $(USER_DIR)/RRThread.h
>         $(GTEST_HEADERS)
>            $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/RRThread.c
>         
>         UT_RRThread.o : $(UNITTEST_DIR)/UT_RRThread.cc \
>                             $(USER_DIR)/RRThread.h $(GTEST_HEADERS)#
>            $(CXX) $(CPPFLAGS) $(CXXFLAGS) -I$(USER_DIR) -c
>         $(UNITTEST_DIR)/UT_RRThread.cc
>         
>         UT_RRThread : RRThread.o UT_RRThread.o gtest_main.a
>            $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
>         
>         
>         /// -> Here how I thought of doing it with CMakeLists.txt:::
>         
>         INCLUDE_DIRECTORIES(${GTEST_HEADER} ${USER_DIR})
>         
>         ADD_EXECUTABLE(UT ${USER_DIR}RRThread.c
>         ${UNIT_TEST_PATH}UT_RRThread.cc)
>         
>         TARGET_LINK_LIBRARIES(UT pthread
>         ${GTEST_LIB_PATH}gtest_main.a)
>         
>         /// -> My result:
>         
>         Linking CXX executable UT
>         /usr/bin/cmake -E cmake_link_script CMakeFiles/UT.dir/link.txt
>         --verbose=1
>         /usr/bin/c++      CMakeFiles/UT.dir/common/RRThread.c.o
>         CMakeFiles/UT.dir/UnitTests/common/UT_RRThread.cc.o  -o UT
>         -rdynamic
>         -lpthread /home/andromeda/rogue-research/3rdParty/gtest/trunk/Release/lib/gtest_main.a
>         CMakeFiles/UT.dir/UnitTests/common/UT_RRThread.cc.o: In
>         function
>         `thread_proc(void*)':
>         UT_RRThread.cc:(.text+0x28): undefined reference to
>         `exitThread()'
>         
>         
>         /// -> My question and my problem is:
>         Since I'm including the USER_DIR with INCLUDE_DIRECTORIES why
>         is it
>         complaining about not finding reference that is in that header
>         file?
>         
>         
>         Best Regards,
>         
>         --
>         Kevyn-Alexandre Paré
>         
>         _______________________________________________
>         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
> 
> 
> 
> -- 
> Philip Lowman
> 




More information about the CMake mailing list