-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 第四章:交叉编译 | ||
|
||
## 编译宏 | ||
- 在cmake时通过-DVIP=ABCDEDF传入对应的值 | ||
``` | ||
target_compile_definitions(main | ||
INTERFACE | ||
VIP="${VIP}" | ||
) | ||
``` | ||
## 编译参数 | ||
``` | ||
target_compile_features() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(main) | ||
set(CMAKE_CXX_STANDARD 17) | ||
include(CTest) | ||
enable_testing() | ||
add_subdirectory(src) | ||
|
||
if(BUILD_TESTING) | ||
add_subdirectory(test) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 单元测试 | ||
``` | ||
include(CTest) | ||
enable_testing() | ||
add_test() | ||
``` | ||
## 编译运行 | ||
``` | ||
ctest --test-dir build | ||
# 或者只测试cs开头的数据 | ||
ctest --test-dir build -R "^cs." | ||
``` | ||
## 宏macro | ||
- ${ARGN}是所有传入的可变参数 | ||
```cmake | ||
macro(my_add_test TEST_NAME) | ||
add_executable(${TEST_NAME} ${ARGN}) | ||
add_test(NAME cs.${TEST_NAME} COMMAND ${TEST_NAME}) | ||
target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main) | ||
endmacro() | ||
``` | ||
|
||
## 函数function | ||
```cmake | ||
function(add_thirdparty) | ||
cmake_parse_arguments(DORIS_THIRDPARTY | ||
"NOTADD;LIB64" | ||
"LIBNAME;WHOLELIBPATH" | ||
"" | ||
${ARGN}) | ||
set(DORIS_THIRDPARTY_NAME ${DORIS_THIRDPARTY_UNPARSED_ARGUMENTS}) | ||
add_library(${DORIS_THIRDPARTY_NAME} STATIC IMPORTED) | ||
endfunction() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_executable(main main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <iostream> | ||
|
||
int main() { | ||
|
||
std::cout<<"hello world!"<<std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# google test | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG v1.14.0 | ||
) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
macro(my_add_test TEST_NAME) | ||
add_executable(${TEST_NAME} ${ARGN}) | ||
add_test(NAME cs.${TEST_NAME} COMMAND ${TEST_NAME}) | ||
target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main) | ||
endmacro() | ||
|
||
my_add_test(test01 gtest_test.cpp) | ||
add_executable(test02 gtest_test2.cpp) | ||
target_link_libraries(test02 PRIVATE gtest gtest_main) | ||
add_test(NAME ee.test02 COMMAND test02) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "gtest/gtest.h" | ||
|
||
|
||
int add(int a, int b) { | ||
return a + b; | ||
} | ||
|
||
TEST(AddFunctionTest, PositiveNumbers) { | ||
EXPECT_EQ(add(2, 3), 5); | ||
EXPECT_EQ(add(0, 0), 0); | ||
EXPECT_EQ(add(-1, 1), 0); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "gtest/gtest.h" | ||
|
||
|
||
int add(int a, int b) { | ||
return a + b; | ||
} | ||
|
||
TEST(AddFunctionTest, PositiveNumbers) { | ||
EXPECT_EQ(add(2, 3), 5); | ||
EXPECT_EQ(add(0, 0), 0); | ||
EXPECT_EQ(add(-1, 1), 0); | ||
} | ||
|
||
|