From e3800df71c3a36ee5e1185b46034679fffdf58d6 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 29 Jul 2015 15:22:09 -0400 Subject: [PATCH] Avoid target conflicts with glslang and googletest. This makes it easier to include spirv-tools into larger cmake-based projects, which may already include glslang or googletest. It is currently difficult to do this because of target clashes and a hardcoded googletest path. glslang defines a target named SPIRV, so rename ours to SPIRV-TOOLS. A googletest subdirectory may already be added somewhere else, so if the external/googletest directory does not exist, probe whether there is a gtest target defined already. This makes spirv-tools work out-of-the-box when plopped into a larger project already containing googletest; otherwise the README.md procedure still works as before. --- CMakeLists.txt | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f08b83..62e85e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. cmake_minimum_required(VERSION 2.8) -project(SPIRV) +project(spirv-tools) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") add_definitions(-DSPIRV_LINUX) @@ -113,27 +113,27 @@ set(SPIRV_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/source/validate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/validate_id.cpp) -add_library(SPIRV ${SPIRV_SOURCES}) -target_link_libraries(SPIRV ${SPIRV_LIBS}) -set_target_properties(SPIRV PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS}) +add_library(SPIRV-TOOLS ${SPIRV_SOURCES}) +target_link_libraries(SPIRV-TOOLS ${SPIRV_LIBS}) +set_target_properties(SPIRV-TOOLS PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS}) add_executable(spirv-as ${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h ${CMAKE_CURRENT_SOURCE_DIR}/tools/as/as.cpp) set_target_properties(spirv-as PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS}) -target_link_libraries(spirv-as SPIRV) +target_link_libraries(spirv-as SPIRV-TOOLS) add_executable(spirv-dis ${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h ${CMAKE_CURRENT_SOURCE_DIR}/tools/dis/dis.cpp) set_target_properties(spirv-dis PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS}) -target_link_libraries(spirv-dis SPIRV) +target_link_libraries(spirv-dis SPIRV-TOOLS) add_executable(spirv-val ${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h ${CMAKE_CURRENT_SOURCE_DIR}/tools/val/val.cpp) set_target_properties(spirv-val PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS}) -target_link_libraries(spirv-val SPIRV) +target_link_libraries(spirv-val SPIRV-TOOLS) set(GTEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest) if(EXISTS ${GTEST_DIR}) @@ -143,13 +143,14 @@ if(EXISTS ${GTEST_DIR}) ON) endif() + add_subdirectory(${GTEST_DIR}) +endif() +if (TARGET gtest) message(STATUS "Found googletest, building tests.") include_directories(SYSTEM - ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest - ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/include) - - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/googletest) + ${gtest_SOURCE_DIR} + ${gtest_SOURCE_DIR}/include) add_executable(UnitSPIRV ${CMAKE_CURRENT_SOURCE_DIR}/test/UnitSPIRV.h @@ -172,14 +173,14 @@ if(EXISTS ${GTEST_DIR}) ${CMAKE_CURRENT_SOURCE_DIR}/test/Validate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/ValidateID.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp) - target_link_libraries(UnitSPIRV SPIRV gtest) + target_link_libraries(UnitSPIRV SPIRV-TOOLS gtest) else() message(STATUS "Did not find googletest, tests will not be built." "To enable tests place googletest in '/external/googletest'.") endif() set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install) -install(TARGETS SPIRV spirv-as spirv-dis spirv-val +install(TARGETS SPIRV-TOOLS spirv-as spirv-dis spirv-val RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -- 2.7.4