Enable TBB for Linux builds

- Fix FindTBB.cmake
- Add TBB logic to various CMakeLists
- Update documentation
This commit is contained in:
manuelk 2013-08-15 16:11:33 -07:00
parent d28dad10e5
commit d57df0eae0
4 changed files with 124 additions and 59 deletions

View File

@ -30,7 +30,7 @@ cmake_minimum_required(VERSION 2.8.6)
#-------------------------------------------------------------------------------
# Obtain OpenSubdiv API version from version.h file
if(EXISTS "${CMAKE_SOURCE_DIR}/opensubdiv/version.h")
file(STRINGS "${CMAKE_SOURCE_DIR}/opensubdiv/version.h"
file(STRINGS "${CMAKE_SOURCE_DIR}/opensubdiv/version.h"
OpenSubdiv_VERSION REGEX "^#define OPENSUBDIV_VERSION .*$")
string(REPLACE "#define OPENSUBDIV_VERSION " "" OpenSubdiv_VERSION ${OpenSubdiv_VERSION})
endif()
@ -118,7 +118,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANGCC OR CMAKE_COMPILER_IS_ICC
# gcc 4.4.1 versions onwards. We disable the warning but keep aliasing
# optimization.
list(APPEND OSD_COMPILER_FLAGS -Wno-strict-aliasing)
# FAR and OSD have templated virtual function implementations that trigger
# a lot of hidden virtual function overloads (some of them spurrious).
# Disable those for now in Clang.
@ -142,7 +142,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANGCC OR CMAKE_COMPILER_IS_ICC
ia32/
mic/
)
if (ICC_${ICC_LIB})
list(APPEND ICC_LIBRARIES ${ICC_${ICC_LIB}})
else()
@ -156,7 +156,7 @@ elseif(MSVC)
# Turn on all warnings
list(APPEND OSD_COMPILER_FLAGS /Wall)
# MSVC is unfortunately not standard conforming with regards to
# the alternative names for logical and bitwise operators:
# http://stackoverflow.com/questions/555505/c-alternative-tokens
@ -186,7 +186,7 @@ elseif(MSVC)
/Dxor=^/**/
/Dxor_eq=^=
)
list(APPEND OSD_COMPILER_FLAGS
/W3 # Use warning level recommended for production purposes.
@ -197,42 +197,42 @@ elseif(MSVC)
/wd4350
# warning C4548: expression before comma has no effect; expected expression with side-effect
/wd4548
# Make sure WinDef.h does not define min and max macros which
# will conflict with std::min() and std::max().
/DNOMINMAX
# Make sure the constants in <math.h> get defined.
/D_USE_MATH_DEFINES
# Do not enforce MSVC's safe CRT replacements.
/D_CRT_SECURE_NO_WARNINGS
# Disable checked iterators and iterator debugging. Visual Studio
# 2008 does not implement std::vector::data(), so we need to take the
# address of std::vector::operator[](0) to get the memory location of
# a vector's underlying data storage. This does not work for an empty
# vector if checked iterators or iterator debugging is enabled.
# XXXX manuelk : we can't force SECURE_SCL to 0 or client code has
# problems linking against OSD if their build is not also
# overriding SSCL to the same value.
# See : http://msdn.microsoft.com/en-us/library/vstudio/hh697468.aspx
# XXXX manuelk : we can't force SECURE_SCL to 0 or client code has
# problems linking against OSD if their build is not also
# overriding SSCL to the same value.
# See : http://msdn.microsoft.com/en-us/library/vstudio/hh697468.aspx
#/D_SECURE_SCL=0
#/D_HAS_ITERATOR_DEBUGGING=0
)
# Turn off a duplicate LIBCMT linker warning
set(CMAKE_EXE_LINKER_FLAGS
# Turn off a duplicate LIBCMT linker warning
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt.lib")
set(CMAKE_SHARED_LINKER_FLAGS
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:libcmt.lib")
endif()
if(${SIMD} MATCHES "AVX")
list(APPEND OSD_COMPILER_FLAGS -xAVX)
endif()
endif()
add_definitions(${OSD_COMPILER_FLAGS})
@ -246,6 +246,9 @@ set(CMAKE_SUPPRESS_REGENERATION TRUE)
if(NOT NO_OMP)
find_package(OpenMP)
endif()
if(NOT NO_TBB)
find_package(TBB 4.0)
endif()
find_package(OpenGL)
find_package(OpenGLES)
find_package(OpenCL 1.1)
@ -300,6 +303,20 @@ else()
"in your cmake installation.")
endif()
if(TBB_FOUND)
add_definitions(
-DOPENSUBDIV_HAS_TBB
${TBB_CXX_FLAGS}
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TBB_CXX_FLAGS}")
else()
message(WARNING
"TBB was not found : support for TBB parallel compute kernels "
"will be diabled in Osd. If your compiler supports TBB "
"directives, please refer to the FindTBB.cmake shared module "
"in your cmake installation.")
endif()
if(GLFW_FOUND AND (GLFW_VERSION VERSION_EQUAL 3.0 OR GLFW_VERSION VERSION_GREATER 3.0))
add_definitions( -DGLFW_VERSION_3 )
endif()
@ -453,7 +470,7 @@ macro(_add_doxy_headers headers)
)
add_custom_target(${targetname} DEPENDS ${outfile})
#set_target_properties(${targetname} PROPERTIES FOLDER "public_headers/")
list(APPEND headerfiles ${targetname} )
@ -472,7 +489,7 @@ macro(_add_possibly_cuda_executable target)
else()
add_executable(${target} ${ARGN})
endif()
if(CMAKE_COMPILER_IS_ICC)
target_link_libraries(${target} ${ICC_LIBRARIES})
endif()

View File

@ -63,51 +63,72 @@ else ()
DOC "The directory where TBB headers reside")
endif ()
set (TBB_LIB_ARCH "")
if (WIN32)
if ("${CMAKE_GENERATOR}" MATCHES "[Ww]in64")
set(WINPATH intel64)
else ()
set(WINPATH ia32)
endif()
if (MSVC80)
set(WINPATH "${WINPATH}/vc8")
elseif (MSVC90)
set(WINPATH "${WINPATH}/vc9")
elseif (MSVC10)
set(WINPATH "${WINPATH}/vc10")
elseif (MSVC11)
set(WINPATH "${WINPATH}/vc11")
endif()
list(APPEND TBB_LIB_ARCH ${WINPATH})
elseif(ANDROID)
list(APPEND TBB_LIB_ARCH "android")
else()
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
list(APPEND TBB_LIB_ARCH "intel64")
elseif(CMAKE_SIZEOF_VOID_P MATCHES "4")
list(APPEND TBB_LIB_ARCH "ia32")
endif()
endif()
# List library files
foreach(TBB_LIB tbb tbb_debug
foreach(TBB_LIB tbb tbb_debug
tbbmalloc tbbmalloc_debug
tbbmalloc_proxy tbbmalloc_proxy_debug
tbb_preview tbb_preview_debug)
if (WIN32)
if ("${CMAKE_GENERATOR}" MATCHES "[Ww]in64")
set(WINPATH intel64)
else ()
set(WINPATH ia32)
endif()
if (MSVC80)
set(WINPATH "${WINPATH}/vc8")
elseif (MSVC90)
set(WINPATH "${WINPATH}/vc9")
elseif (MSVC10)
set(WINPATH "${WINPATH}/vc10")
elseif (MSVC11)
set(WINPATH "${WINPATH}/vc11")
endif()
endif()
find_library(TBB_${TBB_LIB}_LIBRARY
NAMES
${TBB_LIB}
PATHS
${TBB_LOCATION}/lib
${TBB_LOCATION}/bin/${WINPATH}
${TBB_LOCATION}/lib/${WINPATH}
${TBB_LOCATION}/bin
$ENV{TBB_LOCATION}/lib
$ENV{TBB_LOCATION}/bin/${WINPATH}
$ENV{TBB_LOCATION}/bin
$ENV{PROGRAMFILES}/TBB/lib
/usr/lib
/usr/lib/w32api
/usr/local/lib
/usr/X11R6/lib
DOC "Intel's Threading Building Blocks library")
PATH_SUFFIXES
${TBB_LIB_ARCH}
${TBB_LIB_ARCH}/${TBB_COMPILER}
${TBB_LIB_ARCH}/gcc4.4
${TBB_LIB_ARCH}/gcc4.1
DOC "Intel's Threading Building Blocks library")
if (TBB_${TBB_LIB}_LIBRARY)
list(APPEND TBB_LIBRARIES ${TBB_${TBB_LIB}_LIBRARY})
endif()
endforeach()
# Obtain version information
@ -115,20 +136,20 @@ if(TBB_INCLUDE_DIR)
# Tease the TBB version numbers from the lib headers
function(parseVersion FILENAME VARNAME)
set(PATTERN "^#define ${VARNAME}.*$")
file(STRINGS "${TBB_INCLUDE_DIR}/${FILENAME}" TMP REGEX ${PATTERN})
string(REGEX MATCHALL "[0-9]+" TMP ${TMP})
set(${VARNAME} ${TMP} PARENT_SCOPE)
endfunction()
if(EXISTS "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h")
parseVersion(tbb/tbb_stddef.h TBB_VERSION_MAJOR)
parseVersion(tbb/tbb_stddef.h TBB_VERSION_MINOR)
parseVersion(tbb/tbb_stddef.h TBB_VERSION_MINOR)
endif()
if(${TBB_VERSION_MAJOR} OR ${TBB_VERSION_MINOR})
@ -144,7 +165,7 @@ endif(TBB_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TBB
find_package_handle_standard_args(TBB
REQUIRED_VARS
TBB_INCLUDE_DIR
TBB_LIBRARIES

View File

@ -74,6 +74,7 @@ ________
- `Zlib <http://www.zlib.net/>`__ (required for Ptex under Windows)
- `GLEW <http://glew.sourceforge.net/>`__ (Windows/Linux only)
- `CUDA <http://www.nvidia.com/object/cuda_home_new.html>`__
- `TBB <http://www.threadingbuildingblocks.org/>`__
- `OpenCL <http://www.khronos.org/opencl/>`__
- `DX11 SDK <http://www.microsoft.com/>`__
- `GLFW <https://github.com/glfw/glfw>`__ (required for standalone examples
@ -111,6 +112,7 @@ The following configuration arguments can be passed to the cmake command line.
-DGLEW_LOCATION=[path to GLEW]
-DGLFW_LOCATION=[path to GLFW]
-DMAYA_LOCATION=[path to Maya]
-DTBB_LOCATION=[path to Intel's TBB]
-DICC_LOCATION=[path to Intel's C++ Studio XE]
-DNO_LIB=1 // disable the opensubdiv libs build (caveat emptor)
@ -119,6 +121,7 @@ The following configuration arguments can be passed to the cmake command line.
-DNO_PYTHON=1 // disable Python SWIG build
-DNO_DOC=1 // disable documentation build
-DNO_OMP=1 // disable OpenMP
-DNO_TBB=1 // disable TBB
-DNO_CUDA=1 // disable CUDA
-DNO_GCD=1 // disable GrandCentralDispatch on OSX

View File

@ -139,17 +139,17 @@ if( PTEX_FOUND )
)
endif()
list(APPEND DOXY_HEADER_FILES
${GL_PTEX_PUBLIC_HEADERS}
${DX_PTEX_PUBLIC_HEADERS}
list(APPEND DOXY_HEADER_FILES
${GL_PTEX_PUBLIC_HEADERS}
${DX_PTEX_PUBLIC_HEADERS}
)
#-------------------------------------------------------------------------------
set(OPENMP_PUBLIC_HEADERS
set(OPENMP_PUBLIC_HEADERS
ompKernel.h
ompComputeController.h
)
if( OPENMP_FOUND )
list(APPEND CPU_SOURCE_FILES
ompKernel.cpp
@ -167,12 +167,36 @@ endif()
list(APPEND DOXY_HEADER_FILES ${OPENMP_PUBLIC_HEADERS})
#-------------------------------------------------------------------------------
if( TBB_FOUND )
include_directories(
${TBB_INCLUDE_DIR}
)
list(APPEND CPU_SOURCE_FILES
tbbKernel.cpp
tbbComputeController.cpp
)
list(APPEND PUBLIC_HEADER_FILES
tbbKernel.h
tbbComputeController.h
)
if (CMAKE_COMPILER_IS_GNUCXX)
list(APPEND PLATFORM_CPU_LIBRARIES
gomp
)
endif()
list(APPEND PLATFORM_CPU_LIBRARIES
${TBB_LIBRARIES}
)
endif()
#-------------------------------------------------------------------------------
set(GCD_PUBLIC_HEADERS
gcdKernel.h
gcdComputeController.h
)
if( GCD_FOUND )
list(APPEND CPU_SOURCE_FILES
gcdKernel.cpp
@ -373,7 +397,7 @@ if( CUDA_FOUND )
list(APPEND PUBLIC_HEADER_FILES
cudaD3D11VertexBuffer.h
)
endif()
endif()
if (UNIX)
list( APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC --gpu-architecture compute_11 )
@ -483,7 +507,7 @@ install( FILES ${PUBLIC_HEADER_FILES}
if (ANDROID)
install( FILES Android.mk
install( FILES Android.mk
DESTINATION ${LIBRARY_OUTPUT_PATH_ROOT}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ )
endif()