Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[build] generate .xcconfig files with configure_file
Browse files Browse the repository at this point in the history
We previously used incremental `file(WRITE ...)` commands that gradually recreated the file on every CMake invocation. This sometimes lead to Xcode parsing a partially written file, which in turn breaks building dependend targets. Instead, we're now using a templated configuration file, which ensure that the file is created in one go and hopefully reduces the race condition between CMake and Xcode's automatic project updating.
  • Loading branch information
kkaefer committed Mar 28, 2017
1 parent c86b492 commit a9896fa
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ endif()
if(COMMAND mbgl_platform_node)
include(cmake/node.cmake)
endif()

if(CMAKE_GENERATOR STREQUAL "Xcode")
write_xcconfig_target_properties(
mbgl-core
)
endif()
1 change: 0 additions & 1 deletion cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ target_add_mason_package(mbgl-core PRIVATE wagyu)
mbgl_platform_core()

create_source_groups(mbgl-core)
target_append_xcconfig(mbgl-core)
1 change: 0 additions & 1 deletion cmake/loop-darwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ target_include_directories(mbgl-loop-darwin
)

create_source_groups(mbgl-loop-darwin)
target_append_xcconfig(mbgl-loop-darwin)
1 change: 0 additions & 1 deletion cmake/loop-uv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ target_include_directories(mbgl-loop-uv
)

create_source_groups(mbgl-loop-uv)
target_append_xcconfig(mbgl-loop-uv)
23 changes: 12 additions & 11 deletions cmake/mbgl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,28 @@ macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
set_property(TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
endmacro (set_xcode_property)

function(_write_xcconfig_var target var)
function(_get_xcconfig_property target var)
get_property(result TARGET ${target} PROPERTY INTERFACE_${var} SET)
if (result)
get_property(result TARGET ${target} PROPERTY INTERFACE_${var})
string(REPLACE ";" "\" \"" result "${result}")
string(REPLACE "-" "_" target "${target}")
file(APPEND "${CMAKE_BINARY_DIR}/config.xcconfig" "${target}_${var} = \"${result}\"\n")
set(${target}_${var} "${result}" PARENT_SCOPE)
endif()
endfunction()

function(target_append_xcconfig target)
file(APPEND "${CMAKE_BINARY_DIR}/config.xcconfig" "\n// ${target}\n")
_write_xcconfig_var(${target} INCLUDE_DIRECTORIES)
_write_xcconfig_var(${target} COMPILE_DEFINITIONS)
_write_xcconfig_var(${target} COMPILE_OPTIONS)
_write_xcconfig_var(${target} LINK_LIBRARIES)
function(write_xcconfig_target_properties)
foreach(target ${ARGN})
_get_xcconfig_property(${target} INCLUDE_DIRECTORIES)
_get_xcconfig_property(${target} LINK_LIBRARIES)
endforeach()
configure_file(
"${CMAKE_SOURCE_DIR}/scripts/config.xcconfig.in"
"${CMAKE_BINARY_DIR}/config.xcconfig"
@ONLY
)
endfunction()

# Start a new file when we're running CMake
file(WRITE "${CMAKE_BINARY_DIR}/config.xcconfig" "// Do not edit -- generated by CMake\n")

# CMake 3.1 does not have this yet.
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
10 changes: 2 additions & 8 deletions platform/macos/macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1725,10 +1725,7 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
HEADER_SEARCH_PATHS = (
"$(mbgl_core_INCLUDE_DIRECTORIES)",
"$(mbgl_loop_INCLUDE_DIRECTORIES)",
);
HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)";
INFOPLIST_FILE = "$(SRCROOT)/sdk/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -1762,10 +1759,7 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
HEADER_SEARCH_PATHS = (
"$(mbgl_core_INCLUDE_DIRECTORIES)",
"$(mbgl_loop_INCLUDE_DIRECTORIES)",
);
HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)";
INFOPLIST_FILE = "$(SRCROOT)/sdk/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
Expand Down
5 changes: 5 additions & 0 deletions scripts/config.xcconfig.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Do not edit -- generated by CMake

// mbgl-core
mbgl_core_INCLUDE_DIRECTORIES = "@mbgl_core_INCLUDE_DIRECTORIES@"
mbgl_core_LINK_LIBRARIES = "@mbgl_core_LINK_LIBRARIES@"

0 comments on commit a9896fa

Please sign in to comment.