Skip to content

Commit c09db8b

Browse files
committed
cmake: create configurehelp.pm like autotools does
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 efc2c51 #14124 Cherry-picked from #14097 Closes #14129
1 parent d2ef625 commit c09db8b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ function(add_runtests targetname test_flags)
4545
)
4646
endfunction()
4747

48+
# Create configurehelp.pm, used by tests needing to run the C preprocessor.
49+
if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
50+
set(_cpp_cmd "\"${CMAKE_C_COMPILER}\" -E")
51+
if(APPLE AND NOT CMAKE_OSX_SYSROOT STREQUAL "")
52+
set(_cpp_cmd "${_cpp_cmd} -isysroot ${CMAKE_OSX_SYSROOT}")
53+
endif()
54+
# Add header directories, like autotools builds do.
55+
get_property(_include_dirs TARGET ${LIB_SELECTED} PROPERTY INCLUDE_DIRECTORIES)
56+
foreach(_include_dir IN LISTS _include_dirs)
57+
set(_cpp_cmd "${_cpp_cmd} -I${_include_dir}")
58+
endforeach()
59+
else()
60+
set(_cpp_cmd "cpp")
61+
endif()
62+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/configurehelp.pm" "# This is a generated file. Do not edit.
63+
64+
package configurehelp;
65+
66+
use strict;
67+
use warnings;
68+
use Exporter;
69+
70+
use vars qw(
71+
@ISA
72+
@EXPORT_OK
73+
\$Cpreprocessor
74+
);
75+
76+
@ISA = qw(Exporter);
77+
78+
@EXPORT_OK = qw(
79+
\$Cpreprocessor
80+
);
81+
82+
\$Cpreprocessor = '${_cpp_cmd}';
83+
84+
1;
85+
")
86+
4887
add_runtests(test-quiet "-a -s")
4988
add_runtests(test-am "-a -am")
5089
add_runtests(test-full "-a -p -r")

0 commit comments

Comments
 (0)