Just want to say that since I want to test C code i need this in my header file (for more details see http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B% 2B#Linking_C_and_C.2B.2B_code):
#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ extern "C" { #endif void function (); #ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ } #endif On Tue, 2010-12-07 at 12:10 -0500, Kevyn-Alexandre Paré wrote: > Yes it's true I didn't think of this one. It work nicely, here what I > have done: > > wget http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 > tar xjvf gtest-1.5.0.tar.bz2 > cd gtest-1.5.0 > mkdir my-test > vim CMakeLists.txt # Add ADD_SUBDIRECTORY(my-test) > cd my-test > > # SIMPLE HEADER FILE > vim source.h > void function (); > > # SIMPLE SOURCE > vim source.c > #include <stdio.h> > void function () > { > printf("my function to test\n"); > } > > # SIMPLE TEST > vim ut_source.cc > #include <limits.h> > #include <unistd.h> > #include <gtest/gtest.h> > #include "source.h" > static int something() > { > function(); > return 0; > } > TEST(RRThread, CreateThread) > { > EXPECT_EQ(0, something()); > } > > vim CMakeLists.txt > CMAKE_MINIMUM_REQUIRED(VERSION 2.8) > PROJECT(UnitTests) > INCLUDE_DIRECTORIES(~/gtest-1.5.0/my-test) > ADD_EXECUTABLE(UT ut_source.cc source.c) > TARGET_LINK_LIBRARIES(UT pthread ~/gtest-1.5.0/my-build/libgtest.a > ~/gtest-1.5.0/my-build/libgtest_main.a) > > cd .. > mkdir my-build > cd my-build > ccmake .. > > make > > Best Regards, > > Kevyn-Alexandre Paré > > > On Wed, 2010-12-01 at 10:43 -0800, Ben Medina wrote: > > Note that recent versions of gtest come with a CMakeLists.txt, so you > > can just use add_subdirectory on the gtest source tree. > > > > - Ben > > > > On Wed, Dec 1, 2010 at 7:59 AM, Kevyn-Alexandre Paré > > <kap...@rogue-research.com> wrote: > > > 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é > > >> <kap...@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 > > >> > > > > > > > > > _______________________________________________ > > > 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 > _______________________________________________ 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