Skip to content

Commit

Permalink
Merge pull request #239 from mikkoi/fix-for-cmake-fetchcontent
Browse files Browse the repository at this point in the history
Fix for cmake fetchcontent
  • Loading branch information
brarcher authored Jan 18, 2020
2 parents c008c61 + 674dfdb commit d66c604
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2016 Branden Archer <[email protected]>
# Copyright (C) 2016 Joshua D. Boyd <[email protected]>
# Copyright (C) 2020 Mikko Koivunalho <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -50,6 +51,11 @@ matrix:
compiler: clang
env: SCAN_BUILD=YES

include:
- os: linux
compiler: clang
env: CMAKE_PROJECT_USAGE_TEST=YES

before_script:
- if [ "$(uname)" = "Linux" ]; then sudo apt-get update; sudo apt-get install -y texlive texinfo texi2html doxygen; fi
- if [ "$(uname)" = "Darwin" ]; then brew update; brew cask install mactex; brew install texi2html texinfo doxygen; fi
Expand Down
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
# Boston, MA 02111-1307, USA.
#
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

# Detect if Check is being used in another build as a subproject
# probably with command FetchContent*().
set(THIS_IS_MAIN_PROJECT TRUE)
if(DEFINED PROJECT_NAME)
set(THIS_IS_MAIN_PROJECT FALSE)
endif()

if(POLICY CMP0090)
# export(PACKAGE) does not populate package registry by default. (NEW)
cmake_policy(SET CMP0090 NEW)
endif()
if(POLICY CMP0076)
# target_sources() leaves relative source file paths unmodified. (OLD)
cmake_policy(SET CMP0076 OLD)
Expand Down Expand Up @@ -452,7 +464,7 @@ add_subdirectory(checkmk)

###############################################################################
# Unit tests
if (BUILD_TESTING)
if (BUILD_TESTING AND THIS_IS_MAIN_PROJECT)
add_subdirectory(tests)
add_test(NAME check_check COMMAND check_check)
add_test(NAME check_check_export COMMAND check_check_export)
Expand Down Expand Up @@ -481,7 +493,7 @@ if (BUILD_TESTING)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_set_max_msg_size.sh)
endif(UNIX OR MINGW OR MSYS)
endif (BUILD_TESTING)
endif (BUILD_TESTING AND THIS_IS_MAIN_PROJECT)

###############################################################################
# Export project, prepare a config and config-version files
Expand Down Expand Up @@ -510,8 +522,8 @@ install(EXPORT check-targets
)
install(
FILES
"${CMAKE_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
"${CMAKE_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)

Expand Down
4 changes: 2 additions & 2 deletions lib/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int gettimeofday(struct timeval *tv, void *tz)
#if defined(_MSC_VER)
union
{
__int64 ns100; /*time since 1 Jan 1601 in 100ns units */
__int64 ns100; /* time since 1 Jan 1601 in 100ns units */
FILETIME ft;
} now;

Expand All @@ -41,7 +41,7 @@ int gettimeofday(struct timeval *tv, void *tz)
tv->tv_sec = (long)((now.ns100 - EPOCHFILETIME) / 10000000LL);
return (0);
#else
// Return that there is no implementation of this on the system
/* Return that there is no implementation of this on the system */
errno = ENOSYS;
return -1;
#endif /* _MSC_VER */
Expand Down
9 changes: 6 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ configure_file(check.h.in check.h @ONLY)
# Normally CMake would create the system's native default library type.

add_library(check STATIC ${SOURCES} ${HEADERS})
add_library(Check::check ALIAS check)


# We would like to create an OBJECT library but currently they are
# too unreliable and cumbersome,
# especially with target_link_libraries and install(EXPORT...
# https://stackoverflow.com/questions/38832528/transitive-target-include-directories-on-object-libraries
# So we instead do the work twice.
add_library(checkShared SHARED ${SOURCES} ${HEADERS})
add_library(Check::checkShared ALIAS checkShared)

# Add parts of libcompat as required
target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/fpclassify.c)
Expand Down Expand Up @@ -144,7 +147,7 @@ endif (MSVC)

set(LIBRARY_OUTPUT_NAME "check")
list(APPEND public_headers "${CMAKE_CURRENT_BINARY_DIR}/check.h")
list(APPEND public_headers "${CMAKE_BINARY_DIR}/check_stdint.h")
list(APPEND public_headers "${CMAKE_CURRENT_BINARY_DIR}/../check_stdint.h")

set_target_properties(check PROPERTIES
OUTPUT_NAME ${LIBRARY_OUTPUT_NAME}
Expand All @@ -168,13 +171,13 @@ set_target_properties(checkShared PROPERTIES
target_include_directories(check
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..>
$<INSTALL_INTERFACE:include>
)
target_include_directories(checkShared
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..>
$<INSTALL_INTERFACE:include>
)

Expand Down
38 changes: 18 additions & 20 deletions src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ Suite *suite_create(const char *name)
int suite_tcase(Suite * s, const char *tcname)
{
List *l;
TCase *tc;

if(s == NULL)
return 0;

l = s->tclst;
for(check_list_front(l); !check_list_at_end(l); check_list_advance(l))
{
tc = (TCase *)check_list_val(l);
TCase *tc = (TCase *)check_list_val(l);
if(strcmp(tcname, tc->name) == 0)
return 1;
}
Expand Down Expand Up @@ -175,15 +174,15 @@ List *tag_string_to_list(const char *tags_string)

if (NULL == tags_string)
{
return list;
return list;
}

tags = strdup(tags_string);
tag = strtok(tags, " ");
while (tag)
{
check_list_add_end(list, strdup(tag));
tag = strtok(NULL, " ");
check_list_add_end(list, strdup(tag));
tag = strtok(NULL, " ");
}
free(tags);
return list;
Expand All @@ -194,8 +193,8 @@ void tcase_set_tags(TCase * tc, const char *tags_orig)
/* replace any pre-existing list */
if (tc->tags)
{
check_list_apply(tc->tags, free);
check_list_free(tc->tags);
check_list_apply(tc->tags, free);
check_list_free(tc->tags);
}
tc->tags = tag_string_to_list(tags_orig);
}
Expand All @@ -222,21 +221,21 @@ unsigned int tcase_matching_tag(TCase *tc, List *check_for)

if (NULL == check_for)
{
return 0;
return 0;
}

for(check_list_front(check_for); !check_list_at_end(check_for);
check_list_advance(check_for))
{
for(check_list_front(tc->tags); !check_list_at_end(tc->tags);
check_list_advance(tc->tags))
{
if (0 == strcmp((const char *)check_list_val(tc->tags),
(const char *)check_list_val(check_for)))
{
return 1;
}
}
for(check_list_front(tc->tags); !check_list_at_end(tc->tags);
check_list_advance(tc->tags))
{
if (0 == strcmp((const char *)check_list_val(tc->tags),
(const char *)check_list_val(check_for)))
{
return 1;
}
}
}
return 0;
}
Expand Down Expand Up @@ -355,7 +354,7 @@ void tcase_fn_start(const char *fname, const char *file,

const char* tcase_name(void)
{
return current_test_name;
return current_test_name;
}

void _mark_point(const char *file, int line)
Expand Down Expand Up @@ -442,7 +441,6 @@ void srunner_add_suite(SRunner * sr, Suite * s)
void srunner_free(SRunner * sr)
{
List *l;
TestResult *tr;

if(sr == NULL)
return;
Expand All @@ -458,7 +456,7 @@ void srunner_free(SRunner * sr)
l = sr->resultlst;
for(check_list_front(l); !check_list_at_end(l); check_list_advance(l))
{
tr = (TestResult *)check_list_val(l);
TestResult *tr = (TestResult *)check_list_val(l);
tr_free(tr);
}
check_list_free(sr->resultlst);
Expand Down
21 changes: 10 additions & 11 deletions src/check_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ void log_test_end(SRunner * sr, TestResult * tr)
static void srunner_send_evt(SRunner * sr, void *obj, enum cl_event evt)
{
List *l;
Log *lg;

l = sr->loglst;
for(check_list_front(l); !check_list_at_end(l); check_list_advance(l))
{
lg = (Log *)check_list_val(l);
Log *lg = (Log *)check_list_val(l);
fflush(lg->lfile);
lg->lfun(sr, lg->lfile, lg->mode, obj, evt);
fflush(lg->lfile);
Expand Down Expand Up @@ -290,11 +289,11 @@ void xml_lfun(SRunner * sr CK_ATTRIBUTE_UNUSED, FILE * file,
{
case CLINITLOG_SR:
fprintf(file,
"<?xml version=\"1.0\"?>\n"
"<?xml-stylesheet type=\"text/xsl\" "
"href=\"http://check.sourceforge.net/xml/check_unittest.xslt\"?>\n"
"<testsuites xmlns=\"http://check.sourceforge.net/ns\">\n"
" <datetime>%s</datetime>\n", t);
"<?xml version=\"1.0\"?>\n"
"<?xml-stylesheet type=\"text/xsl\" "
"href=\"http://check.sourceforge.net/xml/check_unittest.xslt\"?>\n"
"<testsuites xmlns=\"http://check.sourceforge.net/ns\">\n"
" <datetime>%s</datetime>\n", t);
break;
case CLENDLOG_SR:
{
Expand All @@ -305,8 +304,8 @@ void xml_lfun(SRunner * sr CK_ATTRIBUTE_UNUSED, FILE * file,
clock_gettime(check_get_clockid(), &ts_end);
duration = (unsigned long)DIFF_IN_USEC(ts_start, ts_end);
fprintf(file,
" <duration>%lu.%06lu</duration>\n"
"</testsuites>\n",
" <duration>%lu.%06lu</duration>\n"
"</testsuites>\n",
duration / US_PER_SEC, duration % US_PER_SEC);
}
break;
Expand All @@ -315,8 +314,8 @@ void xml_lfun(SRunner * sr CK_ATTRIBUTE_UNUSED, FILE * file,
case CLSTART_S:
s = (Suite *)obj;
fprintf(file,
" <suite>\n"
" <title>");
" <suite>\n"
" <title>");
fprint_xml_esc(file, s->name);
fprintf(file, "</title>\n");
break;
Expand Down
4 changes: 2 additions & 2 deletions src/check_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static void rcvmsg_update_loc(RcvMsg * rmsg, const char *file, int line)

RcvMsg *punpack(FILE * fdes)
{
int nread, nparse, n;
int nread, nparse;
char *buf;
RcvMsg *rmsg;

Expand All @@ -483,7 +483,7 @@ RcvMsg *punpack(FILE * fdes)
while(nparse > 0)
{
/* Parse one message */
n = get_result(buf, rmsg);
int n = get_result(buf, rmsg);
nparse -= n;
if (nparse < 0)
eprintf("Error in call to get_result", __FILE__, __LINE__ - 3);
Expand Down
Loading

0 comments on commit d66c604

Please sign in to comment.