CMakeLists.txt 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. cmake_minimum_required(VERSION 3.3)
  2. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) # main (top) cmake dir
  3. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # project specific cmake dir
  4. # CMake useful variables
  5. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  6. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  7. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  8. # Set the name of your project here
  9. project("riscv")
  10. include(Common)
  11. conan_basic_setup()
  12. find_package(Boost COMPONENTS program_options system thread filesystem REQUIRED)
  13. # This sets the include directory for the reference project. This is the -I flag in gcc.
  14. include_directories(
  15. ${PROJECT_SOURCE_DIR}/incl
  16. ${SOFTFLOAT_INCLUDE_DIRS}
  17. ${LLVM_INCLUDE_DIRS}
  18. )
  19. include_directories(
  20. ${PROJECT_SOURCE_DIR}/incl
  21. ${PROJECT_SOURCE_DIR}/../external/elfio
  22. ${PROJECT_SOURCE_DIR}/../external/libGIS
  23. ${Boost_INCLUDE_DIRS}
  24. )
  25. # Mac needed variables (adapt for your needs - http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH)
  26. set(CMAKE_MACOSX_RPATH ON)
  27. set(CMAKE_SKIP_BUILD_RPATH FALSE)
  28. set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  29. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
  30. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  31. add_subdirectory(softfloat)
  32. # library files
  33. FILE(GLOB RiscVSCHeaders ${CMAKE_CURRENT_SOURCE_DIR}/incl/sysc/*.h ${CMAKE_CURRENT_SOURCE_DIR}/incl/sysc/*/*.h)
  34. set(LIB_HEADERS ${RiscVSCHeaders} )
  35. set(LIB_SOURCES
  36. src/iss/rv32gc.cpp
  37. src/iss/rv32imac.cpp
  38. src/iss/rv64i.cpp
  39. src/iss/rv64gc.cpp
  40. src/internal/fp_functions.cpp
  41. src/internal/vm_rv32gc.cpp
  42. src/internal/vm_rv32imac.cpp
  43. src/internal/vm_rv64i.cpp
  44. src/internal/vm_rv64gc.cpp
  45. src/plugin/instruction_count.cpp
  46. src/plugin/cycle_estimate.cpp)
  47. # Define two variables in order not to repeat ourselves.
  48. set(LIBRARY_NAME riscv)
  49. # Define the library
  50. add_library(${LIBRARY_NAME} ${LIB_SOURCES})
  51. SET(${LIBRARY_NAME} -Wl,-whole-archive -l${LIBRARY_NAME} -Wl,-no-whole-archive)
  52. target_link_libraries(${LIBRARY_NAME} softfloat)
  53. target_link_libraries(${LIBRARY_NAME} dbt-core)
  54. target_link_libraries(${LIBRARY_NAME} scc-util)
  55. set_target_properties(${LIBRARY_NAME} PROPERTIES
  56. VERSION ${VERSION} # ${VERSION} was defined in the main CMakeLists.
  57. FRAMEWORK FALSE
  58. PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
  59. )
  60. #set_property(TARGET ${LIBRARY_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
  61. if(SystemC_FOUND)
  62. set(SC_LIBRARY_NAME riscv_sc)
  63. add_library(${SC_LIBRARY_NAME} src/sysc/core_complex.cpp)
  64. add_definitions(-DWITH_SYSTEMC)
  65. include_directories(${SystemC_INCLUDE_DIRS})
  66. include_directories(${CCI_INCLUDE_DIRS})
  67. if(SCV_FOUND)
  68. add_definitions(-DWITH_SCV)
  69. include_directories(${SCV_INCLUDE_DIRS})
  70. endif()
  71. target_link_libraries(${SC_LIBRARY_NAME} ${LIBRARY_NAME})
  72. target_link_libraries(${SC_LIBRARY_NAME} dbt-core)
  73. target_link_libraries(${SC_LIBRARY_NAME} softfloat)
  74. target_link_libraries(${SC_LIBRARY_NAME} scc)
  75. target_link_libraries(${SC_LIBRARY_NAME} external)
  76. target_link_libraries(${SC_LIBRARY_NAME} ${llvm_libs})
  77. target_link_libraries(${SC_LIBRARY_NAME} ${Boost_LIBRARIES} )
  78. set_target_properties(${SC_LIBRARY_NAME} PROPERTIES
  79. VERSION ${VERSION} # ${VERSION} was defined in the main CMakeLists.
  80. FRAMEWORK FALSE
  81. PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
  82. )
  83. endif()
  84. project("riscv-sim")
  85. # This is a make target, so you can do a "make riscv-sc"
  86. set(APPLICATION_NAME riscv-sim)
  87. add_executable(${APPLICATION_NAME} src/main.cpp)
  88. # Links the target exe against the libraries
  89. target_link_libraries(${APPLICATION_NAME} ${LIBRARY_NAME})
  90. target_link_libraries(${APPLICATION_NAME} jsoncpp)
  91. target_link_libraries(${APPLICATION_NAME} dbt-core)
  92. target_link_libraries(${APPLICATION_NAME} external)
  93. target_link_libraries(${APPLICATION_NAME} ${llvm_libs})
  94. target_link_libraries(${APPLICATION_NAME} ${Boost_LIBRARIES} )
  95. if (Tcmalloc_FOUND)
  96. target_link_libraries(${APPLICATION_NAME} ${Tcmalloc_LIBRARIES})
  97. endif(Tcmalloc_FOUND)
  98. # Says how and where to install software
  99. # Targets:
  100. # * <prefix>/lib/<libraries>
  101. # * header location after install: <prefix>/include/<project>/*.h
  102. # * headers can be included by C++ code `#<project>/Bar.hpp>`
  103. install(TARGETS ${LIBRARY_NAME} ${APPLICATION_NAME}
  104. EXPORT ${PROJECT_NAME}Targets # for downstream dependencies
  105. ARCHIVE DESTINATION lib COMPONENT libs # static lib
  106. RUNTIME DESTINATION bin COMPONENT libs # binaries
  107. LIBRARY DESTINATION lib COMPONENT libs # shared lib
  108. FRAMEWORK DESTINATION bin COMPONENT libs # for mac
  109. PUBLIC_HEADER DESTINATION incl/${PROJECT_NAME} COMPONENT devel # headers for mac (note the different component -> different package)
  110. INCLUDES DESTINATION incl # headers
  111. )
  112. #
  113. # SYSTEM PACKAGING (RPM, TGZ, ...)
  114. # _____________________________________________________________________________
  115. #include(CPackConfig)
  116. #
  117. # CMAKE PACKAGING (for other CMake projects to use this one easily)
  118. # _____________________________________________________________________________
  119. #include(PackageConfigurator)