Skip to content

Commit

Permalink
Add MSGPACK_USE_STATIC_BOOST cmake option
Browse files Browse the repository at this point in the history
  • Loading branch information
kovdan01 committed Aug 30, 2021
1 parent 0b8d6a6 commit 4ed6b45
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 41 deletions.
26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ OPTION (MSGPACK_CXX14 "Using c++14 compiler" OFF)
OPTION (MSGPACK_CXX17 "Using c++17 compiler" OFF)
OPTION (MSGPACK_CXX20 "Using c++20 compiler" OFF)

OPTION (MSGPACK_32BIT "32bit compile" OFF)
OPTION (MSGPACK_USE_X3_PARSE "Use Boost X3 parse" OFF)
OPTION (MSGPACK_BUILD_TESTS "Build tests" OFF)
OPTION (MSGPACK_FUZZ_REGRESSION "Enable regression testing" OFF)
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples" OFF)
OPTION (MSGPACK_GEN_COVERAGE "Generate coverage report" OFF)
OPTION (MSGPACK_32BIT "32bit compile" OFF)
OPTION (MSGPACK_USE_X3_PARSE "Use Boost X3 parse" OFF)
OPTION (MSGPACK_BUILD_TESTS "Build tests" OFF)
OPTION (MSGPACK_FUZZ_REGRESSION "Enable regression testing" OFF)
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples" OFF)
OPTION (MSGPACK_GEN_COVERAGE "Generate coverage report" OFF)
OPTION (MSGPACK_USE_STATIC_BOOST "Statically link with boost libraries" OFF)
OPTION (MSGPACK_CHAR_SIGN "Char sign to use (signed or unsigned)")

SET (CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down Expand Up @@ -59,8 +61,15 @@ IF (MSGPACK_32BIT)
ENDIF ()
ENDIF ()

SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
SET (Boost_USE_MULTITHREADED ON)

IF (MSGPACK_USE_STATIC_BOOST)
MESSAGE (STATUS "Staticly linking with Boost")
SET (Boost_USE_STATIC_LIBS TRUE)
ELSE ()
MESSAGE (STATUS "Dynamically linking with Boost")
SET (Boost_USE_STATIC_LIBS FALSE)
ENDIF ()

IF (MSGPACK_CHAR_SIGN)
SET (CMAKE_CXX_FLAGS "-f${MSGPACK_CHAR_SIGN}-char ${CMAKE_CXX_FLAGS}")
Expand All @@ -69,6 +78,7 @@ ENDIF ()
IF (MSGPACK_DEFAULT_API_VERSION)
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=${MSGPACK_DEFAULT_API_VERSION} ${CMAKE_CXX_FLAGS}")
ELSE ()
SET (MSGPACK_DEFAULT_API_VERSION 3)
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=3 ${CMAKE_CXX_FLAGS}")
ENDIF ()

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Other useful options:
- `MSGPACK_32BIT` (default `OFF`): 32bit compile
- `MSGPACK_USE_X3_PARSE` (default `OFF`): use Boost X3 parse
(note that it requires C++14 or newer)
- `MSGPACK_CHAR_SIGN` (not set explicitly by default): char sign to use (signed or unsigned)
- `MSGPACK_USE_STATIC_BOOST` (default `OFF`): statically link with boost libraries

#### GUI on Windows

Expand Down
62 changes: 31 additions & 31 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@ FIND_PROGRAM(LCOV_PATH lcov)
FIND_PROGRAM(GENHTML_PATH genhtml)

IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF()

IF(NOT CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_GNUCXX)
# Clang version 3.0.0 and greater now supports gcov as well.
MESSAGE(STATUS "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF()
# Clang version 3.0.0 and greater now supports gcov as well.
MESSAGE(STATUS "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF()
ENDIF()

SET(COVERAGE_FLAGS "-g -O0 --coverage")

FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)

IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF()
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF()

IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF()
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF()

# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Setup target
ADD_CUSTOM_TARGET(${_targetname}

# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters

# Run tests
COMMAND ${_testrunner} ${ARGV3}
# Run tests
COMMAND ${_testrunner} ${ARGV3}

# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info --base-directory ${CMAKE_SOURCE_DIR} --no-external --quiet
COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/test/*' '*/fuzz/*' --output-file ${_outputname}.info.cleaned --quiet
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned --prefix ${CMAKE_SOURCE_DIR}
# COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info --base-directory ${CMAKE_SOURCE_DIR} --no-external --quiet
COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/test/*' '*/fuzz/*' --output-file ${_outputname}.info.cleaned --quiet
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned --prefix ${CMAKE_SOURCE_DIR}
# COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned

WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)

# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)

ENDFUNCTION()
3 changes: 1 addition & 2 deletions example/x3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
FIND_PACKAGE (Boost REQUIRED COMPONENTS context system unit_test_framework)
FIND_PACKAGE (Boost REQUIRED COMPONENTS context system)
FIND_PACKAGE (Threads REQUIRED)

LIST (APPEND exec_PROGRAMS
Expand Down Expand Up @@ -43,7 +43,6 @@ IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
msgpackc-cxx
Boost::context
Boost::system
Boost::unit_test_framework
Threads::Threads
)
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down
6 changes: 6 additions & 0 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ FOREACH (source_file ${check_PROGRAMS})
${source_file_we}
${source_file}
)

TARGET_COMPILE_DEFINITIONS (${source_file_we} PRIVATE
$<IF:$<BOOL:${MSGPACK_USE_STATIC_BOOST}>,,BOOST_TEST_DYN_LINK>)

TARGET_LINK_LIBRARIES (${source_file_we}
msgpackc-cxx
Threads::Threads
Boost::filesystem
Boost::system
Boost::unit_test_framework
)

ADD_TEST (${source_file_we} ${source_file_we})

IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Wno-mismatched-tags -g")
IF ("${MSGPACK_SAN}" STREQUAL "ASAN")
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ FOREACH (source_file ${check_PROGRAMS})
${source_file}
)

TARGET_COMPILE_DEFINITIONS (${source_file_we} PRIVATE
$<IF:$<BOOL:${MSGPACK_USE_STATIC_BOOST}>,,BOOST_TEST_DYN_LINK>)

TARGET_LINK_LIBRARIES (${source_file_we}
msgpackc-cxx
Boost::system
Boost::unit_test_framework
Threads::Threads
ZLIB::ZLIB
)

ADD_TEST (NAME ${source_file_we} COMMAND ${source_file_we})

IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down

0 comments on commit 4ed6b45

Please sign in to comment.