From ce4a21114be319fda1d0c60ecb572f6ebf604636 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 3 Apr 2019 08:23:55 +0300
Subject: [PATCH] Minor cmake cuda refactor

---
 .gitignore                          |  2 +-
 CMakeLists.txt                      |  8 +++++++-
 common/cpp/include/ftl/config.h.in  |  1 +
 cv-node/CMakeLists.txt              | 10 +++-------
 cv-node/include/ftl/cuda_common.hpp |  2 ++
 5 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1a54ff158..7574bf03a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
 */build
-*/node_modules
+**/node_modules
 **/include/ftl/config.h
 **/src/config.cpp
 **/*.blend1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eca831d06..1a2f84925 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,14 +19,20 @@ find_package( URIParser REQUIRED )
 find_package( MsgPack REQUIRED )
 find_package( LibSGM )
 
+# Why is this problematic on some machines?
 check_language(CUDA)
 if (CUDA_TOOLKIT_ROOT_DIR)
 enable_language(CUDA)
 set(CMAKE_CUDA_FLAGS "")
 set(CMAKE_CUDA_FLAGS_DEBUG "-g -DDEBUG -D_DEBUG -Wall")
 set(CMAKE_CUDA_FLAGS_RELEASE "")
-add_definitions(-DHAVE_CUDA)
+set(HAVE_CUDA TRUE)
 include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
+
+set_property(TARGET Threads::Threads
+                 PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler -pthread>
+                                                    "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>")
+
 endif ()
 
 if (NOT MsgPack_FOUND)
diff --git a/common/cpp/include/ftl/config.h.in b/common/cpp/include/ftl/config.h.in
index d3e216603..b03e4eeef 100644
--- a/common/cpp/include/ftl/config.h.in
+++ b/common/cpp/include/ftl/config.h.in
@@ -4,6 +4,7 @@
 #cmakedefine HAVE_VIZ
 #cmakedefine HAVE_OPENCVCUDA
 #cmakedefine HAVE_URIPARSESINGLE
+#cmakedefine HAVE_CUDA
 
 extern const char *FTL_VERSION_LONG;
 extern const char *FTL_VERSION;
diff --git a/cv-node/CMakeLists.txt b/cv-node/CMakeLists.txt
index 5f5457c82..8a77cce2b 100644
--- a/cv-node/CMakeLists.txt
+++ b/cv-node/CMakeLists.txt
@@ -43,14 +43,10 @@ add_executable(cv-node ${CVNODESRC})
 add_dependencies(cv-node net)
 
 if (CUDA_FOUND)
-set_property(TARGET Threads::Threads
-                 PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler -pthread>
-                                                    "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>")
-
 set_property(TARGET cv-node PROPERTY CUDA_SEPARABLE_COMPILATION ON)
-endif (CUDA_FOUND)
+endif()
 
-target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(cv-node Threads::Threads ${OpenCV_LIBS} ${LIBSGM_LIBRARIES} ${CUDA_LIBRARIES} ${GLOG_LIBRARIES})
+#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
+target_link_libraries(cv-node net Threads::Threads ${OpenCV_LIBS} ${LIBSGM_LIBRARIES} ${CUDA_LIBRARIES} ${GLOG_LIBRARIES})
 
 
diff --git a/cv-node/include/ftl/cuda_common.hpp b/cv-node/include/ftl/cuda_common.hpp
index 1adeed475..741f857cc 100644
--- a/cv-node/include/ftl/cuda_common.hpp
+++ b/cv-node/include/ftl/cuda_common.hpp
@@ -1,6 +1,8 @@
 #ifndef _FTL_CUDA_COMMON_HPP_
 #define _FTL_CUDA_COMMON_HPP_
 
+#include <ftl/config.h>
+
 #if defined HAVE_CUDA
 
 #include <opencv2/core/cuda.hpp>
-- 
GitLab