Skip to content

Commit

Permalink
fix(CMakeLists): build fails when using cmake on mac with Xcode as ge…
Browse files Browse the repository at this point in the history
…nerator.
  • Loading branch information
cn-nice committed Sep 7, 2023
1 parent 6fbc93a commit e6cdd67
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,22 @@ target_compile_features (glog_internal PUBLIC $<TARGET_PROPERTY:glog,COMPILE_FEA
add_library (glog
$<TARGET_OBJECTS:glog_internal>
)

# 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 $<$<BOOL:${temporary_file}>:${temporary_file}>)
endif(CMAKE_GENERATOR STREQUAL "Xcode")

target_compile_features (glog PUBLIC cxx_std_14)

add_library (glog::glog ALIAS glog)
Expand Down

0 comments on commit e6cdd67

Please sign in to comment.