build: use configurehelp.pm.in with autotools and cmake

Before this patch, each build tool generated `tests/configurehelp.pm`
manually.

Ref: https://github.com/curl/curl/pull/14802#issuecomment-2332734326
Closes #14819
This commit is contained in:
Viktor Szakats 2024-09-07 01:49:40 +02:00
parent 7100c5bc9b
commit 867c187fdf
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
5 changed files with 62 additions and 60 deletions

View file

@ -55,42 +55,24 @@ 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")
set(CURL_CPP "\"${CMAKE_C_COMPILER}\" -E")
if(APPLE AND CMAKE_OSX_SYSROOT)
set(_cpp_cmd "${_cpp_cmd} -isysroot ${CMAKE_OSX_SYSROOT}")
set(CURL_CPP "${CURL_CPP} -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}")
set(CURL_CPP "${CURL_CPP} -I${_include_dir}")
endforeach()
else()
set(_cpp_cmd "cpp")
set(CURL_CPP "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;
")
# Generate version script for the linker, for versioned symbols.
# Consumed variable:
# CURL_CPP
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/configurehelp.pm.in"
"${CMAKE_CURRENT_BINARY_DIR}/configurehelp.pm" @ONLY)
add_runtests(test-quiet "-a -s")
add_runtests(test-am "-a -am")

View file

@ -95,8 +95,6 @@ EXTRA_DIST = \
$(TESTSCRIPTS) \
$(CURLPAGES)
DISTCLEANFILES = configurehelp.pm
# we have two variables here to make sure DIST_SUBDIRS won't get 'unit'
# added twice as then targets such as 'distclean' misbehave and try to
# do things twice in that subdir at times (and thus fails).

45
tests/configurehelp.pm.in Normal file
View file

@ -0,0 +1,45 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
package configurehelp;
use strict;
use warnings;
use Exporter;
use vars qw(
@ISA
@EXPORT_OK
$Cpreprocessor
);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
$Cpreprocessor
);
$Cpreprocessor = '@CURL_CPP@';
1;