From 2f543923d23faeb41e53b2624a1d053d3c9424db Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 4 Mar 2023 13:10:41 +0100 Subject: [PATCH] Explicitly specify the project is a C project. CMake assumes the default project uses both C and C++, and therefore will fail if both a C and a C++ compiler isn't found. This essentially blocks pure C projects from using msgpack-c if they also don't have a C++ compiler. Just specifying that the project is "C" isn't possible though, as the test themselves use C++. The workaround here is that we specify the project needs both a C and C++ compiler if tests are used, but only a C compiler if the tests aren't used. --- CMakeLists.txt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 938f2a5b..e275fd60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,14 @@ IF ((CMAKE_VERSION VERSION_GREATER 3.1) OR CMAKE_POLICY(SET CMP0054 NEW) ENDIF () -PROJECT (msgpack-c) +OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON) +OPTION (MSGPACK_GEN_COVERAGE "Enable running gcov to get a test coverage report." OFF) + +if(MSGPACK_BUILD_TESTS) + PROJECT (msgpack-c) +else() + PROJECT (msgpack-c C) +endif() FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/version_master.h contents) STRING (REGEX MATCH "#define MSGPACK_VERSION_MAJOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents}) @@ -74,14 +81,6 @@ IF (MSGPACK_CHAR_SIGN) SET (CMAKE_C_FLAGS "-f${MSGPACK_CHAR_SIGN}-char ${CMAKE_C_FLAGS}") ENDIF () -FIND_PACKAGE (GTest) -FIND_PACKAGE (ZLIB) -FIND_PACKAGE (Threads) -IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND) - OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON) - OPTION (MSGPACK_GEN_COVERAGE "Enable running gcov to get a test coverage report." OFF) -ENDIF () - IF (DEFINED BUILD_SHARED_LIBS) IF (BUILD_SHARED_LIBS) IF (DEFINED MSGPACK_ENABLE_SHARED AND NOT MSGPACK_ENABLE_SHARED)