mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
testUtilDataPath: use CMAKE_CURRENT_SOURCE_DIR env to work out-of-tree (#234)
This commit is contained in:
parent
7379acd4a4
commit
4d9aa96453
@ -1288,18 +1288,32 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
|
|||||||
int filename_len = filename ? (int) strlen(filename) : 0;
|
int filename_len = filename ? (int) strlen(filename) : 0;
|
||||||
char *s, *s2;
|
char *s, *s2;
|
||||||
int len;
|
int len;
|
||||||
|
char *cmake_src_dir;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int i;
|
int i;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (getcwd(buffer, buffer_size) == NULL) {
|
if ((cmake_src_dir = getenv("CMAKE_CURRENT_SOURCE_DIR")) != NULL) {
|
||||||
fprintf(stderr, "testUtilDataPath: getcwd NULL buffer_size %d\n", buffer_size);
|
len = (int) strlen(cmake_src_dir);
|
||||||
return 0;
|
if (len <= 0 || len >= buffer_size) {
|
||||||
|
fprintf(stderr, "testUtilDataPath: warning CMAKE_CURRENT_SOURCE_DIR len %d, ignoring\n", len);
|
||||||
|
cmake_src_dir = NULL;
|
||||||
|
} else {
|
||||||
|
strcpy(buffer, cmake_src_dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
len = (int) strlen(buffer);
|
|
||||||
if (len <= 0) {
|
if (cmake_src_dir == NULL) {
|
||||||
fprintf(stderr, "testUtilDataPath: strlen <= 0\n");
|
if (getcwd(buffer, buffer_size) == NULL) {
|
||||||
return 0;
|
fprintf(stderr, "testUtilDataPath: getcwd NULL buffer_size %d\n", buffer_size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
len = (int) strlen(buffer);
|
||||||
|
|
||||||
|
if (len <= 0) {
|
||||||
|
fprintf(stderr, "testUtilDataPath: strlen <= 0\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
@ -1336,7 +1350,7 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
|
|||||||
*s = '\0';
|
*s = '\0';
|
||||||
len = s - buffer;
|
len = s - buffer;
|
||||||
}
|
}
|
||||||
if ((s = strrchr(buffer, '/')) != NULL) { // Remove "build" dir
|
if (cmake_src_dir == NULL && (s = strrchr(buffer, '/')) != NULL) { // Remove "build" dir
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
len = s - buffer;
|
len = s - buffer;
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@ macro(zint_add_test test_name test_command)
|
|||||||
add_executable(${test_command} ${test_command}.c)
|
add_executable(${test_command} ${test_command}.c)
|
||||||
target_link_libraries(${test_command} testcommon ${ADDITIONAL_LIBS})
|
target_link_libraries(${test_command} testcommon ${ADDITIONAL_LIBS})
|
||||||
add_test(${test_name} ${test_command})
|
add_test(${test_name} ${test_command})
|
||||||
|
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
if(ZINT_STATIC)
|
if(ZINT_STATIC)
|
||||||
add_executable(${test_command}-static ${test_command}.c)
|
add_executable(${test_command}-static ${test_command}.c)
|
||||||
target_link_libraries(${test_command}-static testcommon-static ${ADDITIONAL_LIBS})
|
target_link_libraries(${test_command}-static testcommon-static ${ADDITIONAL_LIBS})
|
||||||
add_test(${test_name}-static ${test_command}-static)
|
add_test(${test_name}-static ${test_command}-static)
|
||||||
|
set_tests_properties(${test_name}-static PROPERTIES ENVIRONMENT "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
Loading…
Reference in New Issue
Block a user