CMakeLists.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. cmake_minimum_required(VERSION 3.16)
  2. project(rpcdb C CXX)
  3. set(CXX_STANDARD 20)
  4. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  5. set(CMAKE_C_COMPILER gcc)
  6. set(CMAKE_CXX_COMPILER g++)
  7. add_compile_options(-O3)
  8. set(rpc_dir /usr/include/tirpc)
  9. set(client_dir ${CMAKE_SOURCE_DIR}/client)
  10. set(server_dir ${CMAKE_SOURCE_DIR}/server)
  11. set(status_dir ${CMAKE_SOURCE_DIR}/status_codes)
  12. set(client_subdirs
  13. ${client_dir}
  14. ${client_dir}/command
  15. ${client_dir}/input_controller
  16. ${client_dir}/request
  17. ${client_dir}/response
  18. ${client_dir}/rpc
  19. )
  20. set(server_subdirs
  21. ${server_dir}
  22. ${server_dir}/command
  23. ${server_dir}/request
  24. ${server_dir}/response
  25. )
  26. include_directories(${rpc_dir} ${status_dir})
  27. file(GLOB_RECURSE client_cpp_sources ${client_dir}/*.cpp ${client_dir}/*.c ${status_dir}/*.cpp)
  28. file(GLOB_RECURSE server_cpp_sources ${server_dir}/*.cpp ${server_dir}/*.c ${status_dir}/*.cpp)
  29. add_custom_target(rpc
  30. COMMAND cp ${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.x ${CMAKE_PROJECT_NAME}.x
  31. COMMAND rpcgen -C ${CMAKE_PROJECT_NAME}.x
  32. COMMAND cp ${CMAKE_PROJECT_NAME}.h ${client_dir}/
  33. COMMAND cp ${CMAKE_PROJECT_NAME}_xdr.c ${client_dir}/
  34. COMMAND mv ${CMAKE_PROJECT_NAME}_clnt.c ${client_dir}/
  35. COMMAND mv ${CMAKE_PROJECT_NAME}.h ${server_dir}/
  36. COMMAND mv ${CMAKE_PROJECT_NAME}_xdr.c ${server_dir}/
  37. COMMAND rm ${CMAKE_PROJECT_NAME}_svc.c
  38. )
  39. add_custom_command(TARGET rpc PRE_BUILD
  40. COMMAND cp compile_commands.json ../)
  41. add_executable(client ${client_cpp_sources})
  42. # add_dependencies(client rpc)
  43. target_link_libraries(client nsl tirpc)
  44. target_include_directories(client PUBLIC ${client_subdirs})
  45. add_executable(server ${server_cpp_sources})
  46. # add_dependencies(server rpc)
  47. target_link_libraries(server nsl tirpc)
  48. target_include_directories(server PUBLIC ${server_subdirs})