From 5818f6727667553f15f652a7941c9846ea580280 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20=C3=9Cbelh=C3=B6r?= <t.uebelhoer@irt.rwth-aachen.de>
Date: Wed, 16 Jan 2019 18:08:57 +0100
Subject: [PATCH] created conan package

---
 .gitignore                  |  6 ++--
 CMakeLists.txt              | 64 +++++++------------------------------
 README.md                   |  2 +-
 conanfile.py                | 42 ++++++++++++++++++++++++
 package.xml                 |  1 +
 scigl_renderConfig.cmake.in | 15 ---------
 test_package/CMakeLists.txt |  8 +++++
 test_package/conanfile.py   | 22 +++++++++++++
 test_package/example.cpp    |  8 +++++
 9 files changed, 97 insertions(+), 71 deletions(-)
 create mode 100644 conanfile.py
 delete mode 100644 scigl_renderConfig.cmake.in
 create mode 100644 test_package/CMakeLists.txt
 create mode 100644 test_package/conanfile.py
 create mode 100644 test_package/example.cpp

diff --git a/.gitignore b/.gitignore
index 2572316..a765f7c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-install/
-build/
-log/
+install
+build
+log
 *.blend1
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 708d6b7..fbc225f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,6 @@
-cmake_minimum_required(VERSION 3.12)
 project(scigl_render)
 
-# Default ROS2 configurations for compilation
-if(NOT CMAKE_CXX_STANDARD)
-  set(CMAKE_CXX_STANDARD 11)
-endif()
-set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+cmake_minimum_required(VERSION 2.8.3)
 
 # using conan to manage dependencies
 if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
@@ -13,15 +8,15 @@ if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
    file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.13/conan.cmake"
                  "${CMAKE_BINARY_DIR}/conan.cmake")
 endif()
-include(${CMAKE_BINARY_DIR}/conan.cmake)
-conan_cmake_run(
-  REQUIRES
-    Assimp/4.1.0@jacmoe/stable
-    gl3w/0.1@tuebel/experimental
-    glm/0.9.9.1@g-truc/stable
-    glfw/3.2.1@bincrafters/stable
-  BASIC_SETUP CMAKE_TARGETS
-  BUILD missing)
+if(CONAN_EXPORTED) # when packaging
+  include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+  conan_basic_setup()
+else() # in user space
+  include(${CMAKE_BINARY_DIR}/conan.cmake)
+  conan_cmake_run(CONANFILE conanfile.py
+    BASIC_SETUP
+    BUILD missing)
+endif()
 
 # prefer new ABI for OpenGL
 set(OpenGL_GL_PREFERENCE "GLVND")
@@ -41,15 +36,8 @@ target_sources(scigl_render PRIVATE
   src/shader/depth_shader.cpp
   src/shader/shader.cpp
   src/shader/single_texture_shader.cpp)
-target_include_directories(scigl_render PUBLIC
-  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
-  $<INSTALL_INTERFACE:include>)
-target_link_libraries(scigl_render PUBLIC
-  CONAN_PKG::gl3w
-  CONAN_PKG::glfw
-  CONAN_PKG::glm
-  CONAN_PKG::Assimp)
-target_compile_options(scigl_render PRIVATE -Wall -Wextra)
+target_include_directories(scigl_render PUBLIC include)
+target_link_libraries(scigl_render ${CONAN_LIBS})
 
 # example apps
 add_executable(scigl_viewer
@@ -63,31 +51,3 @@ add_executable(scigl_depth_viewer
   src/example/example_render.cpp)
 target_link_libraries(scigl_depth_viewer
   scigl_render)
-  
-
-# install target
-install(DIRECTORY include/scigl_render DESTINATION include)
-install(TARGETS scigl_render scigl_viewer scigl_depth_viewer
-  EXPORT scigl_render_targets
-  LIBRARY DESTINATION lib
-  ARCHIVE DESTINATION lib
-  RUNTIME DESTINATION bin
-  INCLUDES DESTINATION include)
-# versioning
-include(CMakePackageConfigHelpers)
-write_basic_package_version_file(
-  scigl_renderConfigVersion.cmake
-  VERSION 0.1
-  COMPATIBILITY AnyNewerVersion)
-# for find_package support
-install(EXPORT scigl_render_targets
-  FILE scigl_render_targets.cmake
-  DESTINATION lib/cmake/scigl_render)
-configure_file(scigl_renderConfig.cmake.in scigl_renderConfig.cmake @ONLY)
-install(FILES 
-  "${CMAKE_CURRENT_BINARY_DIR}/scigl_renderConfig.cmake"
-  "${CMAKE_CURRENT_BINARY_DIR}/scigl_renderConfigVersion.cmake"
-  DESTINATION lib/cmake/scigl_render)
-# export for source tree
-export(TARGETS scigl_render FILE scigl_render_targets.cmake)
-export(PACKAGE scigl_render)
diff --git a/README.md b/README.md
index 6814592..0a4123f 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ in ROS2.
 The dependencies are handled via [conan.io](https://conan.io/).
 Please add the following repositories:
 ```bash
-conan remote add tuebel https://api.bintray.com/conan/tuebel/gl3w
+conan remote add tuebel-gl3w https://api.bintray.com/conan/tuebel/gl3w
 conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
 conan remote add conan-transit https://api.bintray.com/conan/conan/conan-transit
 ```
diff --git a/conanfile.py b/conanfile.py
new file mode 100644
index 0000000..f831034
--- /dev/null
+++ b/conanfile.py
@@ -0,0 +1,42 @@
+from conans import ConanFile, CMake
+
+
+class SciglRenderConan(ConanFile):
+    name = "scigl_render"
+    version = "0.1"
+    license = "MIT"
+    url = "https://git.rwth-aachen.de/robo_guide/scigl_render"
+    description = ("Library to simplify rendering objects via OpenGL."
+                   "The intendet use case is scientific "
+                   "(e.g. probabalistic filtering).")
+    settings = "os", "compiler", "build_type", "arch"
+    requires = ("Assimp/4.1.0@jacmoe/stable",
+                "gl3w/0.2@tuebel/testing",
+                "glm/0.9.9.1@g-truc/stable",
+                "glfw/3.2.1@bincrafters/stable")
+    generators = "cmake"
+    exports = "CMakeLists.txt"
+    exports_sources = "src/*", "include/*"
+    options = {"shared": [True, False], "fPIC": [True, False]}
+    default_options = "shared=False", "fPIC=True"
+
+    def configure(self):
+        if self.settings.compiler == 'Visual Studio':
+            del self.options.fPIC
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        self.copy("*.h", dst="include", src="include", keep_path=True)
+        self.copy("*.hpp", dst="include", src="include", keep_path=True)
+        self.copy("*.lib", dst="lib", keep_path=False)
+        self.copy("*.dll", dst="bin", keep_path=False)
+        self.copy("*.dylib*", dst="lib", keep_path=False)
+        self.copy("*.so", dst="lib", keep_path=False)
+        self.copy("*.a", dst="lib", keep_path=False)
+
+    def package_info(self):
+        self.cpp_info.libs = ["scigl_render"]
diff --git a/package.xml b/package.xml
index 5649b1f..7fa3448 100644
--- a/package.xml
+++ b/package.xml
@@ -20,6 +20,7 @@
 
   <doc_depend>doxygen</doc_depend>
   <buildtool_depend>cmake</buildtool_depend>
+  <buildtool_depend>conan</buildtool_depend>
   <build_depend>gl3w</build_depend>
   <depend>OpenGL</depend>
   <depend>glfw</depend>
diff --git a/scigl_renderConfig.cmake.in b/scigl_renderConfig.cmake.in
deleted file mode 100644
index 06cf4d6..0000000
--- a/scigl_renderConfig.cmake.in
+++ /dev/null
@@ -1,15 +0,0 @@
-get_filename_component(scigl_render_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-set(scigle_render_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")
-
-include(CMakeFindDependencyMacro)
-find_dependency(gl3w REQUIRED)
-find_dependency(glfw3 REQUIRED)
-find_dependency(assimp REQUIRED)
-find_dependency(glm REQUIRED)
-
-if(NOT TARGET scigl_render)
-  include(${CMAKE_CURRENT_LIST_DIR}/scigl_render_targets.cmake)
-endif()
-
-set(scigl_render_LIBRARIES scigl_render)
-set(scigl_render_EXECUTABLE scigl_viewer scigl_depth_viewer)
\ No newline at end of file
diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt
new file mode 100644
index 0000000..e469d1e
--- /dev/null
+++ b/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+project(PackageTest)
+cmake_minimum_required(VERSION 2.8.12)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(example example.cpp)
+target_link_libraries(example ${CONAN_LIBS})
diff --git a/test_package/conanfile.py b/test_package/conanfile.py
new file mode 100644
index 0000000..1756708
--- /dev/null
+++ b/test_package/conanfile.py
@@ -0,0 +1,22 @@
+from conans import ConanFile, CMake
+import os
+
+
+class Gl3wTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+    options = {"shared": [True, False], "fPIC": [True, False]}
+    default_options = "shared=False", "fPIC=True"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def imports(self):
+        self.copy("*.dll", dst="bin", src="bin")
+        self.copy("*.dylib*", dst="bin", src="lib")
+
+    def test(self):
+        os.chdir("bin")
+        self.run(".%sexample" % os.sep)
diff --git a/test_package/example.cpp b/test_package/example.cpp
new file mode 100644
index 0000000..d01943f
--- /dev/null
+++ b/test_package/example.cpp
@@ -0,0 +1,8 @@
+#include <cstdlib>
+#include <scigl_render/gl_context.hpp>
+
+int main(int argc, char **argv)
+{
+  scigl_render::GLContext gl_context(true, false, 640, 480);
+  return EXIT_SUCCESS;
+}
-- 
GitLab