@@ -61,3 +61,79 @@ endif()
61
61
62
62
get_directory_property (parent_dir PARENT_DIRECTORY )
63
63
configure_file ("${parent_dir} /tools/cmake/CTestCustom.cmake" "${CMAKE_BINARY_DIR} " )
64
+
65
+
66
+ # The amalgamate_demo and amalgamate_demo_cpp do not catch errors from our
67
+ # quick start instructions.
68
+
69
+ if (BASH_EXECUTABLE )
70
+ set (AMALGAMATION_DIR "${CMAKE_BINARY_DIR} /tests/amalgamation" )
71
+ file (MAKE_DIRECTORY "${AMALGAMATION_DIR} " )
72
+
73
+ add_custom_command (
74
+ OUTPUT "${AMALGAMATION_DIR} /roaring.c" "${AMALGAMATION_DIR} /roaring.h" "${AMALGAMATION_DIR} /roaring.hh"
75
+ COMMAND "${BASH_EXECUTABLE} " "${CMAKE_SOURCE_DIR} /amalgamation.sh" "${AMALGAMATION_DIR} "
76
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR} "
77
+ COMMENT "Running amalgamation.sh to generate amalgamated files"
78
+ VERBATIM
79
+ )
80
+
81
+ add_custom_target (amalgamation ALL
82
+ DEPENDS "${AMALGAMATION_DIR} /roaring.c" "${AMALGAMATION_DIR} /roaring.h" "${AMALGAMATION_DIR} /roaring.hh"
83
+ )
84
+
85
+ set (AMALG_C "${AMALGAMATION_DIR} /demo_amalg_c.c" )
86
+ file (WRITE "${AMALG_C} " "
87
+ #include <stdio.h>
88
+ #include <stdlib.h>
89
+ #include \" roaring.c\"
90
+ int main() {
91
+ roaring_bitmap_t *r1 = roaring_bitmap_create();
92
+ for (uint32_t i = 100; i < 1000; i++) roaring_bitmap_add(r1, i);
93
+ printf(\" cardinality = %d\\ n\" , (int) roaring_bitmap_get_cardinality(r1));
94
+ roaring_bitmap_free(r1);
95
+
96
+ bitset_t *b = bitset_create();
97
+ for (int k = 0; k < 1000; ++k) {
98
+ bitset_set(b, 3 * k);
99
+ }
100
+ printf(\" %zu \\ n\" , bitset_count(b));
101
+ bitset_free(b);
102
+ return EXIT_SUCCESS;
103
+ }
104
+ " )
105
+
106
+ add_executable (amalg_c_demo "${AMALG_C} " )
107
+ add_dependencies (amalg_c_demo amalgamation )
108
+ target_include_directories (amalg_c_demo PRIVATE "${AMALGAMATION_DIR} " )
109
+
110
+ set (AMALG_CPP "${AMALGAMATION_DIR} /demo_amalg_cpp.cpp" )
111
+ file (WRITE "${AMALG_CPP} " "
112
+ #include <iostream>
113
+ #include \" roaring.hh\" // the amalgamated roaring.hh includes roaring64map.hh
114
+ #include \" roaring.c\"
115
+ int main() {
116
+ roaring::Roaring r1;
117
+ for (uint32_t i = 100; i < 1000; i++) {
118
+ r1.add(i);
119
+ }
120
+ std::cout << \" cardinality = \" << r1.cardinality() << std::endl;
121
+
122
+ roaring::Roaring64Map r2;
123
+ for (uint64_t i = 18000000000000000100ull; i < 18000000000000001000ull; i++) {
124
+ r2.add(i);
125
+ }
126
+ std::cout << \" cardinality = \" << r2.cardinality() << std::endl;
127
+ return 0;
128
+ }
129
+ " )
130
+
131
+ add_executable (amalg_cpp_demo "${AMALG_CPP} " )
132
+ add_dependencies (amalg_cpp_demo amalgamation )
133
+ target_include_directories (amalg_cpp_demo PRIVATE "${AMALGAMATION_DIR} " )
134
+
135
+ add_test (NAME amalg_c_demo_test COMMAND amalg_c_demo )
136
+ add_test (NAME amalg_cpp_demo_test COMMAND amalg_cpp_demo )
137
+ else ()
138
+ message (STATUS "Bash executable not found, skipping amalgamation tests." )
139
+ endif ()
0 commit comments