From 060751ffcca0d0f2b800baf09b2e067310d9ddb2 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sat, 10 Aug 2024 12:03:04 +0200 Subject: [PATCH] Add support for building on Windows with Ninja --- .gitmodules | 2 +- CMakeLists.txt | 53 ++++++++++++++++++------------ lin_sys/direct/qdldl/qdldl_sources | 2 +- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/.gitmodules b/.gitmodules index 00e6fcd57..a498d6ff5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "lin_sys/direct/qdldl/qdldl_sources"] path = lin_sys/direct/qdldl/qdldl_sources - url = https://github.com/osqp/qdldl.git + url = https://github.com/robotology-dependencies/qdldl.git diff --git a/CMakeLists.txt b/CMakeLists.txt index afd7bb940..aa6708671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ endif() option (COVERAGE "Perform code coverage" OFF) message(STATUS "Code coverage is ${COVERAGE}") +option (OSQP_BUILD_STATIC_LIB "Build the static library" ON) # Memory allocators # ---------------------------------------------- @@ -272,29 +273,36 @@ endif (R_LANG) add_subdirectory(lin_sys) # Static library -add_library (osqpstatic STATIC ${osqp_src} ${osqp_headers} ${linsys_solvers}) -# Give same name to static library output -set_target_properties(osqpstatic PROPERTIES OUTPUT_NAME osqp) +if (OSQP_BUILD_STATIC_LIB) + add_library (osqpstatic STATIC ${osqp_src} ${osqp_headers} ${linsys_solvers}) + # Give same name to static library output + set_target_properties(osqpstatic PROPERTIES OUTPUT_NAME osqp) -# Include directories for linear system solvers -target_include_directories(osqpstatic PRIVATE ${linsys_solvers_includes}) + # Include directories for linear system solvers + target_include_directories(osqpstatic PRIVATE ${linsys_solvers_includes}) + + # Declare include directories for the cmake exported target + target_include_directories(osqpstatic + PUBLIC "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}/osqp>") + set(OSQP_TARGET_TO_LINK_IN_INTERNAL_EXECUTABLES "osqpstatic") +else() + set(OSQP_TARGET_TO_LINK_IN_INTERNAL_EXECUTABLES "osqp") +endif() -# Declare include directories for the cmake exported target -target_include_directories(osqpstatic - PUBLIC "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}/osqp>") # Install Static Library # ---------------------------------------------- include(GNUInstallDirs) -install(TARGETS osqpstatic - EXPORT ${PROJECT_NAME} - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") - +if (OSQP_BUILD_STATIC_LIB) + install(TARGETS osqpstatic + EXPORT ${PROJECT_NAME} + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif() # Install Headers # ---------------------------------------------- @@ -303,9 +311,9 @@ install(FILES ${osqp_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/osqp") -if (MATLAB) +if (MATLAB AND OSQP_BUILD_STATIC_LIB) target_link_libraries (osqpstatic ${Matlab_LIBRARIES}) -endif (MATLAB) +endif (MATLAB AND OSQP_BUILD_STATIC_LIB) # If we are building Python/Matlab/R interface: # - do not build shared library @@ -330,9 +338,12 @@ if (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT EMBEDDED) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") - # Create demo executable (linked to static library) + set_target_properties(osqp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + # Create demo executable add_executable (osqp_demo ${PROJECT_SOURCE_DIR}/examples/osqp_demo.c) - target_link_libraries (osqp_demo osqpstatic) + target_link_libraries (osqp_demo ${OSQP_TARGET_TO_LINK_IN_INTERNAL_EXECUTABLES}) + endif (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT EMBEDDED) @@ -431,7 +442,7 @@ if (UNITTESTS) CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) - target_link_libraries (osqp_tester osqpstatic ${CMAKE_DL_LIBS}) + target_link_libraries (osqp_tester ${OSQP_TARGET_TO_LINK_IN_INTERNAL_EXECUTABLES} ${CMAKE_DL_LIBS}) # Add custom memory target add_executable(osqp_tester_custom_memory @@ -443,7 +454,7 @@ if (UNITTESTS) ${PROJECT_SOURCE_DIR}/tests/custom_memory/custom_memory.c ${PROJECT_SOURCE_DIR}/tests/custom_memory/custom_memory.h ) - target_link_libraries (osqp_tester_custom_memory osqpstatic ${CMAKE_DL_LIBS}) + target_link_libraries (osqp_tester_custom_memory ${OSQP_TARGET_TO_LINK_IN_INTERNAL_EXECUTABLES} ${CMAKE_DL_LIBS}) # Add testing include(CTest) diff --git a/lin_sys/direct/qdldl/qdldl_sources b/lin_sys/direct/qdldl/qdldl_sources index 7d16b70a1..3770026c0 160000 --- a/lin_sys/direct/qdldl/qdldl_sources +++ b/lin_sys/direct/qdldl/qdldl_sources @@ -1 +1 @@ -Subproject commit 7d16b70a10a152682204d745d814b6eb63dc5cd2 +Subproject commit 3770026c0546216df29c0ea37102df20d33f2ba5