From 51501c5351c737a298eb0cdc821c9eca126bc6f3 Mon Sep 17 00:00:00 2001 From: archibate <17721388340@163.com> Date: Tue, 25 Feb 2020 19:34:39 +0800 Subject: [PATCH] Add cmake configs for TI_WITH_OPENGL --- cmake/TaichiCore.cmake | 23 ++++++++++++++++++++--- taichi/platform/opengl/opengl_api.cpp | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/cmake/TaichiCore.cmake b/cmake/TaichiCore.cmake index 9d9e4951515320..89840bd6013684 100644 --- a/cmake/TaichiCore.cmake +++ b/cmake/TaichiCore.cmake @@ -24,6 +24,7 @@ endif() option(USE_STDCPP "Use -stdlib=libc++" OFF) option(TI_WITH_CUDA "Build with CUDA support" OFF) +option(TI_WITH_OPENGL "Build with OpenGL backend" ON) include_directories(${CMAKE_SOURCE_DIR}) include_directories(external/xxhash) @@ -53,6 +54,25 @@ if (TI_WITH_CUDA) endif() endif() +if (TI_WITH_OPENGL) + if(NOT GLEW_VERSION) + set(GLEW_VERSION 2.0.0) + endif() + find_package(GLEW ${GLEW_VERSION}) + if (GLEW_FOUND) + message("Building with GLEW ${GLEW_VERSION}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_OPENGL") + #if (MSVC) + # TODO(archibate): figure out how GL is installed on Windows... + #else() + target_link_libraries(${LIBRARY_NAME} /usr/lib/libGLEW.so GLEW) + target_link_libraries(${LIBRARY_NAME} /usr/lib/libglfw.so glfw) + #endif() + else() + message(WARNING "GLEW not found, ignoring TI_WITH_OPENGL.") + endif() +endif() + # http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project find_package(LLVM REQUIRED CONFIG 8.0) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") @@ -88,9 +108,6 @@ if (TI_WITH_CUDA) target_link_libraries(${LIBRARY_NAME} ${llvm_ptx_libs}) endif() -target_link_libraries(${LIBRARY_NAME} /usr/lib/libGLEW.so GLEW) -target_link_libraries(${LIBRARY_NAME} /usr/lib/libglfw.so glfw) - # add_executable(runtime runtime/runtime.cpp) # Optional dependencies diff --git a/taichi/platform/opengl/opengl_api.cpp b/taichi/platform/opengl/opengl_api.cpp index 71a2d58f068649..bc149116f52739 100644 --- a/taichi/platform/opengl/opengl_api.cpp +++ b/taichi/platform/opengl/opengl_api.cpp @@ -1,3 +1,4 @@ +#if TI_OPENGL #define USE_GLEW #ifdef USE_GLEW #define GLEW_STATIC @@ -324,3 +325,18 @@ bool is_opengl_api_available() } TLANG_NAMESPACE_END + +#else + +TLANG_NAMESPACE_BEGIN +namespace opengl { + +bool is_opengl_api_available() +{ + return false; +} + +} +TLANG_NAMESPACE_END + +#endif