with_warnings()

include_directories( ${DIVINE_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} )
add_definitions( ${MPI_COMPILE_FLAGS} ${LLVM_COMPILE_FLAGS} )

set( COMBINE_M4_H "${CMAKE_CURRENT_BINARY_DIR}/combine.m4.h" )
set( COMBINE_M4 "${CMAKE_CURRENT_SOURCE_DIR}/combine.m4" )

add_executable( divine divine.cpp compile.cpp combine.cpp ${COMBINE_M4_H}
                $<TARGET_OBJECTS:libdivine-instances> )

target_link_libraries( divine libdivine wibble )
if( MURPHI )
    target_link_libraries( divine murphi )
endif()

if( NOT WIN32 )
  target_link_libraries( divine pthread )
endif( NOT WIN32 )

if( HOARD )
  target_link_libraries( divine hoard )
endif( HOARD )

if( TBBMALLOC )
  target_link_libraries( divine tbbmalloc )
endif()

set( llvmpaths "${CMAKE_CURRENT_BINARY_DIR}/llvmpaths.h" )
file( WRITE ${llvmpaths} "static const char *_cmd_clang= \"${CMD_CLANG}\";\n" )
file( APPEND ${llvmpaths} "static const char *_cmd_gold= \"${CMD_GOLD}\";\n" )
file( APPEND ${llvmpaths} "static const char *_cmd_ar= \"${CMD_AR}\";\n" )
file( APPEND ${llvmpaths} "static const char *_cmd_llvmgold= \"${CMD_LLVMGOLD}\";\n" )

set_source_files_properties( compile.h PROPERTIES OBJECT_DEPENDS ${llvmpaths} )

set( MAKE_STRING_CONST "${CMAKE_CURRENT_SOURCE_DIR}/make-string-const.pl" )

# target_link_libraries( divine lpsolve )
if( NOT WIN32 )
    target_link_libraries( divine rt )
endif()

if( LTL2DSTAR )
  target_link_libraries( divine ltl2dstar )
endif( LTL2DSTAR )

if( WIN32 )
  set( INSTALL_BIN_DEST ./ )
else( WIN32 )
  set( INSTALL_BIN_DEST bin )
endif( WIN32 )

install( TARGETS divine
         DESTINATION ${INSTALL_BIN_DEST} COMPONENT console_tools )

add_custom_command(
  OUTPUT ${COMBINE_M4_H}
  DEPENDS ${COMBINE_M4} ${MAKE_STRING_CONST}
  COMMAND ${PERL_EXECUTABLE} ${MAKE_STRING_CONST} "const char *combine_m4 = " ${COMBINE_M4} > ${COMBINE_M4_H} )

