From e6cdd671c0881e3c570bbcfd256e90140782e279 Mon Sep 17 00:00:00 2001 From: cn-nice Date: Thu, 7 Sep 2023 18:29:20 +0800 Subject: [PATCH] fix(CMakeLists): build fails when using cmake on mac with Xcode as generator. --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5c1e5535..a1507ea42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -495,6 +495,22 @@ target_compile_features (glog_internal PUBLIC $ ) + +# Note: When you use cmake to build with xcode as a generator under Mac, the build will fail. +# See https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries +if(CMAKE_GENERATOR STREQUAL "Xcode") + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp) + set(temporary_file "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/xcode.cpp") + + add_custom_command( + OUTPUT ${temporary_file} + COMMAND ${CMAKE_COMMAND} -E touch ${temporary_file} + COMMENT "Creating temporary files for building on Xcode" + ) + + target_sources(glog PRIVATE $<$:${temporary_file}>) +endif(CMAKE_GENERATOR STREQUAL "Xcode") + target_compile_features (glog PUBLIC cxx_std_14) add_library (glog::glog ALIAS glog)