Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Dec 2nd, 2012  |  syntax: CMake  |  size: 4.95 KB  |  hits: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ########################################################################################################################
  2. # @file FindXilinx.cmake
  3. # @author Andrew D. Zonenberg
  4. # @brief Xilinx ISE toolchain CMake module
  5. ########################################################################################################################
  6.  
  7. ########################################################################################################################
  8. # Autodetect Xilinx paths (very hacky for now)
  9.  
  10. # Find /opt/Xilinx or similar
  11. find_file(XILINX_PARENT NAMES Xilinx PATHS /opt)
  12. if(XILINX_PARENT STREQUAL "XILINX_PARENT-NOTFOUND")
  13.         message(FATAL_ERROR "No Xilinx toolchain installation found")
  14. endif()
  15.  
  16. # Find /opt/Xilinx/VERSION
  17. # TODO: Figure out a better way of doing this
  18. find_file(XILINX NAMES 14.3 PATHS ${XILINX_PARENT})
  19. if(XILINX STREQUAL "XILINX-NOTFOUND")
  20.         message(FATAL_ERROR "No ISE 14.3 installation found")
  21. endif()
  22. message(STATUS "Found Xilinx toolchain... ${XILINX}")
  23.  
  24. # Set current OS architecture (TODO: autodetect)
  25. set(XILINX_ARCH lin64)
  26.  
  27. # Find fuse
  28. find_file(FUSE NAMES fuse PATHS "${XILINX}/ISE_DS/ISE/bin/${XILINX_ARCH}/")
  29. if(FUSE STREQUAL "FUSE-NOTFOUND")
  30.         message(FATAL_ERROR "No Xilinx fuse installation found")
  31. endif()
  32. message(STATUS "Found Xilinx fuse... ${FUSE}")
  33.  
  34. ########################################################################################################################
  35. # Argument parsing helper
  36.  
  37. macro(xilinx_parse_args _top_level _sources)
  38.         set(${_top_level} FALSE)
  39.         set(${_sources})
  40.         set(_found_sources FALSE)
  41.         set(_found_top_level FALSE)
  42.         foreach(arg ${ARGN})
  43.                 if(${arg} STREQUAL "TOP_LEVEL")
  44.                         set(_found_top_level TRUE)
  45.                 elseif(${arg} STREQUAL "SOURCES")
  46.                         set(_found_sources TRUE)
  47.                 elseif(${_found_sources})
  48.                         list(APPEND ${_sources} ${arg})
  49.                 elseif(${_found_top_level})
  50.                         if(${_top_level})
  51.                                 message(FATAL_ERROR "Multiple top-level files specified in xilinx_parse_args")
  52.                         else()
  53.                                 set(${_top_level} ${arg})                              
  54.                         endif()
  55.                 else()
  56.                         message(FATAL_ERROR "Unrecognized command ${arg} in xilinx_parse_args")
  57.                 endif()
  58.         endforeach()
  59. endmacro()
  60.  
  61. ########################################################################################################################
  62. # ISim executable generation
  63.  
  64. function(add_isim_executable OUTPUT_FILE )
  65.                
  66.         # Parse args
  67.         xilinx_parse_args(TOP_LEVEL SOURCES ${ARGN})
  68.        
  69.         # Get base name without extension of the top-level module
  70.         get_filename_component(TOPLEVEL_BASENAME ${TOP_LEVEL} NAME_WE )
  71.        
  72.         # Write the .prj file
  73.         set(PRJ_FILE "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE}.prj")
  74.         file(WRITE ${PRJ_FILE} "verilog work \"${TOP_LEVEL}\"\n")
  75.         foreach(f ${SOURCES})
  76.                 file(APPEND ${PRJ_FILE} "verilog work \"${f}\"\n")
  77.         endforeach()
  78.         file(APPEND ${PRJ_FILE} "verilog work \"${XILINX}/ISE_DS/ISE/verilog/src/glbl.v\"\n")
  79.        
  80.         # Main compile rule
  81.         # TODO: tweak this
  82.         add_custom_target(
  83.                 ${OUTPUT_FILE} ALL
  84.                 COMMAND ${FUSE} ${FUSE_FLAGS} -o ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE} -prj ${PRJ_FILE}
  85.                                 work.${TOPLEVEL_BASENAME} work.glbl > ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE}_build.log
  86.                                 2> ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE}_err.log
  87.                 DEPENDS ${SOURCES} ${TOP_LEVEL}
  88.                 COMMENT "Building ISim executable ${OUTPUT_FILE}..."
  89.         )
  90.        
  91.         # Write the tcl script
  92.         set(TCL_FILE "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE}.tcl")
  93.         file(WRITE ${TCL_FILE} "onerror {resume}\n")
  94.         file(APPEND ${TCL_FILE} "wave add /\n")
  95.         file(APPEND ${TCL_FILE} "run 1000 ns;\n")
  96.         file(APPEND ${TCL_FILE} "exit;\n")
  97.        
  98.         # Write the run-test wrapper script
  99.         set(TEST_WRAPPER "${CMAKE_CURRENT_BINARY_DIR}/run${OUTPUT_FILE}.sh")
  100.         file(WRITE ${TEST_WRAPPER} "#!/bin/bash\n")
  101.         file(APPEND ${TEST_WRAPPER} "cd ${CMAKE_CURRENT_BINARY_DIR}\n")
  102.         file(APPEND ${TEST_WRAPPER} "source ${XILINX}/ISE_DS/settings64.sh\n")
  103.         file(APPEND ${TEST_WRAPPER} "./${OUTPUT_FILE} -tclbatch ${TCL_FILE} -intstyle silent -vcdfile ${OUTPUT_FILE}.vcd -vcdunit ps || exit 1\n")
  104.         file(APPEND ${TEST_WRAPPER} "cat isim.log | grep -q FAIL\n")
  105.         file(APPEND ${TEST_WRAPPER} "if [ \"$?\" != \"1\" ]; then\n")
  106.         file(APPEND ${TEST_WRAPPER} "    exit 1;\n")
  107.         file(APPEND ${TEST_WRAPPER} "fi\n")
  108.         add_custom_command(TARGET ${OUTPUT_FILE} POST_BUILD COMMAND chmod +x ${TEST_WRAPPER})
  109.        
  110. endfunction()
  111.  
  112. ########################################################################################################################
  113. # Test generation
  114. #
  115. # Usage:
  116. # add_isim_test(NandGate
  117. #       TOP_LEVEL
  118. #               ${CMAKE_CURRENT_SOURCE_DIR}/testNandGate.v
  119. #       SOURCES
  120. #               ${CMAKE_SOURCE_DIR}/hdl/NandGate.v
  121. #       )
  122.  
  123. function(add_isim_test TEST_NAME)
  124.  
  125.         # Parse args
  126.         xilinx_parse_args(TOP_LEVEL SOURCES ${ARGN})
  127.  
  128.         # Add the sim executable
  129.         add_isim_executable(test${TEST_NAME}
  130.                 TOP_LEVEL
  131.                         ${TOP_LEVEL}
  132.                 SOURCES
  133.                         ${SOURCES}
  134.                 )
  135.  
  136.         add_test(${TEST_NAME}
  137.                 "${CMAKE_CURRENT_BINARY_DIR}/runtest${TEST_NAME}.sh")
  138.         set_property(TEST ${TEST_NAME} APPEND PROPERTY DEPENDS test${TEST_NAME})
  139.  
  140.  
  141. endfunction()