Skip to content

Commit

Permalink
CMake: Generate header wrt NLOPT_FORTRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Jan 23, 2024
1 parent 2638518 commit 7218c80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(SO_PATCH 1)
list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

option (NLOPT_CXX "enable cxx routines" ON)
option (NLOPT_FORTRAN "enable fortran tests" OFF)
option (NLOPT_FORTRAN "enable fortran" OFF)
option (BUILD_SHARED_LIBS "Build NLopt as a shared library" ON)
option (NLOPT_PYTHON "build python bindings" ON)
option (NLOPT_OCTAVE "build octave bindings" ON)
Expand Down Expand Up @@ -183,18 +183,21 @@ install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION ${RELATIVE_INSTA
#==============================================================================

set (NLOPT_HEADERS
src/api/nlopt.h ${PROJECT_BINARY_DIR}/nlopt.hpp ${PROJECT_BINARY_DIR}/nlopt.f
src/api/nlopt.h ${PROJECT_BINARY_DIR}/nlopt.hpp
)

add_custom_command (OUTPUT nlopt.hpp
COMMAND ${CMAKE_COMMAND} -DAPI_SOURCE_DIR=${PROJECT_SOURCE_DIR}/src/api -P ${PROJECT_SOURCE_DIR}/cmake/generate-cpp.cmake
MAIN_DEPENDENCY src/api/nlopt-in.hpp)
add_custom_target (generate-cpp ALL DEPENDS nlopt.hpp)

add_custom_command (OUTPUT nlopt.f
COMMAND ${CMAKE_COMMAND} -DAPI_SOURCE_DIR=${PROJECT_SOURCE_DIR}/src/api -P ${PROJECT_SOURCE_DIR}/cmake/generate-fortran.cmake
MAIN_DEPENDENCY src/api/nlopt.h)
add_custom_target (generate-fortran ALL DEPENDS nlopt.f)
if (NLOPT_FORTRAN)
add_custom_command (OUTPUT nlopt.f
COMMAND ${CMAKE_COMMAND} -DAPI_SOURCE_DIR=${PROJECT_SOURCE_DIR}/src/api -P ${PROJECT_SOURCE_DIR}/cmake/generate-fortran.cmake
MAIN_DEPENDENCY src/api/nlopt.h)
add_custom_target (generate-fortran ALL DEPENDS nlopt.f)
list (APPEND NLOPT_HEADERS ${PROJECT_BINARY_DIR}/nlopt.f)
endif()

set (NLOPT_SOURCES
src/algs/direct/DIRect.c src/algs/direct/direct_wrap.c src/algs/direct/DIRserial.c src/algs/direct/DIRsubrout.c src/algs/direct/direct-internal.h src/algs/direct/direct.h
Expand Down
8 changes: 1 addition & 7 deletions cmake/generate-fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ foreach (NLOPT_H_LINE ${NLOPT_H_LINES})
endif ()
set (ENUM_LINE " integer NLOPT_${ENUM_STRING}\n parameter (NLOPT_${ENUM_STRING}=${i})\n")
file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f "${ENUM_LINE}")

# https://public.kitware.com/Bug/print_bug_page.php?bug_id=8996
if (i MATCHES "^-")
math (EXPR i "1 ${i}")
else ()
math (EXPR i "${i} + 1")
endif ()
math (EXPR i "${i} + 1")
endif ()
endforeach ()

0 comments on commit 7218c80

Please sign in to comment.