Skip to content

Commit

Permalink
CMake: operators subdir is handled by symbolic subdir (to avoid order…
Browse files Browse the repository at this point in the history
…-dependency) #368
  • Loading branch information
cyrilbouvier committed Apr 3, 2020
1 parent a6d4977 commit fd820d1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ target_include_directories (ibex PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINAR
# source files from interval_lib and lp_lib wrappers
target_sources (ibex PRIVATE ${IBEX_SRC})

# Caveat: operators must be done before symbolic
# Note: operators subdir is handled by CMakeLists.txt from symbolic
foreach (subdir arithmetic bisector combinatorial contractor data function
numeric operators parser predicate set solver strategy symbolic
system tools)
numeric parser predicate set solver strategy symbolic system
tools)
add_subdirectory (${subdir})
endforeach()

Expand Down Expand Up @@ -73,7 +73,9 @@ target_include_directories (ibex PUBLIC
get_target_property (IBEX_SRC ibex SOURCES)
list_filter (IBEX_HDR "\\.(h|hpp)$" ${IBEX_SRC})
list_filter (IBEX_OPS_HDR "operators/.*\\.h" ${IBEX_SRC})
list (REMOVE_ITEM IBEX_HDR ${IBEX_OPS_HDR}) # remove operators headers
if (IBEX_OPS_HDR)
list (REMOVE_ITEM IBEX_HDR ${IBEX_OPS_HDR}) # remove operators headers
endif ()

# Generate ibex.h
set (IBEX_MAIN_HEADER ${CMAKE_CURRENT_BINARY_DIR}/ibex.h)
Expand Down
53 changes: 0 additions & 53 deletions src/operators/CMakeLists.txt

This file was deleted.

51 changes: 50 additions & 1 deletion src/symbolic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
# see arithmetic/CMakeLists.txt for comments

################################################################################
# Deal with files in src/operators and set OPERATORS_* variables
################################################################################
set (OPERATORS_LIST atanhc atanhccc crossproduct sinc trace)

foreach (op ${OPERATORS_LIST})
set (hdr "ibex_${op}.h")
set (hdrfile "${CMAKE_CURRENT_SOURCE_DIR}/../operators/ibex_${op}.h")
#set (cpp "ibex_${op}.cpp")
set (cppfile "${CMAKE_CURRENT_SOURCE_DIR}/../operators/ibex_${op}.cpp")

# Handles includes
string (APPEND OPERATORS_INCLUDES "#include \"${hdr}\"\n")
target_sources (ibex PRIVATE ${hdrfile} ${cppfile})

# Parse header
file (STRINGS ${hdrfile} line REGEX "^class [BU]i?naryOperator<" LIMIT_COUNT 1)
if (NOT line)
message (FATAL_ERROR "Error while parsing ${hdr}: no class line")
endif ()
string(REGEX MATCH " (.*)Operator<([^,]*),([^,]*),([^,]*),?(.*)>" _ ${line})

if (CMAKE_MATCH_1 STREQUAL "Unary")
set (_t "${CMAKE_MATCH_2},${CMAKE_MATCH_3},${CMAKE_MATCH_4}")
string (APPEND OPERATORS_MACRO_UNARY "ADD_UNARY_OPERATOR(${_t});\n")
set (inline_pre "inline ${CMAKE_MATCH_4} ")
set (inline_post "(const ${CMAKE_MATCH_3}& x) { return UnaryOperator<${_t}>::fwd(x); }\n")
else () # Binary
set (_t "${CMAKE_MATCH_2},${CMAKE_MATCH_3},${CMAKE_MATCH_4},${CMAKE_MATCH_5}")
string (APPEND OPERATORS_MACRO_BINARY "ADD_BINARY_OPERATOR(${_t});\n")
set (inline_pre "inline ${CMAKE_MATCH_5} ")
set (inline_post "(const ${CMAKE_MATCH_3}& x1, const ${CMAKE_MATCH_4}& x2) { return BinaryOperator<${_t}>::fwd(x1,x2); }\n")
endif ()
set (OP_VARNAME ${CMAKE_MATCH_2})

# Parse source file
file (STRINGS ${cppfile} line REGEX "^extern const char .*;$" LIMIT_COUNT 1)
if (NOT line)
message (FATAL_ERROR "Error while parsing ${cpp}: no const char line")
endif ()
string (REGEX MATCH " const char ${OP_VARNAME}\\[\\] = \"(.*)\";$" _ ${line})
string (APPEND OPERATORS_FCT_DEF "${inline_pre}${CMAKE_MATCH_1}${inline_post}")
endforeach()

################################################################################
# configure files with OPERATORS_* variables
################################################################################
configure_file (ibex_ExprOperators.cpp.in ibex_ExprOperators.cpp)
configure_file (ibex_ExprOperators.h.in ibex_ExprOperators.h)

################################################################################
target_sources (ibex PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/ibex_CmpOp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ibex_CmpOp.h
Expand Down Expand Up @@ -39,4 +87,5 @@ target_sources (ibex PRIVATE

target_include_directories (ibex PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../operators>")

0 comments on commit fd820d1

Please sign in to comment.