From 0d7d1a2b63b14fb3523abef5d11ec37474c08cf7 Mon Sep 17 00:00:00 2001 From: mpilman Date: Sat, 9 Feb 2019 14:33:36 -0800 Subject: [PATCH] added IDE support for cmake --- CMakeLists.txt | 2 ++ README.md | 23 ++++++++++++++++ cmake/ConfigureCompiler.cmake | 1 - cmake/FlowCommands.cmake | 50 ++++++++++++++++++++++------------- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32d92bed24..32259daf13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ endif() set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) +set(OPEN_FOR_IDE OFF CACHE BOOL "Open this in an IDE (won't compile/link)") + ################################################################################ # Packages used for bindings ################################################################################ diff --git a/README.md b/README.md index 7153ef8add..7a65543b1b 100755 --- a/README.md +++ b/README.md @@ -125,6 +125,29 @@ directory. This can than be used for tools like code-completion and code navigation in flow. It is not yet perfect (it will show a few errors) but we are constantly working on improving the developement experience. +### Using IDEs + +CMake has built in support for a number of popular IDEs. However, because flow +files are precompiled with the actor compiler, an IDE will not be very useful as +a user will only be presented with the generated code - which is not what she +wants to edit and get IDE features for. + +The good news is, that it is possible to generate project files for edititing +flow with a supported IDE. There is a cmake option called `OPEN_FOR_IDE` which +will generate a project which can be opened in an IDE for editing. You won't be +able to build this project, but you will be able to edit the files and get most +edit and navigation features your IDE supports. + +For example, if you want to use XCode to make changes to FoundationDB you can +create a XCode-project with the following command: + +``` +cmake -G Xcode -DOPEN_FOR_IDE=ON +``` + +You should create a second build-directory which you will use for building +(probably with make or ninja) and debugging. + ### Linux There are no special requirements for Linux. However, we are currently working diff --git a/cmake/ConfigureCompiler.cmake b/cmake/ConfigureCompiler.cmake index 1d29e2df7a..3c475e1521 100644 --- a/cmake/ConfigureCompiler.cmake +++ b/cmake/ConfigureCompiler.cmake @@ -4,7 +4,6 @@ set(USE_VALGRIND OFF CACHE BOOL "Compile for valgrind usage") set(USE_GOLD_LINKER OFF CACHE BOOL "Use gold linker") set(ALLOC_INSTRUMENTATION OFF CACHE BOOL "Instrument alloc") set(WITH_UNDODB OFF CACHE BOOL "Use rr or undodb") -set(OPEN_FOR_IDE OFF CACHE BOOL "Open this in an IDE (won't compile/link)") set(FDB_RELEASE OFF CACHE BOOL "This is a building of a final release") add_compile_options(-DCMAKE_BUILD) diff --git a/cmake/FlowCommands.cmake b/cmake/FlowCommands.cmake index f05431ba5f..ecdbdb6d08 100644 --- a/cmake/FlowCommands.cmake +++ b/cmake/FlowCommands.cmake @@ -11,7 +11,7 @@ generated. This property is set through the add_flow_target function.") function(generate_coverage_xml) if(NOT (${ARGC} EQUAL "1")) - message(ERROR "generate_coverage_xml expects one argument") + message(FATAL_ERROR "generate_coverage_xml expects one argument") endif() set(target_name ${ARGV0}) get_target_property(sources ${target_name} SOURCE_FILES) @@ -75,12 +75,31 @@ function(add_flow_target) set(multiValueArgs SRCS COVERAGE_FILTER_OUT DISABLE_ACTOR_WITHOUT_WAIT_WARNING) cmake_parse_arguments(AFT "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") if(NOT AFT_NAME) - message(ERROR "add_flow_target requires option NAME") + message(FATAL_ERROR "add_flow_target requires option NAME") endif() if(NOT AFT_SRCS) - message(ERROR "No sources provided") + message(FATAL_ERROR "No sources provided") endif() - foreach(src IN LISTS AFT_SRCS AFT_DISABLE_ACTOR_WITHOUT_WAIT_WARNING) + if(OPEN_FOR_IDE) + set(sources ${AFT_SRCS} ${AFT_DISABLE_ACTOR_WRITHOUT_WAIT_WARNING}) + if(AFT_EXECUTABLE) + set(target_type exec) + add_executable(${AFT_NAME} ${sources}) + endif() + if(AFT_STATIC_LIBRARY) + if(target_type) + message(FATAL_ERROR "add_flow_target can only be of one type") + endif() + add_library(${AFT_NAME} STATIC ${sources}) + endif() + if(AFT_DYNAMIC_LIBRARY) + if(target_type) + message(FATAL_ERROR "add_flow_target can only be of one type") + endif() + add_library(${AFT_NAME} DYNAMIC ${sources}) + endif() + else() + foreach(src IN LISTS AFT_SRCS AFT_DISABLE_ACTOR_WITHOUT_WAIT_WARNING) if(${src} MATCHES ".*\\.actor\\.(h|cpp)") list(APPEND actors ${src}) if(${src} MATCHES ".*\\.h") @@ -108,8 +127,8 @@ function(add_flow_target) DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${src}" actorcompiler COMMENT "Compile actor: ${src}") endif() - else() - list(APPEND sources ${src}) + else() + list(APPEND sources ${src}) endif() endforeach() if(AFT_EXECUTABLE) @@ -128,18 +147,13 @@ function(add_flow_target) endif() add_library(${AFT_NAME} DYNAMIC ${sources}) endif() - if(AFT_OBJECT_LIBRARY) - if(target_type) - message(FATAL_ERROR "add_flow_target can only be of one type") - endif() - add_library(${AFT_NAME} OBJECT ${sources}) + + set_property(TARGET ${AFT_NAME} PROPERTY SOURCE_FILES ${AFT_SRCS}) + set_property(TARGET ${AFT_NAME} PROPERTY COVERAGE_FILTERS ${AFT_SRCS}) + + add_custom_target(${AFT_NAME}_actors DEPENDS ${generated_files}) + add_dependencies(${AFT_NAME} ${AFT_NAME}_actors) + generate_coverage_xml(${AFT_NAME}) endif() - - set_property(TARGET ${AFT_NAME} PROPERTY SOURCE_FILES ${AFT_SRCS}) - set_property(TARGET ${AFT_NAME} PROPERTY COVERAGE_FILTERS ${AFT_SRCS}) - - add_custom_target(${AFT_NAME}_actors DEPENDS ${generated_files}) - add_dependencies(${AFT_NAME} ${AFT_NAME}_actors) - generate_coverage_xml(${AFT_NAME}) target_include_directories(${AFT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) endfunction()