How to properly setup googleTest on OS X aside from XCode

后端 未结 3 590
别那么骄傲
别那么骄傲 2020-12-05 16:14

How do I setup gTest, so that I can link aganist the library? I will code in vim, so I just want to install the libraries, unlike the XCode setup. Goal is to be able to link

3条回答
  •  失恋的感觉
    2020-12-05 16:30

    I think cmake is an easy way to setup and use gtest on OSX. It works without manually copying files. Unzip gooletest-release-1.8.0, then

    cd googletest-release-1.8.0
    
    # create a build directory
    mkdir build      
    cd build
    
    # build configuration
    cmake .. -DBUILD_GTEST=ON -DBUILD_SHARED_LIBS=ON
    
    # build it 
    make   
    
    # installation
    sudo make install
    

    Afterwards, you can easily incorporate gtest in your project with the cmake commands

    # sets GTEST_INCLUDE_DIRS and GTEST_LIBRARIES
    find_package( GTest REQUIRED )      
    
    # adds the gtest include directory
    include_directories( ${GTEST_INCLUDE_DIRS} )
    
    # links gtest
    target_link_libraries( yourTestApp ${GTEST_LIBRARIES} )
    

提交回复
热议问题