瀏覽代碼

Configurable between static and dynamic

Johannes Kreutz 3 年之前
父節點
當前提交
02b3f8d81f
共有 2 個文件被更改,包括 124 次插入19 次删除
  1. 52 19
      trackpoint-app/CMakeLists.txt
  2. 72 0
      trackpoint-app/cmake/FindLib3MF.cmake

+ 52 - 19
trackpoint-app/CMakeLists.txt

@@ -18,26 +18,32 @@ SET(CMAKE_AUTORCC ON)
 
 SET(CMAKE_INCLUDE_CURRENT_DIR ON)
 
-# Set dependency directory
-#LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/openscenegraph/install")
-#LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/lib3mf/install")
-#LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/json/install")
-LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/qt/install")
-
-# OpenSceneGraph
-INCLUDE(thirdparty/openscenegraph.cmake)
-#FIND_PACKAGE(OpenSceneGraph REQUIRED COMPONENTS osgViewer osgDB osgGA osgText osgUtil)
-
 # Qt
+LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/qt/install")
 FIND_PACKAGE(Qt6 COMPONENTS Core Gui Widgets OpenGLWidgets REQUIRED NO_CMAKE_SYSTEM_PATH)
 
-# lib3mf
-INCLUDE(thirdparty/lib3mf.cmake)
-#FIND_PACKAGE(Lib3MF REQUIRED)
-
 # Json
 INCLUDE(thirdparty/json.cmake)
-#FIND_PACKAGE(nlohmann_json REQUIRED NO_CMAKE_SYSTEM_PATH)
+
+# Development build: dynamic link
+if(NOT BUILD_STATIC_RELEASE)
+  # OpenSceneGraph
+  INCLUDE(thirdparty/openscenegraph.cmake)
+
+  # lib3mf
+  INCLUDE(thirdparty/lib3mf.cmake)
+ENDIF()
+
+# Release build: static link
+if(BUILD_STATIC_RELEASE)
+  # OpenSceneGraph
+  LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/openscenegraph/install")
+  FIND_PACKAGE(OpenSceneGraph REQUIRED COMPONENTS osgViewer osgDB osgGA osgText osgUtil)
+
+  # lib3mf
+  LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/thirdparty/lib3mf/install")
+  FIND_PACKAGE(Lib3MF REQUIRED)
+ENDIF()
 
 # The executable we want to build
 QT_ADD_EXECUTABLE(TrackpointApp
@@ -54,17 +60,44 @@ QT_ADD_EXECUTABLE(TrackpointApp
   src/OpenScadRenderer.cpp
 )
 
+set (TRACKPOINTAPP_INCLUDE_DIRS "")
+set (TRACKPOINTAPP_LINK_LIBRARIES "")
+
+if(NOT BUILD_STATIC_RELEASE)
+  LIST(APPEND TRACKPOINTAPP_INCLUDE_DIRS
+    ${${OPENSCENEGRAPH_PREFIX}_SOURCE_DIR}/include
+    ${${LIB3MF_PREFIX}_BINARY_DIR}/Autogenerated/Bindings/Cpp
+  )
+
+  LIST(APPEND TRACKPOINTAPP_LINK_LIBRARIES
+    osg osgViewer osgDB osgGA osgText osgUtil
+    lib3mf
+  )
+ENDIF()
+
+if(BUILD_STATIC_RELEASE)
+  LIST(APPEND TRACKPOINTAPP_INCLUDE_DIRS
+    ${OPENSCENEGRAPH_INCLUDE_DIRS}
+    ${LIB3MF_INCLUDE_DIRS}
+  )
+
+  LIST(APPEND TRACKPOINTAPP_LINK_LIBRARIES
+    ${OPENSCENEGRAPH_LIBRARIES}
+    ${LIB3MF_LIBRARIES}
+  )
+ENDIF()
+
+message(${TRACKPOINTAPP_INCLUDE_DIRS} status)
+
 INCLUDE_DIRECTORIES(
-  ${${OPENSCENEGRAPH_PREFIX}_SOURCE_DIR}/include
-  ${${LIB3MF_PREFIX}_BINARY_DIR}/Autogenerated/Bindings/Cpp
+  ${TRACKPOINTAPP_INCLUDE_DIRS}
   ${${JSON_PREFIX}_SOURCE_DIR}/include
   include
   gui
 )
 
 TARGET_LINK_LIBRARIES(TrackpointApp PRIVATE
-  osg osgViewer osgDB osgGA osgText osgUtil
-  lib3mf
+  ${TRACKPOINTAPP_LINK_LIBRARIES}
   nlohmann_json::nlohmann_json
   Qt6::Core
   Qt6::Gui

+ 72 - 0
trackpoint-app/cmake/FindLib3MF.cmake

@@ -0,0 +1,72 @@
+#
+# Try to find 3MF library and include path.
+# Once done this will define
+#
+# LIB3MF_FOUND
+# LIB3MF_CFLAGS
+# LIB3MF_LIBDIR
+# LIB3MF_INCLUDE_DIRS
+# LIB3MF_LIBRARIES
+#
+
+# Don't specify REQUIRED here in case pkg-config fails.
+# We still fall back to the rest of detection code here.
+# Travis CI Ubuntu Trusty environment has some issue with pkg-config
+# not finding the version.
+#pkg_check_modules(LIB3MF lib3MF)
+
+# default to uppercase for 1.0 library name
+#set(LIB3MF_LIB "3MF")
+
+# some distribution packages are missing version information for 2.0
+#if (LIB3MF_VERSION STREQUAL "" AND LIB3MF_FOUND)
+#  if (EXISTS "/usr/include/lib3mf" AND EXISTS "/usr/include/lib3mf/lib3mf_implicit.hpp")
+#    set(LIB3MF_VERSION "2.0.0")
+#  endif()
+#endif()
+
+#if (LIB3MF_VERSION VERSION_EQUAL 1.8.1 OR LIB3MF_VERSION VERSION_GREATER 1.8.1)
+#  set(LIB3MF_API "API 1.x")
+#endif()
+
+#if (LIB3MF_VERSION VERSION_EQUAL 2.0.0 OR LIB3MF_VERSION VERSION_GREATER 2.0.0)
+  #set(LIB3MF_API "API 2.x")
+  set(LIB3MF_LIB "3mf")
+  #add_definitions(-DLIB3MF_API_2)
+#endif()
+
+#if (NOT $ENV{OPENSCAD_LIBRARIES} STREQUAL "")
+  if (EXISTS "${CMAKE_SOURCE_DIR}/thirdparty/lib3mf/install")
+    message(STATUS "found lib3mf in thirdparty.")
+    set(LIB3MF_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/thirdparty/lib3mf/install/include/Bindings/Cpp")
+    set(LIB3MF_LIBDIR "${CMAKE_SOURCE_DIR}/thirdparty/lib3mf/install/lib")
+  endif()
+#endif()
+
+#if ("${LIB3MF_LIBDIR}" STREQUAL "")
+#  if (EXISTS "/opt/include/lib3mf/Model/COM/NMR_DLLInterfaces.h")
+#    set(LIB3MF_INCLUDE_DIRS "/opt/include/lib3mf" "/opt/include/lib3mf/Model/COM")
+#    set(LIB3MF_LIBDIR "/opt/lib")
+#  else()
+#    if (EXISTS "/usr/local/include/lib3mf/Model/COM/NMR_DLLInterfaces.h")
+#      set(LIB3MF_INCLUDE_DIRS "/usr/local/include/lib3mf" "/usr/local/include/lib3mf/Model/COM")
+#      set(LIB3MF_LIBDIR "/usr/local/lib")
+#    else()
+#      if (EXISTS "/usr/include/lib3mf/Model/COM/NMR_DLLInterfaces.h")
+#        set(LIB3MF_INCLUDE_DIRS "/usr/include/lib3mf" "/usr/include/lib3mf/Model/COM")
+#        set(LIB3MF_LIBDIR "/usr/lib")
+#      endif()
+#    endif()
+#  endif()
+#endif()
+
+if (NOT ${LIB3MF_LIBDIR} STREQUAL "")
+  find_library(LIBZ_LIBRARY NAMES z)
+  find_library(LIBZIP_LIBRARY NAMES zip)
+  set(LIB3MF_LIBRARIES "-L${LIB3MF_LIBDIR}" "-l${LIB3MF_LIB} ${LIBZIP_LIBRARY} ${LIBZ_LIBRARY}")
+  set(LIB3MF_FOUND TRUE)
+else()
+#  set(LIB3MF_API "disabled")
+  set(LIB3MF_FOUND FALSE)
+  message(STATUS "Could not find lib3mf.")
+endif()