Skip to content

Commit

Permalink
Update CMakeLists to support converted project to C
Browse files Browse the repository at this point in the history
  • Loading branch information
hpwxf committed Nov 12, 2023
1 parent b0414da commit fb52162
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 55 deletions.
65 changes: 11 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
cmake_minimum_required(VERSION 3.10)
project(lbfgsb_cpp CXX)
project(lbfgsb_cpp)

enable_language(C CXX)
set(CMAKE_CXX_STANDARD 17)

option(BUILD_EXAMPLE "Build example" OFF)

if (CMAKE_GENERATOR MATCHES "Visual Studio")
set(LBFGSB_CMAKE_GENERATOR "Unix Makefiles")
else ()
set(LBFGSB_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
endif ()

set(HEADERS "include/${PROJECT_NAME}/lbfgsb.hpp")
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} Lbfgsb.3.0/include/lbfgsb/lbfgsb.h
Lbfgsb.3.0/blas.c
Lbfgsb.3.0/lbfgsb.c
Lbfgsb.3.0/linpack.c
Lbfgsb.3.0/s_cmp.c
Lbfgsb.3.0/s_copy.c
Lbfgsb.3.0/timer.c
)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

set(EMBED_CUSTOM_BLAS ON)
Expand All @@ -24,53 +27,7 @@ set(EMBED_CUSTOM_BLAS ON)
set(lbfgsb_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Lbfgsb.3.0")
set(lbfgsb_BINARY_DIR "${CMAKE_BINARY_DIR}/lbfgsb-build")
set(lbfgsb_INSTALL_DIR "${CMAKE_BINARY_DIR}/lbfgsb-installed")

# subbuild for lbfgsb
set(lbfgsb_VIRTUAL_PROJECT "${CMAKE_CURRENT_BINARY_DIR}/lbfgsb-virtual-project")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ExternalFortranProject.cmake.in"
"${lbfgsb_VIRTUAL_PROJECT}/CMakeLists.txt" @ONLY)


execute_process(
COMMAND ${CMAKE_COMMAND}
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}
-DFortran_LINK_FLAGS="${Fortran_LINK_FLAGS}"
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${lbfgsb_INSTALL_DIR}
-DEMBED_CUSTOM_BLAS=${EMBED_CUSTOM_BLAS}
.
RESULT_VARIABLE result
OUTPUT_VARIABLE capturedOutput
ERROR_VARIABLE capturedOutput
WORKING_DIRECTORY "${lbfgsb_VIRTUAL_PROJECT}"
)
STRING(REPLACE "\n" "\n-- " capturedOutput ${capturedOutput}) # show sub cmake with additional -- markers
if (result)
message("${capturedOutput}")
message(FATAL_ERROR "CMake step for lbfgsb-build failed: ${result}")
elseif (LBFGSB_SHOW_BUILD)
message(STATUS "${capturedOutput}")
endif ()
execute_process(
COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
OUTPUT_VARIABLE capturedOutput
ERROR_VARIABLE capturedOutput
WORKING_DIRECTORY "${lbfgsb_VIRTUAL_PROJECT}"
)
STRING(REPLACE "\n" "\n-- " capturedOutput ${capturedOutput}) # show sub cmake with additional -- markers
if (result)
message("${capturedOutput}")
message(FATAL_ERROR "Build step for lbfgsb-build failed: ${result}")
elseif (LBFGSB_SHOW_BUILD)
message(STATUS "${capturedOutput}")
endif ()
# End of subbuild for lbfgsb

set(lbfgsb_DIR "${lbfgsb_INSTALL_DIR}/lib/cmake/lbfgsb")
find_package(lbfgsb CONFIG REQUIRED)

target_link_libraries(${PROJECT_NAME} INTERFACE lbfgsb::lbfgsb)

target_include_directories(
${PROJECT_NAME} INTERFACE
Expand Down
1 change: 0 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
add_executable(example example.cpp strncmp_debug.cpp)
target_link_libraries(example PRIVATE ${PROJECT_NAME})
target_link_libraries(example PUBLIC lbfgsb::lbfgsb)
#target_compile_options(
# example PRIVATE
# -Wall
Expand Down

0 comments on commit fb52162

Please sign in to comment.