Skip to content

Commit 19aaeed

Browse files
committed
Integrate oneTBB and oneDPL into Nabla's build system, reorganize toolchain detection (put into separate file)
1 parent 8ed6e31 commit 19aaeed

File tree

9 files changed

+305
-190
lines changed

9 files changed

+305
-190
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@
8686
[submodule "3rdparty/nbl_spirv_cross"]
8787
path = 3rdparty/nbl_spirv_cross
8888
url = https://github.com/devshgraphicsprogramming/SPIRV-Cross.git
89+
[submodule "3rdparty/pstl/oneDPL/oneDPL"]
90+
path = 3rdparty/pstl/oneDPL/oneDPL
91+
url = https://github.com/oneapi-src/oneDPL.git
92+
[submodule "3rdparty/pstl/oneTBB"]
93+
path = 3rdparty/pstl/oneTBB
94+
url = https://github.com/Devsh-Graphics-Programming/oneTBB.git

3rdparty/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ if(DEFINED ENV{VULKAN_SDK})
6262
target_include_directories(volk_headers INTERFACE "$ENV{VULKAN_SDK}/include")
6363
endif()
6464

65+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
66+
add_subdirectory(pstl pstl)
67+
endif()
68+
6569
# SDL2
6670
if (NBL_COMPILE_WITH_SDL2)
6771
set(SDL_STATIC_ENABLED_BY_DEFAULT ON)

3rdparty/pstl/CMakeLists.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # only non-multi-generators and clang supported
2+
get_filename_component(CCBD_ABSOLUTE "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE)
3+
4+
set(TBB_INSTALL_VARS ON CACHE BOOL "" FORCE)
5+
set(TBB_TEST OFF CACHE BOOL "" FORCE)
6+
set(TBB_STRICT ON CACHE BOOL "" FORCE)
7+
set(PREVIOUS_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
8+
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
9+
set(TBB_SANITIZE "" CACHE STRING "" FORCE)
10+
add_subdirectory(oneTBB oneTBB)
11+
12+
if(PREVIOUS_BUILD_SHARED_LIBS)
13+
set(BUILD_SHARED_LIBS ${PREVIOUS_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
14+
else()
15+
unset(BUILD_SHARED_LIBS CACHE)
16+
endif()
17+
18+
set(ONETBB_BUILD ${CCBD_ABSOLUTE}/oneTBB)
19+
set(ONETBB_INSTALL_DIR ${ONETBB_BUILD}/install CACHE STRING "oneTBB install directory" FORCE)
20+
21+
add_custom_target(onetbb_build
22+
COMMAND ${CMAKE_COMMAND} --install ${ONETBB_BUILD} --component devel -v --config $<CONFIG> --prefix ${ONETBB_INSTALL_DIR}
23+
COMMAND ${CMAKE_COMMAND} --install ${ONETBB_BUILD} --component runtime -v --config $<CONFIG> --prefix ${ONETBB_INSTALL_DIR}
24+
DEPENDS tbb tbbmalloc tbbmalloc_proxy
25+
COMMENT "Building oneTBB..."
26+
)
27+
28+
set(ONEDPL_BUILD ${CCBD_ABSOLUTE}/oneDPL/build)
29+
set(ONEDPL_INSTALL_DIR ${ONEDPL_BUILD}/install CACHE STRING "oneDPL install directory" FORCE)
30+
31+
set(CMAKE_ARGS_ONEDPL
32+
-DCMAKE_BUILD_TYPE:STRING=$<CONFIG>
33+
-DONETBB_INSTALL_DIR:PATH=${ONETBB_INSTALL_DIR}
34+
)
35+
36+
if(ANDROID)
37+
list(APPEND CMAKE_ARGS_ONEDPL
38+
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}
39+
-DANDROID_ABI:STRING=${ANDROID_ABI}
40+
-DANDROID_PLATFORM:STRING=${ANDROID_PLATFORM}
41+
)
42+
endif()
43+
44+
ExternalProject_Add(oneDPL
45+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/oneDPL
46+
BINARY_DIR ${ONEDPL_BUILD}
47+
CMAKE_ARGS ${CMAKE_ARGS_ONEDPL}
48+
BUILD_COMMAND cmake --build ${ONEDPL_BUILD} --target build-all
49+
INSTALL_COMMAND cmake --install ${ONEDPL_BUILD} --prefix ${ONEDPL_INSTALL_DIR}
50+
USES_TERMINAL_BUILD 1
51+
COMMENT "Building oneDPL..."
52+
)
53+
54+
add_dependencies(oneDPL onetbb_build)
55+
endif()

3rdparty/pstl/oneDPL/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/toolchains/android/build.cmake)
3+
4+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
5+
if(NOT DEFINED ONETBB_INSTALL_DIR)
6+
message(FATAL_ERROR "oneDPL submodule requires valid ONETBB_INSTALL_DIR!")
7+
endif()
8+
9+
set(TBB_DIR ${ONETBB_INSTALL_DIR}/lib/cmake/TBB CACHE INTERNAL "" FORCE)
10+
set(ONEDPL_BACKEND tbb CACHE STRING "" FORCE)
11+
add_subdirectory(oneDPL oneDPL)
12+
13+
if(ANDROID)
14+
add_compile_options(
15+
$<$<CONFIG:DEBUG>:-glldb>
16+
)
17+
endif()
18+
endif()

3rdparty/pstl/oneDPL/oneDPL

Submodule oneDPL added at 5483b88

3rdparty/pstl/oneTBB

Submodule oneTBB added at 5d21288

CMakeLists.txt

Lines changed: 2 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -7,197 +7,9 @@ cmake_minimum_required(VERSION 3.20)
77
cmake_policy(SET CMP0072 OLD) #not yet, would need to get pointers to all OpenGL functions
88
set(OpenGL_GL_PREFERENCE LEGACY)
99
#cmake_policy(SET CMP )
10-
set(NBL_BUILD_ANDROID OFF)
1110

12-
if(DEFINED CMAKE_TOOLCHAIN_FILE)
13-
14-
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
15-
cmake_path(GET CMAKE_TOOLCHAIN_FILE FILENAME _NBL_CMAKE_TOOLCHAIN_FILENAME_)
16-
else()
17-
message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE as '${CMAKE_TOOLCHAIN_FILE}' is invalid!")
18-
endif()
19-
20-
if(${_NBL_CMAKE_TOOLCHAIN_FILENAME_} STREQUAL "android.toolchain.cmake")
21-
message(STATUS "Found Android toolchain! Validating...")
22-
23-
set(_NBL_SUPPORTED_ABI_
24-
"x86_64"
25-
# "arm64-v8a" in future
26-
)
27-
28-
if(DEFINED ANDROID_ABI) # see _NBL_SUPPORTED_ABI_
29-
set(FOUND 0)
30-
foreach(CURRENT_ABI IN LISTS _NBL_SUPPORTED_ABI_)
31-
if("${CURRENT_ABI}" STREQUAL ${ANDROID_ABI})
32-
message(STATUS "Selecting found ${CURRENT_ABI} ABI!")
33-
set(FOUND 1)
34-
break()
35-
endif()
36-
endforeach()
37-
38-
if(NOT FOUND)
39-
message(FATAL_ERROR "Selected ${ANDROID_ABI} isn't appropriate. Supported ABIs: ${_NBL_SUPPORTED_ABI_}!")
40-
else()
41-
unset(FOUND)
42-
endif()
43-
else()
44-
message(FATAL_ERROR "ANDROID_ABI must be specified at the very beginning of execution!")
45-
endif()
46-
47-
if(NOT DEFINED ANDROID_PLATFORM) # android-28
48-
message(FATAL_ERROR "ANDROID_PLATFORM must be specified at the very beginning of execution!")
49-
endif()
50-
51-
include(${CMAKE_TOOLCHAIN_FILE})
52-
53-
if(${ANDROID_NDK_MAJOR} LESS 22)
54-
message(FATAL_ERROR "Update your NDK to at least 22. We don't support ${ANDROID_NDK_REVISION} NDK version!")
55-
endif()
56-
57-
# note that we assume NDK has been installed using Android Studio, so the existing paths should look as followning:
58-
# ${ANDROID_SDK_ROOT_PATH}/ndk/${ANDROID_NDK_REVISION}/build/cmake/android.toolchain.cmake
59-
60-
set(ANDROID_NDK_ROOT_PATH ${CMAKE_ANDROID_NDK})
61-
get_filename_component(ANDROID_SDK_ROOT_PATH "${ANDROID_NDK_ROOT_PATH}/../../" ABSOLUTE)
62-
63-
if(EXISTS "${ANDROID_SDK_ROOT_PATH}/build-tools")
64-
message(STATUS "Building Nabla with ${ANDROID_NDK_REVISION} NDK!")
65-
endif()
66-
67-
set(NBL_BUILD_ANDROID ON)
68-
set(_NBL_ANDROID_VALIDATED_ ON)
69-
endif()
70-
71-
# TODO - another toolchains in future
72-
73-
endif()
74-
75-
if(NBL_BUILD_ANDROID)
76-
if(NOT DEFINED _NBL_ANDROID_VALIDATED_)
77-
message(FATAL_ERROR "Android toolchain hasn't been validated properly. Pass an appropriate path to CMAKE_TOOLCHAIN_FILE!")
78-
endif()
79-
80-
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
81-
message(STATUS "Using Linux as a host OS for Android cross-compiling!")
82-
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
83-
message(STATUS "Using Windows as a host OS for Android cross-compiling!")
84-
else()
85-
message(FATAL_ERROR "Current host OS for Android cross-compiling isn't allowed!")
86-
endif()
87-
88-
# TODO - remove those bellow in future
89-
set(_NBL_COMPILE_WITH_OPEN_EXR_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - check it out
90-
set(_NBL_COMPILE_WITH_BAW_LOADER_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - remove when BAW-v4 is done
91-
set(_NBL_COMPILE_WITH_BAW_WRITER_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - remove when BAW-v4 is done
92-
set(_NBL_COMPILE_WITH_OBJ_LOADER_ ON CACHE BOOL "Off for Android purposes at the moment" FORCE)
93-
set(NBL_BUILD_MITSUBA_LOADER OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - compile/linker errors
94-
95-
find_package(Java 1.8)
96-
97-
if(DEFINED Java_JAVA_EXECUTABLE)
98-
message(STATUS "Found Java executable!: ${Java_JAVA_EXECUTABLE}")
99-
else()
100-
message(FATAL_ERROR "Could not find java executable for Android build!")
101-
endif()
102-
103-
string(LENGTH ${Java_JAVA_EXECUTABLE} Java_JAVA_EXECUTABLE_LENGTH)
104-
if(MSVC)
105-
set(Java_JAVA_EXE_BIN_LENGTH 13)
106-
else()
107-
set(Java_JAVA_EXE_BIN_LENGTH 9)
108-
endif()
109-
math(EXPR JAVA_HOME_LENGTH "${Java_JAVA_EXECUTABLE_LENGTH} - ${Java_JAVA_EXE_BIN_LENGTH}" OUTPUT_FORMAT DECIMAL)
110-
string(SUBSTRING ${Java_JAVA_EXECUTABLE} 0 ${JAVA_HOME_LENGTH} JAVA_HOME)
111-
112-
message(STATUS "Using JAVA_HOME = ${JAVA_HOME}")
113-
114-
execute_process(COMMAND ${JAVA_HOME}/bin/java -version
115-
RESULT_VARIABLE _result
116-
OUTPUT_VARIABLE _output
117-
ERROR_VARIABLE _output
118-
OUTPUT_STRIP_TRAILING_WHITESPACE
119-
ERROR_STRIP_TRAILING_WHITESPACE)
120-
121-
if(NOT _result AND _output MATCHES "version \"([0-9]+).([0-9]+)")
122-
message(STATUS "Java in JAVA_HOME is ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}")
123-
else()
124-
message(STATUS "Java in JAVA_HOME is unknown version ${_output} ${_result}")
125-
endif()
126-
127-
#option(STRIP_ANDROID_LIBRARY "Strip the resulting android library" OFF)
128-
129-
string(SUBSTRING
130-
"${ANDROID_PLATFORM}"
131-
8 # length of "android-"
132-
-1 # take remainder
133-
ANDROID_API_LEVEL
134-
)
135-
136-
# default to libc++_static as the other options can cause crashes
137-
if(NOT ANDROID_STL)
138-
set(ANDROID_STL "c++_static")
139-
endif()
140-
141-
# Choose clang if the NDK has both gcc and clang, since gcc sometimes fails
142-
# iirc api levels > 21 have only clang available
143-
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang")
144-
145-
#
146-
# android-specific utils and build tools
147-
#
148-
set(ANDROID_BUILD_TOOLS_VERSION "" CACHE STRING "Version of Android build-tools to use instead of the default")
149-
# take most recent version of build tools, if not set explicitely
150-
if(ANDROID_BUILD_TOOLS_VERSION STREQUAL "")
151-
file(GLOB __buildTools RELATIVE "${ANDROID_SDK_ROOT_PATH}/build-tools" "${ANDROID_SDK_ROOT_PATH}/build-tools/*")
152-
list(SORT __buildTools)
153-
154-
list(GET __buildTools -1 ANDROID_BUILD_TOOLS_VERSION)
155-
156-
unset(__buildTools)
157-
endif()
158-
set(ANDROID_BUILD_TOOLS "${ANDROID_SDK_ROOT_PATH}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}")
159-
if(MSVC)
160-
set(ANDROID_JAVA_BIN "${JAVA_HOME}")
161-
else()
162-
set(ANDROID_JAVA_BIN "${JAVA_HOME}/bin")
163-
endif()
164-
set(ANDROID_JAVA_RT_JAR "${JAVA_HOME}/jre/lib/rt.jar")
165-
166-
set(ANDROID_APK_TARGET_ID "" CACHE STRING "The Target ID to build the APK for like 'android-99', use <android list targets> to choose another one.")
167-
if(ANDROID_APK_TARGET_ID STREQUAL "")
168-
# This seems different from the platform we're targetting,
169-
# default to the latest available that's greater or equal to our target platform
170-
file(GLOB __platforms RELATIVE "${ANDROID_SDK_ROOT_PATH}/platforms" "${ANDROID_SDK_ROOT_PATH}/platforms/*")
171-
list(SORT __platforms)
172-
173-
# In case we don't find one, target the latest platform
174-
list(GET __platforms -1 ANDROID_APK_TARGET_ID)
175-
176-
string(REPLACE "android-" "" __targetPlat "${ANDROID_PLATFORM}")
177-
178-
# TODO we might want to adjust min version in the future
179-
# We require at least android 23 for Activity.requestPermissions
180-
if(__targetPlat LESS 23)
181-
set(__targetPlat 23)
182-
endif()
183-
184-
foreach( __plat ${__platforms})
185-
string(REPLACE "android-" "" __curPlat "${__plat}")
186-
187-
if(NOT (__curPlat LESS __targetPlat) )
188-
set(ANDROID_APK_TARGET_ID "android-${__curPlat}")
189-
break()
190-
endif()
191-
endforeach()
192-
193-
unset(__platforms)
194-
unset(__targetPlat)
195-
unset(__curPlat)
196-
endif()
197-
198-
message(STATUS "Using android.jar from platform ${ANDROID_APK_TARGET_ID}")
199-
set(ANDROID_JAR "${ANDROID_SDK_ROOT_PATH}/platforms/${ANDROID_APK_TARGET_ID}/android.jar")
200-
endif()
11+
include(ExternalProject)
12+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchains/android/build.cmake)
20113

20214
project(Nabla LANGUAGES CXX C)
20315

0 commit comments

Comments
 (0)