You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.6 KiB

9 months ago
5 months ago
5 months ago
  1. cmake_minimum_required(VERSION 3.12)
  2. project("riscv" VERSION 1.0.0)
  3. include(GNUInstallDirs)
  4. conan_basic_setup()
  5. find_package(Boost COMPONENTS program_options system thread filesystem REQUIRED)
  6. if(WITH_LLVM)
  7. if(DEFINED ENV{LLVM_HOME})
  8. find_path (LLVM_DIR LLVM-Config.cmake $ENV{LLVM_HOME}/lib/cmake/llvm)
  9. endif(DEFINED ENV{LLVM_HOME})
  10. find_package(LLVM REQUIRED CONFIG)
  11. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  12. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  13. llvm_map_components_to_libnames(llvm_libs support core mcjit x86codegen x86asmparser)
  14. endif()
  15. #Mac needed variables (adapt for your needs - http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH)
  16. #set(CMAKE_MACOSX_RPATH ON)
  17. #set(CMAKE_SKIP_BUILD_RPATH FALSE)
  18. #set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  19. #set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
  20. #set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  21. add_subdirectory(softfloat)
  22. # library files
  23. FILE(GLOB RiscVSCHeaders ${CMAKE_CURRENT_SOURCE_DIR}/incl/sysc/*.h ${CMAKE_CURRENT_SOURCE_DIR}/incl/sysc/*/*.h)
  24. set(LIB_HEADERS ${RiscVSCHeaders} )
  25. set(LIB_SOURCES
  26. src/iss/rv32gc.cpp
  27. src/iss/rv32imac.cpp
  28. src/iss/rv64i.cpp
  29. src/iss/rv64gc.cpp
  30. src/iss/mnrv32.cpp
  31. src/vm/fp_functions.cpp
  32. src/vm/tcc/vm_mnrv32.cpp
  33. src/vm/tcc/vm_rv32gc.cpp
  34. src/vm/tcc/vm_rv32imac.cpp
  35. src/vm/tcc/vm_rv64i.cpp
  36. src/vm/tcc/vm_rv64gc.cpp
  37. src/vm/interp/vm_mnrv32.cpp
  38. src/vm/interp/vm_rv32gc.cpp
  39. src/vm/interp/vm_rv32imac.cpp
  40. src/vm/interp/vm_rv64i.cpp
  41. src/vm/interp/vm_rv64gc.cpp
  42. src/plugin/instruction_count.cpp
  43. src/plugin/cycle_estimate.cpp
  44. )
  45. if(WITH_LLVM)
  46. set(LIB_SOURCES ${LIB_SOURCES}
  47. src/vm/llvm/fp_impl.cpp
  48. src/vm/llvm/vm_mnrv32.cpp
  49. src/vm/llvm/vm_rv32gc.cpp
  50. src/vm/llvm/vm_rv32imac.cpp
  51. src/vm/llvm/vm_rv64i.cpp
  52. src/vm/llvm/vm_rv64gc.cpp
  53. )
  54. endif()
  55. # Define the library
  56. add_library(riscv SHARED ${LIB_SOURCES})
  57. target_compile_options(riscv PRIVATE -Wno-shift-count-overflow)
  58. target_include_directories(riscv PUBLIC incl ../external/elfio)
  59. target_link_libraries(riscv PUBLIC softfloat scc-util)
  60. target_link_libraries(riscv PUBLIC -Wl,--whole-archive dbt-core -Wl,--no-whole-archive)
  61. set_target_properties(riscv PROPERTIES
  62. VERSION ${PROJECT_VERSION}
  63. FRAMEWORK FALSE
  64. PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
  65. )
  66. if(SystemC_FOUND)
  67. add_library(riscv_sc src/sysc/core_complex.cpp)
  68. target_compile_definitions(riscv_sc PUBLIC WITH_SYSTEMC)
  69. target_include_directories(riscv_sc PUBLIC ../incl ${SystemC_INCLUDE_DIRS} ${CCI_INCLUDE_DIRS})
  70. if(SCV_FOUND)
  71. target_compile_definitions(riscv_sc PUBLIC WITH_SCV)
  72. target_include_directories(riscv_sc PUBLIC ${SCV_INCLUDE_DIRS})
  73. endif()
  74. target_link_libraries(riscv_sc PUBLIC riscv scc )
  75. if(WITH_LLVM)
  76. target_link_libraries(riscv_sc PUBLIC ${llvm_libs})
  77. endif()
  78. target_link_libraries(riscv_sc PUBLIC ${Boost_LIBRARIES} )
  79. set_target_properties(riscv_sc PROPERTIES
  80. VERSION ${PROJECT_VERSION}
  81. FRAMEWORK FALSE
  82. PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
  83. )
  84. endif()
  85. project("riscv-sim")
  86. add_executable(riscv-sim src/main.cpp)
  87. # This sets the include directory for the reference project. This is the -I flag in gcc.
  88. target_include_directories(riscv-sim PRIVATE ../external/libGIS)
  89. if(WITH_LLVM)
  90. target_compile_definitions(riscv-sim PRIVATE WITH_LLVM)
  91. target_link_libraries(riscv-sim PUBLIC ${llvm_libs})
  92. endif()
  93. # Links the target exe against the libraries
  94. target_link_libraries(riscv-sim riscv)
  95. target_link_libraries(riscv-sim jsoncpp)
  96. target_link_libraries(riscv-sim external)
  97. target_link_libraries(riscv-sim ${Boost_LIBRARIES} )
  98. if (Tcmalloc_FOUND)
  99. target_link_libraries(riscv-sim ${Tcmalloc_LIBRARIES})
  100. endif(Tcmalloc_FOUND)
  101. install(TARGETS riscv riscv-sim
  102. EXPORT ${PROJECT_NAME}Targets # for downstream dependencies
  103. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # static lib
  104. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # binaries
  105. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # shared lib
  106. FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # for mac
  107. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} COMPONENT devel # headers for mac (note the different component -> different package)
  108. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # headers
  109. )
  110. #
  111. # SYSTEM PACKAGING (RPM, TGZ, ...)
  112. # _____________________________________________________________________________
  113. #include(CPackConfig)
  114. #
  115. # CMAKE PACKAGING (for other CMake projects to use this one easily)
  116. # _____________________________________________________________________________
  117. #include(PackageConfigurator)