Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
68a0193d
Commit
68a0193d
authored
Jun 10, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CMake refactoring to functions
parent
80740f0e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
54 deletions
+59
-54
CMakeLists.txt
CMakeLists.txt
+3
-15
CMakeLists.txt
bench/CMakeLists.txt
+1
-0
sanitizers.cmake
cmake/sanitizers.cmake
+0
-21
utils.cmake
cmake/utils.cmake
+42
-0
version.cmake
cmake/version.cmake
+0
-17
CMakeLists.txt
example/CMakeLists.txt
+2
-0
CMakeLists.txt
tests/CMakeLists.txt
+11
-1
No files found.
CMakeLists.txt
View file @
68a0193d
...
...
@@ -7,7 +7,8 @@ cmake_minimum_required(VERSION 3.1)
#---------------------------------------------------------------------------------------
# Start spdlog project
#---------------------------------------------------------------------------------------
include
(
cmake/version.cmake
)
include
(
cmake/utils.cmake
)
spdlog_extract_version
()
project
(
spdlog VERSION
${
SPDLOG_VERSION
}
LANGUAGES CXX
)
message
(
STATUS
"Build spdlog:
${
SPDLOG_VERSION
}
"
)
...
...
@@ -49,7 +50,6 @@ option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
message
(
STATUS
"Build type: "
${
CMAKE_BUILD_TYPE
}
)
find_package
(
Threads REQUIRED
)
#---------------------------------------------------------------------------------------
...
...
@@ -63,6 +63,7 @@ target_include_directories(spdlog PUBLIC
"$<BUILD_INTERFACE:
${
CMAKE_CURRENT_LIST_DIR
}
/include>"
"$<INSTALL_INTERFACE:
${
CMAKE_INSTALL_INCLUDEDIR
}
>"
)
target_link_libraries
(
spdlog PUBLIC Threads::Threads
)
spdlog_enable_warnings
(
spdlog
)
#---------------------------------------------------------------------------------------
# Header only version
...
...
@@ -75,19 +76,6 @@ target_include_directories(spdlog_header_only INTERFACE
"$<INSTALL_INTERFACE:
${
CMAKE_INSTALL_INCLUDEDIR
}
>"
)
target_link_libraries
(
spdlog_header_only INTERFACE Threads::Threads
)
#---------------------------------------------------------------------------------------
# Turn on compiler warnings and sanitizers if we build our own project
#---------------------------------------------------------------------------------------
if
(
SPDLOG_MASTER_PROJECT
)
if
(
CMAKE_CXX_COMPILER_ID MATCHES
"GNU|Clang|AppleClang"
)
target_compile_options
(
spdlog PRIVATE -Wall -Wextra -Wconversion -pedantic -Wfatal-errors
)
endif
()
if
(
CMAKE_CXX_COMPILER_ID MATCHES
"MSVC"
)
target_compile_options
(
spdlog PRIVATE /W3 /WX
)
endif
()
include
(
cmake/sanitizers.cmake
)
endif
()
#---------------------------------------------------------------------------------------
# use fmt package if using exertnal fmt
...
...
bench/CMakeLists.txt
View file @
68a0193d
...
...
@@ -13,6 +13,7 @@ find_package(Threads REQUIRED)
find_package
(
benchmark CONFIG REQUIRED
)
add_executable
(
bench bench.cpp
)
spdlog_enable_warnings
(
bench
)
target_link_libraries
(
bench PRIVATE spdlog::spdlog
)
add_executable
(
async_bench async_bench.cpp
)
...
...
cmake/sanitizers.cmake
deleted
100644 → 0
View file @
80740f0e
if
(
SPDLOG_SANITIZE_THREAD AND SPDLOG_SANITIZE_ADDRESS
)
message
(
FATAL_ERROR
"AddressSanitizer is not compatible with ThreadSanitizer."
)
endif
()
if
(
SPDLOG_SANITIZE_ADDRESS
)
message
(
STATUS
"AddressSanitizer enabled"
)
set
(
SANITIZER_FLAGS
"-fsanitize=address,undefined"
)
add_compile_options
(
"-fno-sanitize=signed-integer-overflow"
)
endif
()
if
(
SPDLOG_SANITIZE_THREAD
)
message
(
STATUS
"ThreadSanitizer enabled"
)
set
(
SANITIZER_FLAGS
"-fsanitize=thread"
)
endif
()
if
(
SPDLOG_SANITIZE_THREAD OR SPDLOG_SANITIZE_ADDRESS
)
add_compile_options
(
${
SANITIZER_FLAGS
}
)
add_compile_options
(
"-fno-sanitize-recover=all"
)
add_compile_options
(
"-fno-omit-frame-pointer"
)
set
(
CMAKE_EXE_LINKER_FLAGS
"
${
CMAKE_EXE_LINKER_FLAGS
}
${
SANITIZER_FLAGS
}
-fuse-ld=gold"
)
endif
()
cmake/utils.cmake
0 → 100644
View file @
68a0193d
# Get spdlog version from include/spdlog/version.h and put it in SPDLOG_VERSION
function
(
spdlog_extract_version
)
file
(
READ
"
${
CMAKE_CURRENT_LIST_DIR
}
/include/spdlog/version.h"
file_contents
)
string
(
REGEX MATCH
"SPDLOG_VER_MAJOR ([0-9]+)"
_
"
${
file_contents
}
"
)
set
(
ver_major
${
CMAKE_MATCH_1
}
)
string
(
REGEX MATCH
"SPDLOG_VER_MINOR ([0-9]+)"
_
"
${
file_contents
}
"
)
set
(
ver_minor
${
CMAKE_MATCH_1
}
)
string
(
REGEX MATCH
"SPDLOG_VER_PATCH ([0-9]+)"
_
"
${
file_contents
}
"
)
set
(
ver_patch
${
CMAKE_MATCH_1
}
)
if
(
NOT ver_major OR NOT ver_minor OR NOT ver_patch
)
message
(
FATAL_ERROR
"Could not extract valid version from spdlog/version.h"
)
endif
()
set
(
SPDLOG_VERSION
"
${
ver_major
}
.
${
ver_minor
}
.
${
ver_patch
}
"
PARENT_SCOPE
)
endfunction
()
# Turn on warnings on the given target
function
(
spdlog_enable_warnings target_name
)
if
(
CMAKE_CXX_COMPILER_ID MATCHES
"GNU|Clang|AppleClang"
)
target_compile_options
(
${
target_name
}
PRIVATE -Wall -Wextra -Wconversion -pedantic -Wfatal-errors
)
endif
()
if
(
CMAKE_CXX_COMPILER_ID MATCHES
"MSVC"
)
target_compile_options
(
${
target_name
}
PRIVATE /W4 /WX
)
endif
()
endfunction
()
# Enable address sanitizer (gcc/clang only)
function
(
spdlog_enable_sanitizer target_name
)
if
(
NOT CMAKE_CXX_COMPILER_ID MATCHES
"GNU|Clang"
)
message
(
FATAL_ERROR
"Sanitizer supported only for gcc/clang"
)
endif
()
message
(
STATUS
"Address sanitizer enabled"
)
target_compile_options
(
${
target_name
}
"-fsanitize=address,undefined"
)
target_compile_options
(
${
target_name
}
"-fno-sanitize=signed-integer-overflow"
)
target_compile_options
(
${
target_name
}
"-fno-sanitize-recover=all"
)
target_compile_options
(
${
target_name
}
"-fno-omit-frame-pointer"
)
target_link_libraries
(
${
target_name
}
"-fsanitize=address,undefined -fuse-ld=gold"
)
endfunction
()
\ No newline at end of file
cmake/version.cmake
deleted
100644 → 0
View file @
80740f0e
#---------------------------------------------------------------------------------------
# Get spdlog version from include/spdlog/version.h
#---------------------------------------------------------------------------------------
file
(
READ
"
${
CMAKE_CURRENT_LIST_DIR
}
/../include/spdlog/version.h"
SPDLOG_VERSION_FILE
)
string
(
REGEX MATCH
"SPDLOG_VER_MAJOR ([0-9]+)"
_
"
${
SPDLOG_VERSION_FILE
}
"
)
set
(
ver_major
${
CMAKE_MATCH_1
}
)
string
(
REGEX MATCH
"SPDLOG_VER_MINOR ([0-9]+)"
_
"
${
SPDLOG_VERSION_FILE
}
"
)
set
(
ver_minor
${
CMAKE_MATCH_1
}
)
string
(
REGEX MATCH
"SPDLOG_VER_PATCH ([0-9]+)"
_
"
${
SPDLOG_VERSION_FILE
}
"
)
set
(
ver_patch
${
CMAKE_MATCH_1
}
)
if
(
NOT ver_major OR NOT ver_minor OR NOT ver_patch
)
message
(
FATAL_ERROR
"Could not extract valid version from spdlog/version.h"
)
endif
()
set
(
SPDLOG_VERSION
"
${
ver_major
}
.
${
ver_minor
}
.
${
ver_patch
}
"
)
\ No newline at end of file
example/CMakeLists.txt
View file @
68a0193d
...
...
@@ -13,12 +13,14 @@ endif()
# Example of using pre-compiled library
#---------------------------------------------------------------------------------------
add_executable
(
example example.cpp
)
spdlog_enable_warnings
(
example
)
target_link_libraries
(
example spdlog::spdlog
)
#---------------------------------------------------------------------------------------
# Example of using header-only library
#---------------------------------------------------------------------------------------
add_executable
(
example_header_only example.cpp
)
spdlog_enable_warnings
(
example_header_only
)
target_link_libraries
(
example_header_only spdlog::spdlog_header_only
)
# Create logs directory
...
...
tests/CMakeLists.txt
View file @
68a0193d
...
...
@@ -21,13 +21,22 @@ enable_testing()
# The compiled library tests
if
(
SPDLOG_BUILD_TESTS
)
add_executable
(
spdlog-utests
${
SPDLOG_UTESTS_SOURCES
}
)
spdlog_enable_warnings
(
spdlog-utests
)
target_link_libraries
(
spdlog-utests spdlog
)
add_test
(
NAME spdlog-utests COMMAND spdlog-utests
)
if
(
SPDLOG_SANITIZE_ADDRESS
)
spdlog_enable_sanitizer
(
spdlog-utests
)
endif
()
add_test
(
NAME spdlog-utests COMMAND spdlog-utests
)
endif
()
# The header-only library version tests
if
(
SPDLOG_BUILD_HO_TESTS
)
add_executable
(
spdlog-utests-ho
${
SPDLOG_UTESTS_SOURCES
}
)
spdlog_enable_warnings
(
spdlog-utests-ho
)
target_link_libraries
(
spdlog-utests-ho spdlog::spdlog_header_only
)
if
(
SPDLOG_SANITIZE_ADDRESS
)
spdlog_set_address_sanitizer
(
spdlog-utests-ho
)
endif
()
add_test
(
NAME spdlog-utests-ho COMMAND spdlog-utests-ho
)
endif
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment