CMakeLists.txt 5.1KB

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