##*************************************************************************##
##  CUBE        http://www.scalasca.org/                                   ##
##*************************************************************************##
##  Copyright (c) 2023-2024                                                ##
##  Forschungszentrum Juelich GmbH, Juelich Supercomputing Centre          ##
##                                                                         ##
##  This software may be modified and distributed under the terms of       ##
##  a BSD-style license.  See the COPYING file in the package base         ##
##  directory for details.                                                 ##
##*************************************************************************##


# === cube_remap2 ===========================================================

set(CUBELIB_HEADERS_PUBLIC
     ./remap2_calls.h
     ./ReMapDriver.h
     ./ReMapParseContext.h
     ./ReMapParser.hh
     ./ReMapScanner.h
)

# === use flex/bison to regenerate sources ==================================
option(CUBELIB_REMAPPER_ENABLE_REGENERATION "Regenerate Remapper sources" OFF)
if (CUBELIB_REMAPPER_ENABLE_REGENERATION)
    find_package(FLEX REQUIRED)
    #todo FLEX_TARGET(Scanner ReMapScanner.ll ${CMAKE_CURRENT_BINARY_DIR}/ReMapScanner.cc COMPILE_FLAGS "-f -8")

    find_package(BISON REQUIRED)
    #todo BISON_TARGET(Parser ReMapParser.yy ${CMAKE_CURRENT_BINARY_DIR}/ReMapParser.cc COMPILE_FLAGS "-Wno-yacc -d")
endif()

add_executable(cube_remap2
   ./cube_remap2.cpp
   ./FlexLexer.h
   ./ReMapDriver.cpp
   ./ReMapDriver.h
   ./ReMapParseContext.h
   ./ReMapParser.cc
   ./ReMapParser.hh
   ./ReMapScanner.cc
   ./ReMapScanner.h
   ./location.hh
   ./position.hh
   ./stack.hh
   ./remap2_calls.h
   ./remap2_calls.cpp
)
target_link_libraries(cube_remap2 PRIVATE
    cube-base utils libcube_library_tools
)

# === install ===============================================================
install(TARGETS cube_remap2
     DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(FILES ${CUBELIB_HEADERS_PUBLIC}
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cubelib
)
