[StreamExecutor] Make SE work with an in-tree LLVM build.
authorJustin Lebar <jlebar@google.com>
Fri, 9 Sep 2016 21:01:02 +0000 (21:01 +0000)
committerJustin Lebar <jlebar@google.com>
Fri, 9 Sep 2016 21:01:02 +0000 (21:01 +0000)
Summary:
With these changes, we can put parallel-libs within llvm/projects and
build as normal.

This is kind of the minimal change I could figure out how to make while
still making us compatible with llvm's build system.  Some things I'm
not thrilled about include:

 * The creation of a CoreTests directory (the macros really seemed to
   want this)

 * Pulling SimpleHostPlatformDevice.h into CoreTests.  It seems to me
   this should live inside unittests/include, or maybe tests/include,
   but I didn't want to make that change in this patch.

One important piece of work that remains to be done is to make

  $ ninja check-streamexecutor

run all the tests.  Right now the only way I've figured out to run the
tests is

  $ ninja projects/parallel-libs/streamexecutor/unittests/StreamExecutorUnitTests
  $ projects/parallel-libs/streamexecutor/unittests/CoreTests/CoreTests

Reviewers: jhen

Subscribers: beanz, parallel_libs-commits, jprice

Differential Revision: https://reviews.llvm.org/D24368

llvm-svn: 281091

12 files changed:
parallel-libs/CMakeLists.txt [new file with mode: 0644]
parallel-libs/streamexecutor/CMakeLists.txt
parallel-libs/streamexecutor/lib/CMakeLists.txt
parallel-libs/streamexecutor/lib/Utils/CMakeLists.txt [new file with mode: 0644]
parallel-libs/streamexecutor/lib/unittests/CMakeLists.txt [deleted file]
parallel-libs/streamexecutor/unittests/CMakeLists.txt [new file with mode: 0644]
parallel-libs/streamexecutor/unittests/CoreTests/CMakeLists.txt [new file with mode: 0644]
parallel-libs/streamexecutor/unittests/CoreTests/DeviceTest.cpp [moved from parallel-libs/streamexecutor/lib/unittests/DeviceTest.cpp with 100% similarity]
parallel-libs/streamexecutor/unittests/CoreTests/KernelSpecTest.cpp [moved from parallel-libs/streamexecutor/lib/unittests/KernelSpecTest.cpp with 100% similarity]
parallel-libs/streamexecutor/unittests/CoreTests/PackedKernelArgumentArrayTest.cpp [moved from parallel-libs/streamexecutor/lib/unittests/PackedKernelArgumentArrayTest.cpp with 100% similarity]
parallel-libs/streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h [moved from parallel-libs/streamexecutor/lib/unittests/SimpleHostPlatformDevice.h with 100% similarity]
parallel-libs/streamexecutor/unittests/CoreTests/StreamTest.cpp [moved from parallel-libs/streamexecutor/lib/unittests/StreamTest.cpp with 100% similarity]

diff --git a/parallel-libs/CMakeLists.txt b/parallel-libs/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e96b2e4
--- /dev/null
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.1)
+
+add_subdirectory(streamexecutor)
index fde628f..c290104 100644 (file)
@@ -38,9 +38,9 @@ if(STREAM_EXECUTOR_STANDALONE)
         OUTPUT_STRIP_TRAILING_WHITESPACE)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS}")
 
-    # Find the libraries that correspond to the LLVM components
-    # that we wish to use
-    llvm_map_components_to_libnames(llvm_libs support symbolize)
+    set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
+    list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
+    include(AddLLVM)
 
     if(STREAM_EXECUTOR_UNIT_TESTS)
         enable_testing()
@@ -55,6 +55,10 @@ else(NOT STREAM_EXECUTOR_STANDALONE)
     endif()
 endif(STREAM_EXECUTOR_STANDALONE)
 
+# Find the libraries that correspond to the LLVM components
+# that we wish to use
+llvm_map_components_to_libnames(llvm_libs support symbolize)
+
 # Insist on C++ 11 features.
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -65,6 +69,10 @@ set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
 add_subdirectory(lib)
 add_subdirectory(examples)
 
+if(STREAM_EXECUTOR_UNIT_TESTS)
+    add_subdirectory(unittests)
+endif()
+
 if(STREAM_EXECUTOR_ENABLE_CONFIG_TOOL )
     add_subdirectory(tools/streamexecutor-config)
 endif(STREAM_EXECUTOR_ENABLE_CONFIG_TOOL )
index 8c3ac02..11873c4 100644 (file)
@@ -1,11 +1,12 @@
-add_library(
-    utils
-    OBJECT
-    Utils/Error.cpp)
+macro(add_se_library name)
+  add_llvm_library(${name} ${ARGN})
+  set_target_properties(${name} PROPERTIES FOLDER "streamexecutor libraries")
+endmacro(add_se_library)
 
-add_library(
+add_subdirectory(Utils)
+
+add_se_library(
     streamexecutor
-    $<TARGET_OBJECTS:utils>
     Device.cpp
     DeviceMemory.cpp
     Kernel.cpp
@@ -14,11 +15,10 @@ add_library(
     Platform.cpp
     PlatformDevice.cpp
     PlatformManager.cpp
-    Stream.cpp)
-target_link_libraries(streamexecutor ${llvm_libs})
+    Stream.cpp
 
-install(TARGETS streamexecutor DESTINATION lib)
+    LINK_LIBS
+      utils
+    )
 
-if(STREAM_EXECUTOR_UNIT_TESTS)
-    add_subdirectory(unittests)
-endif()
+install(TARGETS streamexecutor DESTINATION lib)
diff --git a/parallel-libs/streamexecutor/lib/Utils/CMakeLists.txt b/parallel-libs/streamexecutor/lib/Utils/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2cbbc3b
--- /dev/null
@@ -0,0 +1,3 @@
+add_se_library(
+  utils
+  Error.cpp)
diff --git a/parallel-libs/streamexecutor/lib/unittests/CMakeLists.txt b/parallel-libs/streamexecutor/lib/unittests/CMakeLists.txt
deleted file mode 100644 (file)
index e12b675..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-add_executable(
-    device_test
-    DeviceTest.cpp)
-target_link_libraries(
-    device_test
-    streamexecutor
-    ${GTEST_BOTH_LIBRARIES}
-    ${CMAKE_THREAD_LIBS_INIT})
-add_test(DeviceTest device_test)
-
-add_executable(
-    kernel_spec_test
-    KernelSpecTest.cpp)
-target_link_libraries(
-    kernel_spec_test
-    streamexecutor
-    ${GTEST_BOTH_LIBRARIES}
-    ${CMAKE_THREAD_LIBS_INIT})
-add_test(KernelSpecTest kernel_spec_test)
-
-add_executable(
-    packed_kernel_argument_array_test
-    PackedKernelArgumentArrayTest.cpp)
-target_link_libraries(
-    packed_kernel_argument_array_test
-    streamexecutor
-    ${llvm_libs}
-    ${GTEST_BOTH_LIBRARIES}
-    ${CMAKE_THREAD_LIBS_INIT})
-add_test(PackedKernelArgumentArrayTest packed_kernel_argument_array_test)
-
-add_executable(
-    stream_test
-    StreamTest.cpp)
-target_link_libraries(
-    stream_test
-    streamexecutor
-    ${llvm_libs}
-    ${GTEST_BOTH_LIBRARIES}
-    ${CMAKE_THREAD_LIBS_INIT})
-add_test(StreamTest stream_test)
diff --git a/parallel-libs/streamexecutor/unittests/CMakeLists.txt b/parallel-libs/streamexecutor/unittests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3a81422
--- /dev/null
@@ -0,0 +1,9 @@
+add_custom_target(StreamExecutorUnitTests)
+set_target_properties(StreamExecutorUnitTests PROPERTIES FOLDER "streamexecutor tests")
+
+function(add_se_unittest testdir_name)
+  add_unittest(StreamExecutorUnitTests ${testdir_name} ${ARGN})
+  target_link_libraries(${testdir_name} streamexecutor)
+endfunction()
+
+add_subdirectory(CoreTests)
diff --git a/parallel-libs/streamexecutor/unittests/CoreTests/CMakeLists.txt b/parallel-libs/streamexecutor/unittests/CoreTests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3365dd0
--- /dev/null
@@ -0,0 +1,7 @@
+add_se_unittest(
+  CoreTests
+  DeviceTest.cpp
+  KernelSpecTest.cpp
+  PackedKernelArgumentArrayTest.cpp
+  StreamTest.cpp
+)