Skip to content

Commit 1cba0ae

Browse files
committed
Simplify CMake config and do minor adjustments
for consistency with used coding conventions.
1 parent a9d2e82 commit 1cba0ae

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

CMakeLists.txt

+10-14
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ if (BIICODE)
9494
return()
9595
endif ()
9696

97+
add_library(cppformat ${FMT_SOURCES})
9798
if (BUILD_SHARED_LIBS)
98-
add_library(cppformat SHARED ${FMT_SOURCES})
99-
if (UNIX AND NOT APPLE)
100-
# Fix rpmlint warning:
101-
# unused-direct-shlib-dependency /usr/lib/libformat.so.1.1.0 /lib/libm.so.6.
102-
target_link_libraries(cppformat -Wl,--as-needed)
103-
endif ()
104-
else ()
105-
add_library(cppformat ${FMT_SOURCES})
106-
endif()
99+
if (UNIX AND NOT APPLE)
100+
# Fix rpmlint warning:
101+
# unused-direct-shlib-dependency /usr/lib/libformat.so.1.1.0 /lib/libm.so.6.
102+
target_link_libraries(cppformat -Wl,--as-needed)
103+
endif ()
104+
set(FMT_EXTRA_COMPILE_FLAGS -DFMT_EXPORT)
105+
endif ()
107106

108107
if (FMT_PEDANTIC AND
109108
(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
110-
set(FMT_EXTRA_COMPILE_FLAGS "-Wall -Wextra -Wshadow -pedantic")
109+
set(FMT_EXTRA_COMPILE_FLAGS
110+
"${FMT_EXTRA_COMPILE_FLAGS} -Wall -Wextra -Wshadow -pedantic")
111111
endif ()
112112

113113
# If FMT_PEDANTIC is TRUE, then test compilation with both -std=c++11
@@ -119,10 +119,6 @@ if (CPP11_FLAG AND FMT_PEDANTIC)
119119
set(FMT_TEST_DEFAULT_FLAGS TRUE)
120120
endif ()
121121

122-
if (BUILD_SHARED_LIBS)
123-
set(FMT_EXTRA_COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS} -DFMT_EXPORT")
124-
endif ()
125-
126122
set_target_properties(cppformat
127123
PROPERTIES COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS}")
128124

format.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ typedef long long intmax_t;
6464
# include <iterator>
6565
#endif
6666

67-
#if !defined(FMT_HEADER_ONLY) && (defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
67+
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
6868
# ifdef FMT_EXPORT
6969
# define FMT_API __declspec(dllexport)
7070
# elif defined(FMT_SHARED)
7171
# define FMT_API __declspec(dllimport)
72-
# else
73-
# define FMT_API
7472
# endif
75-
#else
73+
#endif
74+
#ifndef FMT_API
7675
# define FMT_API
7776
#endif
7877

@@ -903,11 +902,11 @@ class UTF16ToUTF8 {
903902
};
904903

905904
FMT_API void format_windows_error(fmt::Writer &out, int error_code,
906-
fmt::StringRef message) FMT_NOEXCEPT;
905+
fmt::StringRef message) FMT_NOEXCEPT;
907906
#endif
908907

909908
FMT_API void format_system_error(fmt::Writer &out, int error_code,
910-
fmt::StringRef message) FMT_NOEXCEPT;
909+
fmt::StringRef message) FMT_NOEXCEPT;
911910

912911
// A formatting argument value.
913912
struct Value {
@@ -1836,7 +1835,8 @@ class PrintfFormatter : private FormatterBase {
18361835

18371836
public:
18381837
explicit PrintfFormatter(const ArgList &args) : FormatterBase(args) {}
1839-
FMT_API void format(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str);
1838+
FMT_API void format(BasicWriter<Char> &writer,
1839+
BasicCStringRef<Char> format_str);
18401840
};
18411841
} // namespace internal
18421842

@@ -2941,7 +2941,8 @@ void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) {
29412941

29422942
// Reports a system error without throwing an exception.
29432943
// Can be used to report errors from destructors.
2944-
FMT_API void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT;
2944+
FMT_API void report_system_error(int error_code,
2945+
StringRef message) FMT_NOEXCEPT;
29452946

29462947
#if FMT_USE_WINDOWS_H
29472948

@@ -2987,7 +2988,8 @@ class WindowsError : public SystemError {
29872988

29882989
// Reports a Windows error without throwing an exception.
29892990
// Can be used to report errors from destructors.
2990-
FMT_API void report_windows_error(int error_code, StringRef message) FMT_NOEXCEPT;
2991+
FMT_API void report_windows_error(int error_code,
2992+
StringRef message) FMT_NOEXCEPT;
29912993

29922994
#endif
29932995

test/CMakeLists.txt

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ set(FMT_GMOCK_DIR ../gmock)
22

33
include_directories(.. ${FMT_GMOCK_DIR})
44

5-
if (BUILD_SHARED_LIBS)
6-
set(FMT_IMPORT "-DFMT_SHARED")
7-
endif ()
5+
# Links target with cppformat and any libraries passed as extra arguments.
6+
function (target_link_cppformat target)
7+
target_link_libraries(${target} cppformat ${ARGN})
8+
if (BUILD_SHARED_LIBS)
9+
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -DFMT_SHARED)
10+
endif ()
11+
endfunction ()
812

913
# We compile Google Test ourselves instead of using pre-compiled libraries.
1014
# See the Google Test FAQ "Why is it not recommended to install a
@@ -49,8 +53,7 @@ endif ()
4953

5054
set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc)
5155
add_library(test-main STATIC ${TEST_MAIN_SRC})
52-
set_target_properties(test-main PROPERTIES COMPILE_FLAGS "${FMT_IMPORT}")
53-
target_link_libraries(test-main cppformat gmock)
56+
target_link_cppformat(test-main gmock)
5457

5558
# Adds a test.
5659
# Usage: add_fmt_test(name [CUSTOM_LINK] srcs...)
@@ -59,8 +62,7 @@ function(add_fmt_test name)
5962
add_executable(${name} ${name}.cc ${add_fmt_test_UNPARSED_ARGUMENTS})
6063
target_link_libraries(${name} test-main)
6164
if (NOT add_fmt_test_CUSTOM_LINK)
62-
set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${FMT_IMPORT}")
63-
target_link_libraries(${name} cppformat)
65+
target_link_cppformat(${name})
6466
endif ()
6567
add_test(NAME ${name} COMMAND ${name})
6668
endfunction()

0 commit comments

Comments
 (0)