Skip to content

Commit

Permalink
ENH: Integrate libLBFGS into our CMake build system
Browse files Browse the repository at this point in the history
  • Loading branch information
bradking committed Jan 24, 2025
1 parent 7f25a6f commit 2f2dcf5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ITKOptimizersv4Export.h"
#include <memory>

#include "lbfgs.h"
#include "itk_lbfgs.h"

namespace itk
{
Expand Down
7 changes: 6 additions & 1 deletion Modules/ThirdParty/libLBFGS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ set(ITKLIBLBFGS_THIRD_PARTY 1)
# set(ITKLIBLBFGS_NO_SRC 1)
#else()

set(ITKLIBLBFGS_INCLUDE_DIRS ${ITKLIBLBFGS_SOURCE_DIR}/include )
set(ITKLIBLBFGS_INCLUDE_DIRS ${ITKLIBLBFGS_SOURCE_DIR}/src)
set(ITKLIBLBFGS_LIBRARIES itklbfgs)

#endif()

itk_module_impl()

install(FILES ${ITKLIBLBFGS_SOURCE_DIR}/src/itk_lbfgs.h
DESTINATION ${ITKLIBLBFGS_INSTALL_INCLUDE_DIR}
COMPONENT Development
)
20 changes: 1 addition & 19 deletions Modules/ThirdParty/libLBFGS/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
ADD_LIBRARY( itklbfgs
lbfgs.c
)

IF(ITK_LIBRARY_PROPERTIES)
SET_TARGET_PROPERTIES(itklbfgs PROPERTIES ${ITK_LIBRARY_PROPERTIES})
ENDIF(ITK_LIBRARY_PROPERTIES)

set(ITK3P_INSTALL_EXPORT_NAME "${ITKLIBLBFGS-targets}")
set(ITK3P_INSTALL_INCLUDE_DIR "${ITKLIBLBFGS_INSTALL_INCLUDE_DIR}")
set(ITK3P_INSTALL_RUNTIME_DIR "${ITKLIBLBFGS_INSTALL_RUNTIME_DIR}")
set(ITK3P_INSTALL_LIBRARY_DIR "${ITKLIBLBFGS_INSTALL_LIBRARY_DIR}")
set(ITK3P_INSTALL_ARCHIVE_DIR "${ITKLIBLBFGS_INSTALL_ARCHIVE_DIR}")

IF(UNIX)
TARGET_LINK_LIBRARIES(itklbfgs m)
ENDIF(UNIX)

INSTALL(TARGETS itklbfgs
EXPORT ${ITK3P_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development)

add_subdirectory(itklbfgs)
itk_module_target(itklbfgs NO_INSTALL)
27 changes: 27 additions & 0 deletions Modules/ThirdParty/libLBFGS/src/itk_lbfgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
/*=========================================================================
* Include file to wrap the internal ITK libLBFGS library header
*=========================================================================*/

#ifndef itk_lbfgs_h
#define itk_lbfgs_h

#include <itklbfgs/include/lbfgs.h>

#endif
20 changes: 20 additions & 0 deletions Modules/ThirdParty/libLBFGS/src/itklbfgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_library(itklbfgs lib/lbfgs.c)
target_include_directories(itklbfgs PRIVATE include)

if(ITK_LIBRARY_PROPERTIES)
set_target_properties(itklbfgs PROPERTIES ${ITK_LIBRARY_PROPERTIES})
endif()

if(UNIX)
target_link_libraries(itklbfgs m)
endif()

install(TARGETS itklbfgs
EXPORT ${ITK3P_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/lbfgs.h
DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR}/itklbfgs/include)

0 comments on commit 2f2dcf5

Please sign in to comment.