cmake 添加测试模板

master
zcy 2022-03-23 22:00:32 +08:00
parent b452eae0c7
commit aa743a87b4
4 changed files with 57 additions and 6 deletions

View File

@ -11,3 +11,4 @@ link_libraries(ws2_32)
link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../third/lib/libevent.a) link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../third/lib/libevent.a)
link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../third/lib/libevent_core.a) link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../third/lib/libevent_core.a)
add_executable(tcptest src/tcpclient_test.cpp src/patterntest/pattern_test.cpp) add_executable(tcptest src/tcpclient_test.cpp src/patterntest/pattern_test.cpp)

31
test/CmakeTemplate.txt Normal file
View File

@ -0,0 +1,31 @@
string(REGEX REPLACE "(.*)/(.*)/(.*)" "\\1" PARENTPATH ${CMAKE_CURRENT_LIST_FILE})
message("parent path is " ${PARENTPATH})
include_directories(${PARENTPATH}/obj/inc)
include_directories(${PARENTPATH}/obj/inc/third/include)
message("incldue " ${PARENTPATH}/obj/inc/third/include)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
link_directories(${PARENTPATH}/cmake-build-debug/libgenerallib.a)
link_libraries(libGeneral.a)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# using Intel C++
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
link_libraries(ws2_32)
link_libraries(${PARENTPATH}/general/third/lib/libevent.a)
link_libraries(${PARENTPATH}/general/third/lib/libevent_core.a)
endif()

View File

@ -6,14 +6,20 @@ message("project dir " ${PROJECT_SOURCE_DIR})
set(CMAKE_BUILD_TYPE DEBUG) set(CMAKE_BUILD_TYPE DEBUG)
set(CMAKE_CXX_FLAGS "/OPT:NOREF /MTd /std:c++14 /EHsc /MTd") set(CMAKE_CXX_FLAGS "/OPT:NOREF /std:c++14 /EHsc /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "") set(CMAKE_CXX_FLAGS_RELEASE "")
string(REGEX REPLACE "(.*)/(.*)/(.*)" "\\1" PARENTPATH ${PROJECT_SOURCE_DIR})
message("last=" ${PARENTPATH})
include_directories(E:\\conan_data\\gtest\\1.0\\_\\_\\package\\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\\include) include(${PARENTPATH}/CmakeTemplate.txt)
link_directories(E:\\conan_data\\gtest\\1.0\\_\\_\\package\\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\\lib) include_directories(./third/gtest/include)
link_directories(./third/gtest/lib)
link_libraries(gtestd.lib gtest_maind.lib gmockd.lib gmock_maind.lib) link_libraries(gtestd.lib gtest_maind.lib gmockd.lib gmock_maind.lib)
# include(${CMAKE_CURRENT_SOURCE_DIR}/../CmakeTemplate.txt)
add_executable(gtest_demo gtest_demo.cpp) add_executable(gtest_demo gtest_demo.cpp)
set_property(TARGET gtest_demo PROPERTY set_property(TARGET gtest_demo PROPERTY

View File

@ -1,13 +1,26 @@
/*
* @Author: your name
* @Date: 2022-03-23 20:41:42
* @LastEditTime: 2022-03-23 21:00:44
* @LastEditors: your name
* @Description: koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \gtest_demo\gtest_demo.cpp
*/
#include<gtest/gtest.h> #include<gtest/gtest.h>
#include "function/cpu_usage.h"
int add(int a,int b){ int add(int a,int b){
return a+b; return a+b;
} }
TEST(testCase,test0){ TEST(testCase,test0){
EXPECT_EQ(add(2,3),5); EXPECT_EQ(add(2,3),5);
} }
int main(int argc,char **argv){ int main(int argc,char **argv){
testing::InitGoogleTest(&argc,argv); testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }