4 install (FILES nlopt.3 nlopt_minimize.3 nlopt_minimize_constrained.3 DESTINATION share/man/man3)
7 # generate nlopt.f from nlopt.h enums
8 if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f)
9 file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f "")
10 file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.h NLOPT_H_LINES REGEX " NLOPT_[A-Z0-9_]+")
12 foreach (NLOPT_H_LINE ${NLOPT_H_LINES})
13 if (NOT NLOPT_H_LINE MATCHES "NLOPT_NUM_")
14 string (REGEX REPLACE ".*NLOPT_([A-Z0-9_]+).*" "\\1" ENUM_STRING ${NLOPT_H_LINE})
15 string (REGEX REPLACE ".*NLOPT_[A-Z0-9_]+ = (-?[0-9]+).*" "\\1" ENUM_VAL ${NLOPT_H_LINE})
16 if (ENUM_VAL MATCHES "^-?[0-9]+$")
19 set (ENUM_LINE " integer NLOPT_${ENUM_STRING}\n parameter (NLOPT_${ENUM_STRING}=${i})\n")
20 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f "${ENUM_LINE}")
22 # https://public.kitware.com/Bug/print_bug_page.php?bug_id=8996
24 math (EXPR i "1 ${i}")
26 math (EXPR i "${i} + 1")
32 # generate nlopt.hpp from nlopt-in.hpp
33 if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp)
34 file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "")
35 file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-in.hpp NLOPT_HPP_LINES)
36 foreach (NLOPT_HPP_LINE ${NLOPT_HPP_LINES})
37 list(LENGTH NLOPT_HPP_LINE line_len)
38 # handling trailing backlashes in "file (STRINGS" is a little tricky
39 if (line_len VERSION_LESS 8)
40 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "${NLOPT_HPP_LINE}\n")
43 foreach(NLOPT_HPP_SUBLINE ${NLOPT_HPP_LINE})
44 # test is we need to add the eaten semicolon
45 if (NLOPT_HPP_SUBLINE MATCHES "\\)$" OR NLOPT_HPP_SUBLINE MATCHES "return")
51 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "${NLOPT_HPP_SUBLINE}")
53 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp ";")
55 list (FIND NLOPT_HPP_LINE "${NLOPT_HPP_SUBLINE}" index)
56 math (EXPR index "${index} + 1")
57 list (LENGTH NLOPT_HPP_LINE total)
58 if (NOT index STREQUAL total)
59 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " \\")
61 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "\n")
63 set (prev_inst ${new_inst})
66 if (NLOPT_HPP_LINE MATCHES "GEN_ENUMS_HERE")
67 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " enum algorithm {\n")
68 file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.h NLOPT_H_LINES REGEX " NLOPT_[A-Z0-9_]+")
69 foreach (NLOPT_H_LINE ${NLOPT_H_LINES})
70 string (REGEX REPLACE "NLOPT_" "" ENUM_LINE ${NLOPT_H_LINE})
71 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "${ENUM_LINE}\n")
72 if (NLOPT_H_LINE MATCHES "NLOPT_NUM_ALGORITHMS")
73 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " };\n enum result {\n")
74 elseif (NLOPT_H_LINE MATCHES "NLOPT_MAXTIME_REACHED")
75 file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " };\n")