Skip to content

Commit

Permalink
Having some fun with XCode
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcao3 committed Dec 23, 2022
1 parent 28b818d commit 2aaeff9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmake/TaichiCAPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ if(TI_BUILD_TESTS)
endif()

add_library(${TAICHI_C_API_NAME} SHARED ${C_API_SOURCE})
target_link_static_library(${TAICHI_C_API_NAME} taichi_core)
if (${CMAKE_GENERATOR} STREQUAL "Xcode")
target_link_libraries(${TAICHI_C_API_NAME} PRIVATE taichi_core)
message(WARNING "Static wrapping does not work on Xcode, using object linking instead.")
else()
target_link_static_library(${TAICHI_C_API_NAME} taichi_core)
endif()
target_enable_function_level_linking(${TAICHI_C_API_NAME})

# Strip shared library
Expand Down
2 changes: 1 addition & 1 deletion cmake/TaichiCXXFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (WIN32)
else()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message("Clang compiler detected. Using std=c++17.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fsized-deallocation -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fsized-deallocation -Wno-deprecated-declarations -Wno-shorten-64-to-32")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
message("GNU compiler detected. Using std=c++17.")
message(WARNING "It is detected that you are using gcc as the compiler. This is an experimental feature. Consider adding -DCMAKE_CXX_COMPILER=clang argument to CMake to switch to clang (or MSVC on Windows).")
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def get_cmake_args():
cmake_args = shlex.split(os.getenv('TAICHI_CMAKE_ARGS', '').strip())

use_msbuild = False
use_xcode = False

if (os.getenv('DEBUG', '0') in ('1', 'ON')):
cfg = 'Debug'
Expand All @@ -129,6 +130,11 @@ def get_cmake_args():
build_options.extend(['-G', 'Visual Studio 17 2022'])
else:
build_options.extend(['-G', 'Ninja', '--skip-generator-test'])
if sys.platform == "darwin":
if (os.getenv('TAICHI_USE_XCODE', '0') in ('1', 'ON')):
use_xcode = True
if use_xcode:
build_options.extend(['-G', 'Xcode', '--skip-generator-test'])
sys.argv[2:2] = build_options

cmake_args += [
Expand All @@ -137,7 +143,9 @@ def get_cmake_args():
f'-DTI_VERSION_PATCH={TI_VERSION_PATCH}',
]

if sys.platform != 'win32':
if sys.platform == "darwin" and use_xcode:
os.environ['SKBUILD_BUILD_OPTIONS'] = f'-jobs {num_threads}'
elif sys.platform != 'win32':
os.environ['SKBUILD_BUILD_OPTIONS'] = f'-j{num_threads}'
elif use_msbuild:
# /M uses multi-threaded build (similar to -j)
Expand Down

0 comments on commit 2aaeff9

Please sign in to comment.