cmake.patch 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. diff --git a/CMakeLists.txt b/CMakeLists.txt
  2. index afd7bb94..a8ccb883 100644
  3. --- a/CMakeLists.txt
  4. +++ b/CMakeLists.txt
  5. @@ -267,15 +267,18 @@ endif (R_LANG)
  6. # Create Static Library
  7. # ----------------------------------------------
  8. -
  9. +include(GNUInstallDirs)
  10. +include(FindPkgConfig)
  11. +pkg_search_module(qdldl REQUIRED IMPORTED_TARGET qdldl)
  12. # Add linear system solvers cumulative library
  13. add_subdirectory(lin_sys)
  14. +if(NOT BUILD_SHARED_LIBS)
  15. # Static library
  16. add_library (osqpstatic STATIC ${osqp_src} ${osqp_headers} ${linsys_solvers})
  17. # Give same name to static library output
  18. set_target_properties(osqpstatic PROPERTIES OUTPUT_NAME osqp)
  19. -
  20. +target_link_libraries(osqpstatic PkgConfig::qdldl)
  21. # Include directories for linear system solvers
  22. target_include_directories(osqpstatic PRIVATE ${linsys_solvers_includes})
  23. @@ -294,7 +297,7 @@ install(TARGETS osqpstatic
  24. ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  25. LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  26. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  27. -
  28. +endif()
  29. # Install Headers
  30. # ----------------------------------------------
  31. @@ -310,10 +313,11 @@ endif (MATLAB)
  32. # If we are building Python/Matlab/R interface:
  33. # - do not build shared library
  34. # - do not build demo
  35. -if (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT EMBEDDED)
  36. +if (BUILD_SHARED_LIBS)
  37. # Create osqp shared library
  38. # NB: Add all the linear system solvers here
  39. add_library (osqp SHARED ${osqp_src} ${osqp_headers} ${linsys_solvers})
  40. + target_link_libraries(osqp PkgConfig::qdldl)
  41. # Include directories for linear system solvers
  42. target_include_directories(osqp PRIVATE ${linsys_solvers_includes})
  43. @@ -331,10 +335,9 @@ if (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT EMBEDDED)
  44. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  45. # Create demo executable (linked to static library)
  46. - add_executable (osqp_demo ${PROJECT_SOURCE_DIR}/examples/osqp_demo.c)
  47. - target_link_libraries (osqp_demo osqpstatic)
  48. -endif (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT EMBEDDED)
  49. +
  50. +endif (BUILD_SHARED_LIBS)
  51. # Create CMake packages for the build directory
  52. # ----------------------------------------------
  53. diff --git a/lin_sys/direct/CMakeLists.txt b/lin_sys/direct/CMakeLists.txt
  54. index c36c375a..2942cc9f 100644
  55. --- a/lin_sys/direct/CMakeLists.txt
  56. +++ b/lin_sys/direct/CMakeLists.txt
  57. @@ -6,7 +6,7 @@ add_subdirectory(qdldl)
  58. # Need to add qdldlobject only here because it cannot be
  59. # included in another object library such as linsys_qdldl
  60. -set(direct_linsys_solvers $<TARGET_OBJECTS:linsys_qdldl> $<TARGET_OBJECTS:qdldlobject>)
  61. +set(direct_linsys_solvers $<TARGET_OBJECTS:linsys_qdldl> )
  62. # NB. The second directory is added because we need to include the "qdldl_types.h" file in "qdldl_interface.h"
  63. set(direct_linsys_solvers_includes
  64. diff --git a/lin_sys/direct/qdldl/CMakeLists.txt b/lin_sys/direct/qdldl/CMakeLists.txt
  65. index d78c4a38..b3429a12 100644
  66. --- a/lin_sys/direct/qdldl/CMakeLists.txt
  67. +++ b/lin_sys/direct/qdldl/CMakeLists.txt
  68. @@ -1,5 +1,4 @@
  69. # Add qdldl
  70. -add_subdirectory(qdldl_sources)
  71. if(NOT DEFINED EMBEDDED)
  72. @@ -39,3 +38,4 @@ set(qdldl_interface_src
  73. # Create object library for linear system solver interface
  74. add_library(linsys_qdldl OBJECT ${qdldl_interface_src})
  75. target_include_directories(linsys_qdldl PRIVATE ${qdldl_interface_includes} ${PROJECT_SOURCE_DIR}/include)
  76. +target_link_libraries(linsys_qdldl PkgConfig::qdldl)