--- CMakeLists.txt.orig 2023-05-25 14:48:50 UTC +++ CMakeLists.txt @@ -272,28 +272,32 @@ 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 (BUILD_STATIC_LIBS) + add_library (osqp STATIC ${osqp_src} ${osqp_headers} ${linsys_solvers}) + # Give same name to static library output + set_target_properties(osqp 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(osqp PRIVATE ${linsys_solvers_includes}) -# Declare include directories for the cmake exported target -target_include_directories(osqpstatic - PUBLIC "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}/osqp>") + # Declare include directories for the cmake exported target + target_include_directories(osqp + PUBLIC "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}/osqp>") +endif() # 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 (BUILD_STATIC_LIBS) + install(TARGETS osqp + EXPORT ${PROJECT_NAME} + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif() # Install Headers @@ -304,7 +308,7 @@ install(FILES ${osqp_headers} DESTINATION "${CMAKE_INS if (MATLAB) -target_link_libraries (osqpstatic ${Matlab_LIBRARIES}) +target_link_libraries (osqp ${Matlab_LIBRARIES}) endif (MATLAB) # If we are building Python/Matlab/R interface: @@ -331,8 +335,10 @@ if (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT E RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") # Create demo executable (linked to static library) - add_executable (osqp_demo ${PROJECT_SOURCE_DIR}/examples/osqp_demo.c) - target_link_libraries (osqp_demo osqpstatic) + if (BUILD_EXAMPLES) + add_executable (osqp_demo ${PROJECT_SOURCE_DIR}/examples/osqp_demo.c) + target_link_libraries (osqp_demo osqp) + endif() endif (NOT PYTHON AND NOT MATLAB AND NOT R_LANG AND NOT EMBEDDED) @@ -431,7 +437,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 ${CMAKE_DL_LIBS}) # Add custom memory target add_executable(osqp_tester_custom_memory @@ -443,7 +449,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 ${CMAKE_DL_LIBS}) # Add testing include(CTest)