]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: sync tests unity builds between cmake and autotools
authorViktor Szakats <commit@vsz.me>
Sun, 15 Jun 2025 19:54:20 +0000 (21:54 +0200)
committerViktor Szakats <commit@vsz.me>
Sun, 15 Jun 2025 23:07:41 +0000 (01:07 +0200)
Instead of relying on CMake's built-in unity feature, use `mk-unity.pl`,
as already done with autotools. It simplified the build, shortens logs
and makes debugging easier because of the fewer build variations.
It also allows testing / fixing with cmake and those automatically apply
to autotools builds too. cmake builds can be much-much faster, esp.
when working the builds themselves.

It also enables "unity" in old cmake versions. Basically every test
target is a single generated .c source.

Also:
- drop a `lib` unity workaround for libtests with autotools after fixing
  the issue in libtests itself. It drops a few exceptions and makes
  libcurl build faster (in autotools unity).
- fix another `lib` autotools unity issue and drop the workaround for it
  from `mk-unity.pl`. `srcdir` was missing from the header path.
- simplify `mk-unity.pl` command-lines, drop exclusions.

Follow-up to 2c27a67daa1b76859c18d63e4e1f528db05b5e13 #17590

Closes #17628

docs/examples/CMakeLists.txt
lib/Makefile.am
scripts/mk-unity.pl
tests/libtest/CMakeLists.txt
tests/libtest/Makefile.am
tests/server/CMakeLists.txt
tests/server/Makefile.am
tests/tunit/CMakeLists.txt
tests/unit/CMakeLists.txt

index e27ed47ac17d92f2e4e2fc5facda5edd28f2d18f..d9fcd7df7fe75632bb51fe620fb91e8d3678cfa6 100644 (file)
@@ -37,6 +37,5 @@ foreach(_target IN LISTS check_PROGRAMS)
   if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
   endif()
-  set_target_properties(${_target_name} PROPERTIES OUTPUT_NAME "${_target}" PROJECT_LABEL "Example ${_target}"
-    UNITY_BUILD OFF)
+  set_target_properties(${_target_name} PROPERTIES OUTPUT_NAME "${_target}" PROJECT_LABEL "Example ${_target}" UNITY_BUILD OFF)
 endforeach()
index 8306607e40d150c42abdf66d67abf1da83c1a2ff..31751921caaef92d1269c773d59d7fda405832f3 100644 (file)
@@ -52,7 +52,8 @@ CFLAGS += @CURL_CFLAG_EXTRAS@
 # $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
 
 AM_CPPFLAGS = -I$(top_srcdir)/include   \
-              -I$(top_builddir)/lib
+              -I$(top_builddir)/lib     \
+              -I$(srcdir)
 
 # Prevent LIBS from being used for all link targets
 LIBS = $(BLANK_AT_MAKETIME)
@@ -75,9 +76,7 @@ CSOURCES += dllmain.c
 endif
 
 if USE_UNITY
-# Keep these separate to avoid duplicate definitions when linking libtests
-# in static mode.
-curl_EXCLUDE = curl_threads.c curlx/timediff.c curlx/warnless.c
+curl_EXCLUDE =
 if CURLDEBUG
 # We must compile this source separately to avoid memdebug.h redefinitions
 # applying to it.
index c1878b12169f6e30e37f86bc1db14caf4ee8d85c..7685595c7cdb8959801830540652d83f08ad8dd3 100755 (executable)
@@ -91,10 +91,10 @@ foreach my $src (@src) {
     if($src =~ /([a-z0-9]+)\.c$/ && !exists $exclude{$src}) {
         my $name = $1;
         my $fn = $src;
-        if($srcdir ne "" && (exists $include{$src} || $embed) && -e "$srcdir/$fn") {
-            $fn = $srcdir . "/" . $fn;
-        }
         if($embed) {
+            if($srcdir ne "" && -e "$srcdir/$fn") {
+                $fn = $srcdir . "/" . $fn;
+            }
             my $content = do { local $/; open my $fh, '<', $fn or die $!; <$fh> };
             print $content;
         }
index eb9188a52119a4efaa1d44ed6795bde1b60b9195..baeeeeef28e47c0686ec56c2745e23e46cd61d21 100644 (file)
 curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 
+set(_bundle_extra "")
+if(LIB_SELECTED STREQUAL LIB_SHARED)
+  list(APPEND _bundle_extra ${CURLX_SRCS})  # Not exported from the libcurl shared build. Build a copy.
+endif()
+
 add_custom_command(
   OUTPUT "lib1521.c"
   COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" < "${PROJECT_SOURCE_DIR}/include/curl/curl.h" "lib1521.c"
@@ -36,18 +41,15 @@ add_custom_command(
 
 add_custom_command(
   OUTPUT "${BUNDLE_SRC}"
-  COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" --test ${TESTFILES} "lib1521.c"
+  COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl"
+    --include ${UTILS} ${MEMPTR} ${_bundle_extra} --test ${TESTFILES} "lib1521.c"
     ${CURL_MK_UNITY_OPTION} --srcdir "${CMAKE_CURRENT_SOURCE_DIR}" > "${BUNDLE_SRC}"
   DEPENDS
-    "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc" ${FIRSTFILES} ${TESTFILES} "lib1521.c"
+    "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
+    ${FIRSTFILES} ${UTILS} ${MEMPTR} ${_bundle_extra} ${TESTFILES} "lib1521.c"
   VERBATIM)
 
-set(_sources "")
-if(LIB_SELECTED STREQUAL LIB_SHARED)
-  list(APPEND _sources ${MEMPTR} ${CURLX_SRCS})  # These are part of the libcurl static lib. Add them here when linking shared.
-endif()
-
-add_executable(libtests EXCLUDE_FROM_ALL ${_sources} ${UTILS} "${BUNDLE_SRC}")
+add_executable(libtests EXCLUDE_FROM_ALL "${BUNDLE_SRC}")
 add_dependencies(testdeps libtests)
 target_link_libraries(libtests ${LIB_SELECTED} ${CURL_LIBS})
 target_include_directories(libtests PRIVATE
@@ -59,4 +61,4 @@ target_include_directories(libtests PRIVATE
   "${PROJECT_SOURCE_DIR}/tests/unit"     # for curlcheck.h
 )
 set_property(TARGET libtests APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}" "CURL_NO_OLDIES" "CURL_DISABLE_DEPRECATION")
-set_target_properties(libtests PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}")
+set_target_properties(libtests PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}" UNITY_BUILD OFF)
index 2d5329c7f4a95fdeec279ae3de2dac662fbbcbc5..a60c5ed39dbf135ae6abbc13c5db77c737fe95d0 100644 (file)
@@ -88,17 +88,18 @@ libstubgss_la_LIBADD =
 libstubgss_la_DEPENDENCIES =
 endif
 
-bundle_EXCLUDE =
+bundle_extra =
 if USE_CPPFLAG_CURL_STATICLIB
+else
 # These are part of the libcurl static lib. Add them here when linking shared.
-bundle_EXCLUDE += $(MEMPTR) $(CURLX_SRCS)
+bundle_extra += $(CURLX_SRCS)
 endif
-$(BUNDLE_SRC): $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRSTFILES) $(UTILS) $(MEMPTR) $(CURLX_SRCS) $(TESTFILES) lib1521.c
-       @PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS) $(MEMPTR) $(CURLX_SRCS) --test $(TESTFILES) lib1521.c --exclude $(bundle_EXCLUDE) > $(BUNDLE_SRC)
+$(BUNDLE_SRC): $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRSTFILES) $(UTILS) $(MEMPTR) $(bundle_extra) $(TESTFILES) lib1521.c
+       @PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS) $(MEMPTR) $(bundle_extra) --test $(TESTFILES) lib1521.c > $(BUNDLE_SRC)
 
 noinst_PROGRAMS = $(BUNDLE)
 nodist_libtests_SOURCES = $(BUNDLE_SRC)
-libtests_SOURCES = $(bundle_EXCLUDE)
+libtests_SOURCES =
 CLEANFILES = $(BUNDLE_SRC) lib1521.c
 
 lib1521.c: $(top_srcdir)/tests/libtest/mk-lib1521.pl $(top_srcdir)/include/curl/curl.h
index 8e86a8c9738007f14ca031f591a6a1135a28e2c6..0f7c5dee12a3bd757384f072fa1d86bec9d225e7 100644 (file)
 curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 
+set(_sources_extra "")
+if(ENABLE_SERVER_DEBUG AND ENABLE_CURLDEBUG)
+  list(APPEND _sources_extra ${MEMDEBUG})
+endif()
+
 add_custom_command(
   OUTPUT "${BUNDLE_SRC}"
-  COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" --test ${TESTFILES}
+  COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl"
+    --include ${UTILS} ${CURLX_SRCS} --test ${TESTFILES}
     ${CURL_MK_UNITY_OPTION} --srcdir "${CMAKE_CURRENT_SOURCE_DIR}" > "${BUNDLE_SRC}"
   DEPENDS
-    "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc" ${FIRSTFILES} ${TESTFILES}
+    "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
+    ${FIRSTFILES} ${UTILS} ${CURLX_SRCS} ${TESTFILES}
   VERBATIM)
 
-if(ENABLE_SERVER_DEBUG AND ENABLE_CURLDEBUG)
-  set_source_files_properties("../../lib/memdebug.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
-endif()
-
-add_executable(servers EXCLUDE_FROM_ALL ${MEMDEBUG} ${CURLX_SRCS} ${UTILS} "${BUNDLE_SRC}")
+add_executable(servers EXCLUDE_FROM_ALL "${BUNDLE_SRC}" ${_sources_extra})
 add_dependencies(testdeps servers)
 target_include_directories(servers PRIVATE
   "${PROJECT_BINARY_DIR}/lib"           # for "curl_config.h"
@@ -61,4 +64,4 @@ set_property(TARGET servers APPEND PROPERTY COMPILE_DEFINITIONS "WITHOUT_LIBCURL
 if(WIN32)
   set_property(TARGET servers APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
 endif()
-set_target_properties(servers PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}")
+set_target_properties(servers PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}" UNITY_BUILD OFF)
index 06f64d5cb472eb64d0e5254fdcf1e4e9cd3f18f7..8b994c7bfb4bfd28a1719d290ead089e74a512f9 100644 (file)
@@ -64,18 +64,17 @@ endif
 
 AM_CPPFLAGS += -DWITHOUT_LIBCURL -DCURL_NO_OLDIES
 
-bundle_EXCLUDE =
+$(BUNDLE_SRC): $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRSTFILES) $(UTILS) $(CURLX_SRCS) $(TESTFILES)
+       @PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS) $(CURLX_SRCS) --test $(TESTFILES) > $(BUNDLE_SRC)
+
+noinst_PROGRAMS = $(BUNDLE)
+nodist_servers_SOURCES = $(BUNDLE_SRC)
+servers_SOURCES =
 if ENABLE_SERVER_DEBUG
 if CURLDEBUG
-bundle_EXCLUDE += $(MEMDEBUG)
+servers_SOURCES += $(MEMDEBUG)
 endif
 endif
-$(BUNDLE_SRC): $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRSTFILES) $(UTILS) $(MEMDEBUG) $(CURLX_SRCS) $(TESTFILES)
-       @PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS) $(MEMDEBUG) $(CURLX_SRCS) --test $(TESTFILES) --exclude $(bundle_EXCLUDE) > $(BUNDLE_SRC)
-
-noinst_PROGRAMS = $(BUNDLE)
-nodist_servers_SOURCES = $(BUNDLE_SRC)
-servers_SOURCES = $(bundle_EXCLUDE)
 servers_LDADD = @CURL_NETWORK_AND_TIME_LIBS@
 servers_CFLAGS = $(AM_CFLAGS)
 CLEANFILES = $(BUNDLE_SRC)
index 4151a490974235eaf3f193df1ac2e519168a09d3..afde8d0a4fbbdb98ef4d2fbade8104099cb1c935 100644 (file)
@@ -47,4 +47,4 @@ target_include_directories(tunits PRIVATE
   "${PROJECT_SOURCE_DIR}/tests/tunit"
 )
 set_property(TARGET tunits APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}" "CURL_NO_OLDIES" "CURL_DISABLE_DEPRECATION")
-set_target_properties(tunits PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}")
+set_target_properties(tunits PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}" UNITY_BUILD OFF)
index 5416aaeedcd9b8b8c4977928db4e0d57512ea971..1c7f86fabe1b1816435b7984f47ef451e161ac99 100644 (file)
@@ -47,4 +47,4 @@ target_include_directories(units PRIVATE
 )
 set_property(TARGET units APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}" "CURL_NO_OLDIES" "CURL_DISABLE_DEPRECATION")
 set_property(TARGET units APPEND PROPERTY COMPILE_DEFINITIONS "BUILDING_LIBCURL")  # unit tests are small pretend-libcurl-programs
-set_target_properties(units PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}")
+set_target_properties(units PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}" UNITY_BUILD OFF)