]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: create `configurehelp.pm` like autotools does
authorViktor Szakats <commit@vsz.me>
Mon, 8 Jul 2024 16:32:34 +0000 (18:32 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 16 Jul 2024 09:41:52 +0000 (11:41 +0200)
Required by tests 1119 and 1167 to run a C preprocessor.

Tested OK: https://github.com/curl/curl/actions/runs/9915343826

Besides Apple, it also supports any gcc and clang builds, and MSVC.
For other platforms, it defaults to `cpp` (like autotools).

Follow-up to efc2c5184d008fe2e5910fd03263e1ab0331d4e6 #14124
Cherry-picked from #14097
Closes #14129

tests/CMakeLists.txt

index 82c6511671972f317269831003b8aa339d2e3746..53e39e01b4a3b36a6f2f4d45f1f801454748488e 100644 (file)
@@ -45,6 +45,45 @@ function(add_runtests targetname test_flags)
   )
 endfunction()
 
+# Create configurehelp.pm, used by tests needing to run the C preprocessor.
+if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+  set(_cpp_cmd "\"${CMAKE_C_COMPILER}\" -E")
+  if(APPLE AND NOT CMAKE_OSX_SYSROOT STREQUAL "")
+    set(_cpp_cmd "${_cpp_cmd} -isysroot ${CMAKE_OSX_SYSROOT}")
+  endif()
+  # Add header directories, like autotools builds do.
+  get_property(_include_dirs TARGET ${LIB_SELECTED} PROPERTY INCLUDE_DIRECTORIES)
+  foreach(_include_dir IN LISTS _include_dirs)
+    set(_cpp_cmd "${_cpp_cmd} -I${_include_dir}")
+  endforeach()
+else()
+  set(_cpp_cmd "cpp")
+endif()
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/configurehelp.pm" "# This is a generated file.  Do not edit.
+
+package configurehelp;
+
+use strict;
+use warnings;
+use Exporter;
+
+use vars qw(
+    @ISA
+    @EXPORT_OK
+    \$Cpreprocessor
+    );
+
+@ISA = qw(Exporter);
+
+@EXPORT_OK = qw(
+    \$Cpreprocessor
+    );
+
+\$Cpreprocessor = '${_cpp_cmd}';
+
+1;
+")
+
 add_runtests(test-quiet     "-a -s")
 add_runtests(test-am        "-a -am")
 add_runtests(test-full      "-a -p -r")