Skip to content

Commit 7b3ac07

Browse files
authored
Stop generating the export header and just check it in (#1435)
* Stop generating the export header and just check it in * format the new header * support windows * format the header again * avoid depending on internal macro * ensure we define the right thing for windows static builds * support older cmake * and for tests
1 parent d845b7b commit 7b3ac07

File tree

7 files changed

+55
-213
lines changed

7 files changed

+55
-213
lines changed

BUILD.bazel

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
licenses(["notice"])
22

3-
load("//:config/generate_export_header.bzl", "generate_export_header")
4-
5-
# Generate header to provide ABI export symbols
6-
generate_export_header(
7-
out = "include/benchmark/export.h",
8-
lib = "benchmark",
9-
static_define = "BENCHMARK_STATIC_DEFINE",
10-
)
11-
123
config_setting(
134
name = "qnx",
145
constraint_values = ["@platforms//os:qnx"],

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ include(AddCXXCompilerFlag)
130130
include(CheckCXXCompilerFlag)
131131
include(CheckLibraryExists)
132132
include(CXXFeatureCheck)
133-
include(GenerateExportHeader)
134133

135134
check_library_exists(rt shm_open "" HAVE_LIB_RT)
136135

LICENSE

-32
Original file line numberDiff line numberDiff line change
@@ -200,35 +200,3 @@
200200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201201
See the License for the specific language governing permissions and
202202
limitations under the License.
203-
204-
205-
Only benchmark/config/generate_export_header.bzl depends on the following licence:
206-
207-
BSD 3-Clause License
208-
209-
Copyright (c) [year], [fullname]
210-
211-
Redistribution and use in source and binary forms, with or without
212-
modification, are permitted provided that the following conditions are met:
213-
214-
1. Redistributions of source code must retain the above copyright notice, this
215-
list of conditions and the following disclaimer.
216-
217-
2. Redistributions in binary form must reproduce the above copyright notice,
218-
this list of conditions and the following disclaimer in the documentation
219-
and/or other materials provided with the distribution.
220-
221-
3. Neither the name of the copyright holder nor the names of its
222-
contributors may be used to endorse or promote products derived from
223-
this software without specific prior written permission.
224-
225-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
226-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
227-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
228-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
229-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
230-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
231-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
232-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
233-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
234-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

config/generate_export_header.bzl

-168
This file was deleted.

include/benchmark/export.h

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef BENCHMARK_EXPORT_H
2+
#define BENCHMARK_EXPORT_H
3+
4+
#if defined(_WIN32)
5+
#define EXPORT_ATTR __declspec(dllexport)
6+
#define IMPORT_ATTR __declspec(dllimport)
7+
#define NO_EXPORT_ATTR
8+
#define DEPRECATED_ATTR __declspec(deprecated)
9+
#else // _WIN32
10+
#define EXPORT_ATTR __attribute__((visibility("default")))
11+
#define IMPORT_ATTR __attribute__((visibility("default")))
12+
#define NO_EXPORT_ATTR __attribute__((visibility("hidden")))
13+
#define DEPRECATE_ATTR __attribute__((__deprecated__))
14+
#endif // _WIN32
15+
16+
#ifdef BENCHMARK_STATIC_DEFINE
17+
#define BENCHMARK_EXPORT
18+
#define BENCHMARK_NO_EXPORT
19+
#else // BENCHMARK_STATIC_DEFINE
20+
#ifndef BENCHMARK_EXPORT
21+
#ifdef benchmark_EXPORTS
22+
/* We are building this library */
23+
#define BENCHMARK_EXPORT EXPORT_ATTR
24+
#else // benchmark_EXPORTS
25+
/* We are using this library */
26+
#define BENCHMARK_EXPORT IMPORT_ATTR
27+
#endif // benchmark_EXPORTS
28+
#endif // !BENCHMARK_EXPORT
29+
30+
#ifndef BENCHMARK_NO_EXPORT
31+
#define BENCHMARK_NO_EXPORT NO_EXPORT_ATTR
32+
#endif // !BENCHMARK_NO_EXPORT
33+
#endif // BENCHMARK_STATIC_DEFINE
34+
35+
#ifndef BENCHMARK_DEPRECATED
36+
#define BENCHMARK_DEPRECATED DEPRECATE_ATTR
37+
#endif // BENCHMARK_DEPRECATED
38+
39+
#ifndef BENCHMARK_DEPRECATED_EXPORT
40+
#define BENCHMARK_DEPRECATED_EXPORT BENCHMARK_EXPORT BENCHMARK_DEPRECATED
41+
#endif // BENCHMARK_DEPRECATED_EXPORT
42+
43+
#ifndef BENCHMARK_DEPRECATED_NO_EXPORT
44+
#define BENCHMARK_DEPRECATED_NO_EXPORT BENCHMARK_NO_EXPORT BENCHMARK_DEPRECATED
45+
#endif // BENCHMARK_DEPRECATED_EXPORT
46+
47+
#endif /* BENCHMARK_EXPORT_H */

src/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ target_include_directories(benchmark PUBLIC
2929
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
3030
)
3131

32-
generate_export_header(benchmark
33-
EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/benchmark/export.h)
34-
3532
# libpfm, if available
3633
if (HAVE_LIBPFM)
3734
target_link_libraries(benchmark PRIVATE pfm)
@@ -58,6 +55,10 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
5855
target_link_libraries(benchmark PRIVATE kstat)
5956
endif()
6057

58+
if (NOT BUILD_SHARED_LIBS)
59+
add_definitions(-DBENCHMARK_STATIC_DEFINE)
60+
endif()
61+
6162
# Benchmark main library
6263
add_library(benchmark_main "benchmark_main.cc")
6364
add_library(benchmark::benchmark_main ALIAS benchmark_main)

test/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
2424
endforeach()
2525
endif()
2626

27+
if (NOT BUILD_SHARED_LIBS)
28+
add_definitions(-DBENCHMARK_STATIC_DEFINE)
29+
endif()
30+
2731
check_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
2832
set(BENCHMARK_O3_FLAG "")
2933
if (BENCHMARK_HAS_O3_FLAG)

0 commit comments

Comments
 (0)