Skip to content

Commit 84bf9a2

Browse files
committed
chore: improve test items
1 parent 1c9e201 commit 84bf9a2

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

test/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,24 @@ target_include_directories(cxx_static_lib PUBLIC include)
2525

2626
add_executable(c_app src/main.c)
2727
target_link_libraries(c_app c_shared_lib c_static_lib)
28+
target_compile_definitions(c_app PRIVATE
29+
-DPROJECT_VERSION="${PROJECT_VERSION}"
30+
-DBUILD_DATE="${BUILD_DATE}"
31+
-DBUILD_COMPILER_ID="${CMAKE_C_COMPILER_ID}"
32+
-DBUILD_COMPILER_VERSION="${CMAKE_C_COMPILER_VERSION}"
33+
)
34+
if(WIN32)
35+
target_sources(c_app PRIVATE resource.rc)
36+
endif()
37+
2838
add_executable(cxx_app src/main.cpp)
2939
target_link_libraries(cxx_app c_shared_lib c_static_lib cxx_shared_lib cxx_static_lib)
30-
40+
target_compile_definitions(cxx_app PRIVATE
41+
-DPROJECT_VERSION="${PROJECT_VERSION}"
42+
-DBUILD_DATE="${BUILD_DATE}"
43+
-DBUILD_COMPILER_ID="${CMAKE_C_COMPILER_ID}"
44+
-DBUILD_COMPILER_VERSION="${CMAKE_C_COMPILER_VERSION}"
45+
)
3146
if(WIN32)
32-
target_sources(c_app PRIVATE resource.rc)
3347
target_sources(cxx_app PRIVATE resource.rc)
3448
endif()

test/src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
#include "shared_lib.h"
44
#include "static_lib.h"
55

6+
#ifndef PROJECT_VERSION
7+
#define PROJECT_VERSION "unknown"
8+
#endif
9+
#ifndef BUILD_DATE
10+
#define BUILD_DATE "unknown"
11+
#endif
12+
#ifndef BUILD_COMPILER_ID
13+
#define BUILD_COMPILER_ID "unknown"
14+
#endif
15+
#ifndef BUILD_COMPILER_VERSION
16+
#define BUILD_COMPILER_VERSION "unknown"
17+
#endif
18+
619
int main(void) {
720
int a = 1, b = 2;
821
printf("%d + %d = %d\n", a, b, add(a, b));
922
printf("%d - %d = %d\n", a, b, sub(a, b));
23+
24+
printf(PROJECT_VERSION " " BUILD_DATE " (" BUILD_COMPILER_ID " " BUILD_COMPILER_VERSION ").\n");
1025
return 0;
1126
}

test/src/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
#include "shared_lib.h"
44
#include "static_lib.h"
55

6+
#ifndef PROJECT_VERSION
7+
#define PROJECT_VERSION "unknown"
8+
#endif
9+
#ifndef BUILD_DATE
10+
#define BUILD_DATE "unknown"
11+
#endif
12+
#ifndef BUILD_COMPILER_ID
13+
#define BUILD_COMPILER_ID "unknown"
14+
#endif
15+
#ifndef BUILD_COMPILER_VERSION
16+
#define BUILD_COMPILER_VERSION "unknown"
17+
#endif
18+
619
int main(void) {
720
int a = 1, b = 2;
821
printf("%d + %d = %d/%d\n", a, b, add(a, b), shared_lib::SharedLib::add(a, b));
922
printf("%d - %d = %d/%d\n", a, b, sub(a, b), static_lib::StaticLib::sub(a, b));
23+
24+
printf(PROJECT_VERSION " " BUILD_DATE " (" BUILD_COMPILER_ID " " BUILD_COMPILER_VERSION ").\n");
1025
return 0;
1126
}

0 commit comments

Comments
 (0)