Skip to content

Commit 1719c58

Browse files
committed
In the CMake build, make MockHTTPinC a separats static library and change
flags to use C99 and silence all warnings only for that target. * test/CMakeLists.txt: Include the MockHTTPinC subdirectory and don't fiddle with the CMAKE_C_FLAGS. (TEST_ALL_SOURCES): Remove the MockHTTPinC source files. (test_all): Depend on an link the mockhttpinc library. * test/MockHTTPinC/CMakeLists.txt: New. Build the mockhttpinc library. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1926869 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3b91ca5 commit 1719c58

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

test/CMakeLists.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# under the License.
1818
# ===================================================================
1919

20+
add_subdirectory(MockHTTPinC)
2021

2122
set(TEST_ALL_SOURCES
2223
"test_all.c"
@@ -30,8 +31,6 @@ set(TEST_ALL_SOURCES
3031
"mock_buckets.c"
3132
"mock_sock_buckets.c"
3233
"test_ssl.c"
33-
"MockHTTPinC/MockHTTP.c"
34-
"MockHTTPinC/MockHTTP_server.c"
3534
)
3635

3736
set(TEST_ALL_SUITES
@@ -52,22 +51,16 @@ set(SIMPLE_TEST_TARGETS
5251
"serf_bwtp"
5352
)
5453

55-
if(CC_LIKE_GNUC)
56-
# MockHTTP requires C99 standard, so use it for the test suite.
57-
string(REPLACE "-std=c89" "-std=c99" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
58-
endif()
59-
6054
foreach(TEST_TARGET ${SIMPLE_TEST_TARGETS})
6155
add_executable(${TEST_TARGET} "${TEST_TARGET}.c")
6256
add_dependencies(${TEST_TARGET} serf_static)
6357
target_link_libraries(${TEST_TARGET} serf_static)
6458
endforeach()
6559

6660
add_executable(test_all ${TEST_ALL_SOURCES})
67-
add_dependencies(test_all serf_static)
68-
target_compile_definitions(test_all PRIVATE "-DMOCKHTTP_OPENSSL")
61+
add_dependencies(test_all serf_static mockhttpinc)
6962
target_include_directories(test_all SYSTEM BEFORE PRIVATE ${SERF_DEPENDENCY_INCLUDES})
70-
target_link_libraries(test_all serf_static)
63+
target_link_libraries(test_all serf_static mockhttpinc)
7164

7265
file(GLOB RESPONSE_TEST_CASES "${CMAKE_CURRENT_SOURCE_DIR}/testcases/*.response")
7366
foreach(TEST_CASE ${RESPONSE_TEST_CASES})

test/MockHTTPinC/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ===================================================================
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
# ===================================================================
19+
20+
set(MockHTTPinC_SOURCES
21+
"MockHTTP.c"
22+
"MockHTTP_server.c"
23+
)
24+
25+
# Update compiler options for this library.
26+
if(CC_LIKE_GNUC)
27+
# MockHTTP requires the C99 standard.
28+
string(REPLACE "-std=c89" "-std=c99" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
29+
# Also silence all warnings.
30+
if(NOT SHOW_MockHTTPinC_WARNINGS)
31+
string(REGEX REPLACE " *-W[a-z][a-z-]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
32+
string(APPEND CMAKE_C_FLAGS " -w")
33+
endif()
34+
elseif(MSVC)
35+
# Silence warnings from Microsoft's compiler...
36+
#
37+
# ... of course, somewhere, somehow CMake adds the /W1 warning option
38+
# to the command line and then MSVC complains that we're overriding /W1
39+
# with /w. But it's more fun this way, or at least more #$@^&@%!
40+
# Or maybe that's just MSBuild doing its magic, and it depends on the
41+
# build generator. What would life be without its little mysteries?
42+
if(NOT SHOW_MockHTTPinC_WARNINGS)
43+
string(REGEX REPLACE " */(W|w[de])[0-9]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
44+
string(APPEND CMAKE_C_FLAGS " /w")
45+
endif()
46+
endif()
47+
mark_as_advanced(SHOW_MockHTTPinC_WARNINGS)
48+
49+
add_library(mockhttpinc STATIC ${MockHTTPinC_SOURCES})
50+
target_compile_definitions(mockhttpinc PUBLIC "MOCKHTTP_OPENSSL")
51+
target_include_directories(mockhttpinc SYSTEM BEFORE
52+
PRIVATE ${APR_INCLUDES} ${APRUTIL_INCLUDES})

0 commit comments

Comments
 (0)