Skip to content

Commit dc8669e

Browse files
committed
[acquire/acquire_net_common.h] musl libc / classic C library solution to fallback/weak definition (static to the rescue) ; [acquire/tests/CMakeLists.txt] Modify symbol impl src prop to get it to build successfully on Windows with MSVC ; [acquire/tests/test.c] Remove old hack
1 parent 302e08c commit dc8669e

File tree

5 files changed

+70
-16
lines changed

5 files changed

+70
-16
lines changed

acquire/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ else ()
315315
else ()
316316
set_source_files_properties(
317317
${src} PROPERTIES
318-
COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION=1;STRCASESTR_IMPL=1;STRERRORLEN_IMPL=1;STRNSTR_IMPL=1"
318+
COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION=1;STRCASESTR_IMPL=1;STRERRORLEN_IMPL=1;STRNSTR_IMPL=1;STRNCASECMP_IMPL=1"
319319
)
320320
endif ()
321321
elseif (src MATCHES "/gen_acquire_url_utils.c$")
@@ -585,7 +585,7 @@ include(GenerateExportHeader)
585585
set(_export_file "${CMAKE_CURRENT_BINARY_DIR}/lib${LIBRARY_NAME}_export.h")
586586

587587
if (1)
588-
# pass
588+
# pass (intentionally never run)
589589
elseif (LIBACQUIRE_HEADER_ONLY)
590590
file(WRITE "${_export_file}"
591591
"#ifndef LIBACQUIRE_EXPORT_H\n"

acquire/acquire_net_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ bool is_downloaded(const char *url_or_path, enum Checksum checksum,
7878
return result == 0;
7979
}
8080

81+
/* fallback */
82+
static const char *get_download_dir(void) { return ".fallback_downloads"; }
83+
8184
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \
8285
defined(LIBACQUIRE_ACQUIRE_NET_COMMON_IMPL) */
8386

acquire/acquire_string_extras.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* */
55

66
#ifndef LIBACQUIRE_ACQUIRE_STRING_EXTRAS_H
7-
#define LIBACQUIRE_ACQUIRE_STRING_EXTRAS_H 1
7+
#define LIBACQUIRE_ACQUIRE_STRING_EXTRAS_H
88

99
#ifdef __cplusplus
1010
extern "C" {
@@ -192,13 +192,25 @@ inline double wtf_vsnprintf(char *buffer, size_t count, const char *format,
192192
#endif /* !defined(HAVE_SNPRINTF) && defined(SNPRINTF_IMPL) && SNPRINTF_IMPL \
193193
*/
194194

195+
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(STRNCASECMP_IMPL)
196+
/* TODO: remove this hack */
197+
#define STRNCASECMP_IMPL 1
198+
#endif /* defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(STRNCASECMP_IMPL) */
199+
195200
#if !defined(HAVE_STRNCASECMP) && defined(STRNCASECMP_IMPL) && STRNCASECMP_IMPL
196201
#define HAVE_STRNCASECMP 1
197202

198203
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
199-
#define strncasecmp _strnicmp
204+
/* this didn't work `#define strncasecmp _strnicmp` */
205+
LIBACQUIRE_EXPORT int strncasecmp(const char *_l, const char *_r, size_t n) {
206+
return _strnicmp(_l, _r, n);
207+
}
208+
209+
/* this didn't work `#define strcasecmp _stricmp` */
210+
LIBACQUIRE_EXPORT int strcasecmp(const char *l, const char *r) {
211+
return _stricmp(l, r);
212+
}
200213

201-
#define strcasecmp _stricmp
202214
#else
203215
/* from MIT licensed musl @ e0ef93c20de1a9e0a6b8f4a4a951a8e61a1a2973 */
204216
int strncasecmp(const char *_l, const char *_r, size_t n) {

acquire/tests/CMakeLists.txt

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
set(EXEC_NAME "test_${PROJECT_NAME}")
2-
31
#########################
42
# Dependencies download #
53
#########################
@@ -119,6 +117,45 @@ endmacro(test_wrapper)
119117

120118
configure_file(config_for_tests.h.in "${PROJECT_BINARY_DIR}/src/config_for_tests.h" @ONLY)
121119

120+
#######################
121+
# Download dir target #
122+
#######################
123+
124+
set(DOWNLOAD_DIR_LIB "test_${PROJECT_NAME}_download_dir")
125+
126+
set(Header_Files
127+
"${CMAKE_BINARY_DIR}/gen/gen_acquire_common_defs.h"
128+
"${CMAKE_BINARY_DIR}/gen/gen_acquire_net_common.h"
129+
)
130+
source_group("${DOWNLOAD_DIR_LIB} Header Files" FILES "${Header_Files}")
131+
132+
set(Source_Files
133+
"${CMAKE_BINARY_DIR}/gen/gen_acquire_net_common.c")
134+
source_group("${DOWNLOAD_DIR_LIB} Source Files" FILES "${Source_Files}")
135+
136+
add_library("${DOWNLOAD_DIR_LIB}" SHARED "${Header_Files}" "${Source_Files}")
137+
138+
target_link_libraries("${DOWNLOAD_DIR_LIB}" PRIVATE "${PROJECT_NAME}")
139+
140+
target_include_directories(
141+
"${DOWNLOAD_DIR_LIB}"
142+
PRIVATE
143+
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/tests>"
144+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
145+
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/gen>"
146+
)
147+
if (WIN32)
148+
target_compile_definitions(
149+
"${DOWNLOAD_DIR_LIB}"
150+
PRIVATE
151+
"_${TARGET_ARCH}_"
152+
)
153+
endif ()
154+
155+
####
156+
157+
set(EXEC_NAME "test_${PROJECT_NAME}")
158+
122159
set(Header_Files
123160
"test_handle.h"
124161
"test_checksum.h"
@@ -133,18 +170,23 @@ set(Header_Files
133170
)
134171
source_group("Header Files" FILES "${Header_Files}")
135172

136-
set(Source_Files "test.c" "${CMAKE_SOURCE_DIR}/acquire/cli/cli.c")
173+
set(Source_Files
174+
"${CMAKE_BINARY_DIR}/gen/gen_acquire_string_extras.c"
175+
"test.c"
176+
"${CMAKE_SOURCE_DIR}/acquire/cli/cli.c")
137177
source_group("Source Files" FILES "${Source_Files}")
138178

139179
if (MSVC)
140180
set_source_files_properties("test_string_extras.c"
141-
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION=1;STRCASESTR_IMPL=1;STRNCASECMP_IMPL=1")
181+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION=0;STRCASESTR_IMPL=0;STRNCASECMP_IMPL=0")
182+
set_source_files_properties("${CMAKE_BINARY_DIR}/gen/gen_acquire_string_extras.c"
183+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION=1;STRCASESTR_IMPL=1;STRNCASECMP_IMPL=0;STRNSTR_IMPL=1;STRERRORLEN_IMPL=1")
142184
else ()
143-
set_source_files_properties("test.c"
144-
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_DOWNLOAD_DIR_IMPL=1")
145185
set_source_files_properties("test_string_extras.c"
146186
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION=1")
147187
endif ()
188+
#set_source_files_properties("test.c"
189+
# PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_DOWNLOAD_DIR_IMPL=1")
148190

149191
add_executable("${EXEC_NAME}" "${Header_Files}" "${Source_Files}")
150192
target_compile_definitions("${EXEC_NAME}" PUBLIC "_${TARGET_ARCH}_")
@@ -156,11 +198,12 @@ target_link_libraries(
156198
PRIVATE
157199
"${PROJECT_NAME}"
158200
"${PROJECT_NAME}_compiler_flags"
201+
"${DOWNLOAD_DIR_LIB}"
159202
)
160203

161204
if (LIBACQUIRE_USE_MY_LIBFETCH)
162205
target_link_libraries(${EXEC_NAME} PRIVATE freebsd_libfetch)
163-
endif ()
206+
endif (LIBACQUIRE_USE_MY_LIBFETCH)
164207

165208
if (LIBACQUIRE_USE_MINIZ)
166209
find_package(kubazip CONFIG REQUIRED)

acquire/tests/test.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
#include "test_string_extras.h"
2828
#include "test_url_utils.h"
2929

30-
#ifdef LIBACQUIRE_DOWNLOAD_DIR_IMPL
31-
const char *get_download_dir(void) { return ".test_downloads"; }
32-
#endif /* LIBACQUIRE_DOWNLOAD_DIR_IMPL */
33-
3430
/* Add definitions that need to be in the test runner's main file. */
3531
GREATEST_MAIN_DEFS();
3632

0 commit comments

Comments
 (0)