Skip to content

Commit 7e98c4d

Browse files
committed
Do not compile the serf_spider test program if APR doesn't support threads.
* build/scons_extras.py (CheckAPRHasThreads): New custom test function. * SConstruct (custom_tests): Add CheckAPRHasThreads. (apr_has_threads): Perform the config test. (TEST_PROGRAMS): Add serf_spider only if APR has threads. * test/CMakeLists.txt (serf_check_apr_has_threads): New test function. (SIMPLE_TEST_TARGETS): Add serf_spider only if APR has threads. * CMakeLists.txt: Add a note to the summary if APR doesn't have threads. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1931481 13f79535-47bb-0310-9956-ffa450edef68
1 parent 477e0f6 commit 7e98c4d

4 files changed

Lines changed: 66 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ if(DOT_CLANGD)
635635
set(_gen_dot_clangd ON)
636636
endif()
637637

638+
if(APR_HAS_THREADS)
639+
set(_apr_version "${APR_VERSION}")
640+
else()
641+
set(_apr_version "${APR_VERSION} [no threads]")
642+
endif()
643+
638644
if("SERF_HAVE_BROTLI" IN_LIST SERF_C_DEFINES)
639645
set(_have_brotli ON)
640646
if(NOT SERF_WINDOWS)
@@ -684,7 +690,7 @@ message(STATUS " GSSAPI .................. : ${_have_gssapi}")
684690
message(STATUS " SSPI .................... : ${_have_sspi}")
685691
message(STATUS " Unbound ................. : ${_have_unbound}")
686692
message(STATUS " Dependencies:")
687-
message(STATUS " APR ..................... : ${APR_VERSION}")
693+
message(STATUS " APR ..................... : ${_apr_version}")
688694
if(APR_VERSION VERSION_LESS 2.0.0)
689695
message(STATUS " APR-Util ................ : ${APRUTIL_VERSION}")
690696
endif()

SConstruct

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import build.scons_extras
4343
import build.exports
4444

4545
build.scons_extras.AddEnvironmentMethods()
46-
custom_tests = {'CheckGnuCC': build.scons_extras.CheckGnuCC}
46+
custom_tests = {'CheckGnuCC': build.scons_extras.CheckGnuCC,
47+
'CheckAPRHasThreads': build.scons_extras.CheckAPRHasThreads}
4748

4849
# SCons 4.7 introduced the function argument list parameter to CheckFunc.
4950
try:
@@ -650,6 +651,7 @@ for line in stream.readlines():
650651
ssl_includes = '\n'.join(ssl_include_list)
651652

652653
conf = Configure(env, custom_tests=custom_tests)
654+
apr_has_threads = conf.CheckAPRHasThreads()
653655
if not conf.CheckFunc('BIO_set_init', ssl_includes, 'C', 'NULL, 0'):
654656
env.Append(CPPDEFINES=['SERF_NO_SSL_BIO_WRAPPERS'])
655657
if not conf.CheckFunc('X509_STORE_get0_param', ssl_includes, 'C', 'NULL'):
@@ -830,11 +832,18 @@ mockhttpinc = mockenv.StaticLibrary('mockhttpinc',
830832

831833
# Check if long-running tests should be enabled
832834
if tenv.get('ENABLE_SLOW_TESTS', None):
833-
tenv.Append(CPPDEFINES=['SERF_TEST_DEFLATE_4GBPLUS_BUCKETS'])
834-
835-
TEST_PROGRAMS = [ 'serf_get', 'serf_response', 'serf_request', 'serf_spider',
836-
'serf_httpd',
837-
'test_all', 'serf_bwtp' ]
835+
tenv.Append(CPPDEFINES=['SERF_TEST_DEFLATE_4GBPLUS_BUCKETS'])
836+
837+
TEST_PROGRAMS = [
838+
'serf_get',
839+
'serf_response',
840+
'serf_request',
841+
'serf_httpd',
842+
'test_all',
843+
'serf_bwtp',
844+
]
845+
if apr_has_threads:
846+
TEST_PROGRAMS.append("serf_spider")
838847

839848
_exe = '.exe' if sys.platform == 'win32' else ''
840849
TEST_EXES = [os.path.join('test', '%s%s' % (prog, _exe)) for prog in TEST_PROGRAMS]

build/scons_extras.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ def CheckGnuCC(context):
4141
return result
4242

4343

44+
def CheckAPRHasThreads(context):
45+
'''Check if APR_HAS_THREADS is defined'''
46+
47+
src = '''
48+
#include <apr.h>
49+
#if !APR_HAS_THREADS
50+
oh noes!
51+
#endif
52+
'''
53+
54+
context.Display('Checking for thread support in APR... ')
55+
result = context.TryCompile(src, '.c')
56+
context.Result(result)
57+
return result
58+
59+
4460
def __env_munge_if(env, method, variables, pattern, **kwargs):
4561
'''Invoke `env`.`method`(**`kwargs`), unless `pattern` matches the
4662
values in `variables` that are also in `env`.

test/CMakeLists.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@
1717
# under the License.
1818
# ===================================================================
1919

20+
include(CheckCSourceCompiles)
21+
22+
# Check if APR has threads, serf_spider doesn't compile otherwise.
23+
function(serf_check_apr_has_threads)
24+
set(CMAKE_REQUIRED_LIBRARIES APR::APR)
25+
set(source
26+
"#include <apr.h>"
27+
"#if !APR_HAS_THREADS"
28+
"#error \"no threads\""
29+
"#endif"
30+
"int main(void) { return 0\; }"
31+
"")
32+
list(JOIN source "\n" source)
33+
check_c_source_compiles("${source}" "APR_HAS_THREADS")
34+
if(APR_HAS_THREADS)
35+
set(APR_HAS_THREADS TRUE PARENT_SCOPE)
36+
else()
37+
set(APR_HAS_THREADS FALSE PARENT_SCOPE)
38+
endif()
39+
unset(CMAKE_REQUIRED_LIBRARIES)
40+
endfunction(serf_check_apr_has_threads)
41+
serf_check_apr_has_threads()
42+
2043
add_subdirectory(MockHTTPinC)
2144

2245
set(TEST_ALL_SOURCES
@@ -46,10 +69,14 @@ set(SIMPLE_TEST_TARGETS
4669
"serf_get"
4770
"serf_response"
4871
"serf_request"
49-
"serf_spider"
5072
"serf_httpd"
5173
"serf_bwtp"
5274
)
75+
if(APR_HAS_THREADS)
76+
list(APPEND SIMPLE_TEST_TARGETS "serf_spider")
77+
else()
78+
message(STATUS "Test program serf_spider will not be built (requires APR_HAS_THREADS)")
79+
endif()
5380

5481
foreach(TEST_TARGET ${SIMPLE_TEST_TARGETS})
5582
add_executable(${TEST_TARGET} "${TEST_TARGET}.c")

0 commit comments

Comments
 (0)