From 75f692b9317b42bc3237e940228cf23d996dea35 Mon Sep 17 00:00:00 2001 From: mpilman Date: Fri, 8 Feb 2019 16:51:13 -0800 Subject: [PATCH] simplify actorcompiler and target to compile coveragetool --- CMakeLists.txt | 11 ++-- bindings/java/CMakeLists.txt | 3 +- cmake/CompileActorCompiler.cmake | 21 ------ cmake/CompileCoverageTool.cmake | 25 +++++++ cmake/EnableCsharp.cmake | 27 ++++++++ cmake/FlowCommands.cmake | 108 ++++++++++++++++++------------- fdbbackup/CMakeLists.txt | 4 +- fdbcli/CMakeLists.txt | 4 +- fdbclient/CMakeLists.txt | 4 +- fdbrpc/CMakeLists.txt | 7 +- fdbserver/CMakeLists.txt | 4 +- flow/CMakeLists.txt | 4 +- 12 files changed, 130 insertions(+), 92 deletions(-) create mode 100644 cmake/CompileCoverageTool.cmake create mode 100644 cmake/EnableCsharp.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 56e1775d42..32d92bed24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,12 +23,6 @@ project(foundationdb HOMEPAGE_URL "http://www.foundationdb.org/" LANGUAGES ASM C CXX) -if(WIN32) - # C# is currently only supported on Windows. - # On other platforms we find mono manually - enable_language(CSharp) -endif() - set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${PROJECT_SOURCE_DIR}/cmake") message (STATUS "${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}") if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") @@ -122,10 +116,15 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/versions.h.cmake ${CMAKE_CU # Flow ################################################################################ +# Flow and other tools are written in C# - so we need that dependency +include(EnableCSharp) + # First thing we need is the actor compiler - and to compile and run the # actor compiler, we need mono include(CompileActorCompiler) +include(CompileCoverageTool) + # with the actor compiler, we can now make the flow commands available include(FlowCommands) diff --git a/bindings/java/CMakeLists.txt b/bindings/java/CMakeLists.txt index 47391874b0..75191cc670 100644 --- a/bindings/java/CMakeLists.txt +++ b/bindings/java/CMakeLists.txt @@ -148,9 +148,10 @@ if(BUILD_FAT_JAR) add_custom_command(OUTPUT ${unpack_dir}/META-INF/MANIFEST.MF COMMAND ${Java_JAR_EXECUTABLE} xf ${jar_path} WORKING_DIRECTORY ${unpack_dir} + DEPENDS "${jar_path}" COMMENT "Unpack jar-file") add_custom_target(unpack_jar DEPENDS ${unpack_dir}/META-INF/MANIFEST.MF) - add_dependencies(unpack_jar fdb_java) + add_dependencies(unpack_jar fdb-java) add_custom_command(OUTPUT ${unpack_dir}/LICENSE COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE ${unpack_dir} COMMENT "copy license") diff --git a/cmake/CompileActorCompiler.cmake b/cmake/CompileActorCompiler.cmake index 4c39dc7b8e..2f737b6179 100644 --- a/cmake/CompileActorCompiler.cmake +++ b/cmake/CompileActorCompiler.cmake @@ -16,27 +16,6 @@ if(WIN32) "System.Data" "System.Xml") else() - find_program(MONO_EXECUTABLE mono) - find_program(MCS_EXECUTABLE dmcs) - - if (NOT MCS_EXECUTABLE) - find_program(MCS_EXECUTABLE mcs) - endif() - - set(MONO_FOUND FALSE CACHE INTERNAL "") - - if (NOT MCS_EXECUTABLE) - find_program(MCS_EXECUTABLE mcs) - endif() - - if (MONO_EXECUTABLE AND MCS_EXECUTABLE) - set(MONO_FOUND True CACHE INTERNAL "") - endif() - - if (NOT MONO_FOUND) - message(FATAL_ERROR "Could not find mono") - endif() - set(ACTOR_COMPILER_REFERENCES "-r:System,System.Core,System.Xml.Linq,System.Data.DataSetExtensions,Microsoft.CSharp,System.Data,System.Xml") diff --git a/cmake/CompileCoverageTool.cmake b/cmake/CompileCoverageTool.cmake new file mode 100644 index 0000000000..f7bfddc438 --- /dev/null +++ b/cmake/CompileCoverageTool.cmake @@ -0,0 +1,25 @@ +set(COVERAGETOOL_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/flow/coveragetool/Program.cs + ${CMAKE_CURRENT_SOURCE_DIR}/flow/coveragetool/Properties/AssemblyInfo.cs) +if(WIN32) + add_executable(coveragetool ${COVERAGETOOL_SRCS}) + target_compile_options(coveragetool PRIVATE "/langversion:6") + set_property(TARGET coveragetool PROPERTY VS_DOTNET_REFERENCES + "System" + "ystem.Core" + "System.Xml.Linq" + "ystem.Data.DataSetExtensions" + "Microsoft.CSharp" + "ystem.Data" + "System.Xml") +else() + set(COVERAGETOOL_COMPILER_REFERENCES + "-r:System,System.Core,System.Xml.Linq,System.Data.DataSetExtensions,Microsoft.CSharp,System.Data,System.Xml") + + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/coveragetool.exe + COMMAND ${MCS_EXECUTABLE} ARGS ${COVERAGETOOL_COMPILER_REFERENCES} ${COVERAGETOOL_SRCS} "-target:exe" "-out:coveragetool.exe" + DEPENDS ${COVERAGETOOL_SRCS} + COMMENT "Compile coveragetool" VERBATIM) + add_custom_target(coveragetool DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/coveragetool.exe) + set(coveragetool_exe "${CMAKE_CURRENT_BINARY_DIR}/coveragetool.exe") +endif() diff --git a/cmake/EnableCsharp.cmake b/cmake/EnableCsharp.cmake new file mode 100644 index 0000000000..89a38bab1a --- /dev/null +++ b/cmake/EnableCsharp.cmake @@ -0,0 +1,27 @@ +if(WIN32) + # C# is currently only supported on Windows. + # On other platforms we find mono manually + enable_language(CSharp) +else() + # for other platforms we currently use mono + find_program(MONO_EXECUTABLE mono) + find_program(MCS_EXECUTABLE dmcs) + + if (NOT MCS_EXECUTABLE) + find_program(MCS_EXECUTABLE mcs) + endif() + + set(MONO_FOUND FALSE CACHE INTERNAL "") + + if (NOT MCS_EXECUTABLE) + find_program(MCS_EXECUTABLE mcs) + endif() + + if (MONO_EXECUTABLE AND MCS_EXECUTABLE) + set(MONO_FOUND True CACHE INTERNAL "") + endif() + + if (NOT MONO_FOUND) + message(FATAL_ERROR "Could not find mono") + endif() +endif() diff --git a/cmake/FlowCommands.cmake b/cmake/FlowCommands.cmake index 4eb4c4735d..61a54d18e6 100644 --- a/cmake/FlowCommands.cmake +++ b/cmake/FlowCommands.cmake @@ -1,53 +1,71 @@ -macro(actor_set varname srcs) - set(${varname}) - foreach(src ${srcs}) - set(tmp "${src}") +function(add_flow_target) + set(options EXECUTABLE STATIC_LIBRARY + DYNAMIC_LIBRARY) + set(oneValueArgs NAME) + set(multiValueArgs SRCS 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") + endif() + if(NOT AFT_SRCS) + message(ERROR "No sources provided") + endif() + 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") - continue() - elseif(${src} MATCHES ".*\\.actor\\.cpp") - string(REPLACE ".actor.cpp" ".actor.g.cpp" tmp ${src}) - set(tmp "${CMAKE_CURRENT_BINARY_DIR}/${tmp}") - endif() - set(${varname} "${${varname}};${tmp}") - endforeach() -endmacro() - -set(ACTOR_TARGET_COUNTER "0") -macro(actor_compile target srcs) - set(options DISABLE_ACTOR_WITHOUT_WAIT_WARNING) - set(oneValueArg) - set(multiValueArgs) - cmake_parse_arguments(ACTOR_COMPILE "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") - set(_tmp_out "") - foreach(src ${srcs}) - set(tmp "") - if(${src} MATCHES ".*\\.actor\\.h") - string(REPLACE ".actor.h" ".actor.g.h" tmp ${src}) - elseif(${src} MATCHES ".*\\.actor\\.cpp") - string(REPLACE ".actor.cpp" ".actor.g.cpp" tmp ${src}) - endif() - set(actor_compiler_flags "") - if(ACTOR_COMPILE_DISABLE_ACTOR_WITHOUT_WAIT_WARNING) - set(actor_compiler_flags "--disable-actor-without-wait-warning") - endif() - if(tmp) + string(REPLACE ".actor.h" ".actor.g.h" generated ${src}) + else() + string(REPLACE ".actor.cpp" ".actor.g.cpp" generated ${src}) + endif() + set(actor_compiler_flags "") + foreach(s IN LISTS AFT_DISABLE_ACTOR_WITHOUT_WAIT_WARNING) + if("${s}" STREQUAL "${src}") + set(actor_compiler_flags "--disable-actor-without-wait-warning") + break() + endif() + endforeach() + list(APPEND sources ${generated}) + list(APPEND generated_files ${CMAKE_CURRENT_BINARY_DIR}/${generated}) if(WIN32) - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${tmp}" - COMMAND $ "${CMAKE_CURRENT_SOURCE_DIR}/${src}" "${CMAKE_CURRENT_BINARY_DIR}/${tmp}" ${actor_compiler_flags} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${src}" actorcompiler ${actor_exe} + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${generated}" + COMMAND $ "${CMAKE_CURRENT_SOURCE_DIR}/${src}" "${CMAKE_CURRENT_BINARY_DIR}/${generated}" ${actor_compiler_flags} ${actor_compiler_flags} + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${src}" actorcompiler COMMENT "Compile actor: ${src}") else() - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${tmp}" - COMMAND ${MONO_EXECUTABLE} ${actor_exe} "${CMAKE_CURRENT_SOURCE_DIR}/${src}" "${CMAKE_CURRENT_BINARY_DIR}/${tmp}" ${actor_compiler_flags} > /dev/null - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${src}" actorcompiler ${actor_exe} + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${generated}" + COMMAND ${MONO_EXECUTABLE} ${actor_exe} "${CMAKE_CURRENT_SOURCE_DIR}/${src}" "${CMAKE_CURRENT_BINARY_DIR}/${generated}" ${actor_compiler_flags} ${actor_compiler_flags} > /dev/null + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${src}" actorcompiler COMMENT "Compile actor: ${src}") endif() - set(_tmp_out "${_tmp_out};${CMAKE_CURRENT_BINARY_DIR}/${tmp}") + else() + list(APPEND sources ${src}) endif() endforeach() - MATH(EXPR ACTOR_TARGET_COUNTER "${ACTOR_TARGET_COUNTER}+1") - add_custom_target(${target}_actors_${ACTOR_TARGET_COUNTER} DEPENDS ${_tmp_out}) - add_dependencies(${target} ${target}_actors_${ACTOR_TARGET_COUNTER}) - target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) -endmacro() + 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() + 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}) + endif() + + add_custom_target(${AFT_NAME}_actors DEPENDS ${generated_files}) + add_dependencies(${AFT_NAME} ${AFT_NAME}_actors) + target_include_directories(${AFT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +endfunction() diff --git a/fdbbackup/CMakeLists.txt b/fdbbackup/CMakeLists.txt index dd6f46fa5b..c35aec3c3c 100644 --- a/fdbbackup/CMakeLists.txt +++ b/fdbbackup/CMakeLists.txt @@ -1,9 +1,7 @@ set(FDBBACKUP_SRCS backup.actor.cpp) -actor_set(FDBBACKUP_BUILD "${FDBBACKUP_SRCS}") -add_executable(fdbbackup "${FDBBACKUP_BUILD}") -actor_compile(fdbbackup "${FDBBACKUP_SRCS}") +add_flow_target(EXECUTABLE NAME fdbbackup SRCS ${FDBBACKUP_SRCS}) target_link_libraries(fdbbackup PRIVATE fdbclient) install(TARGETS fdbbackup DESTINATION ${FDB_BIN_DIR} COMPONENT clients) diff --git a/fdbcli/CMakeLists.txt b/fdbcli/CMakeLists.txt index 3cfbb7b793..251bbd86ef 100644 --- a/fdbcli/CMakeLists.txt +++ b/fdbcli/CMakeLists.txt @@ -8,9 +8,7 @@ if(NOT WIN32) list(APPEND FDBCLI_SRCS linenoise/linenoise.c) endif() -actor_set(FDBCLI_BUILD "${FDBCLI_SRCS}") -add_executable(fdbcli "${FDBCLI_BUILD}") -actor_compile(fdbcli "${FDBCLI_SRCS}") +add_flow_target(EXECUTABLE NAME fdbcli SRCS ${FDBCLI_SRCS}) target_link_libraries(fdbcli PRIVATE fdbclient) install(TARGETS fdbcli DESTINATION ${FDB_BIN_DIR} COMPONENT clients) diff --git a/fdbclient/CMakeLists.txt b/fdbclient/CMakeLists.txt index 1f7a00e11a..d0be44e3a8 100644 --- a/fdbclient/CMakeLists.txt +++ b/fdbclient/CMakeLists.txt @@ -87,8 +87,6 @@ set(FDBCLIENT_SRCS vexillographer_compile(TARGET fdboptions LANG cpp OUT ${CMAKE_CURRENT_BINARY_DIR}/FDBOptions.g OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/FDBOptions.g.h ${CMAKE_CURRENT_BINARY_DIR}/FDBOptions.g.cpp) -actor_set(FDBCLIENT_BUILD "${FDBCLIENT_SRCS}") -add_library(fdbclient STATIC ${FDBCLIENT_BUILD}) +add_flow_target(STATIC_LIBRARY NAME fdbclient SRCS ${FDBCLIENT_SRCS}) add_dependencies(fdbclient fdboptions) -actor_compile(fdbclient "${FDBCLIENT_SRCS}") target_link_libraries(fdbclient PUBLIC fdbrpc) diff --git a/fdbrpc/CMakeLists.txt b/fdbrpc/CMakeLists.txt index 3447f4e066..a873c5696c 100644 --- a/fdbrpc/CMakeLists.txt +++ b/fdbrpc/CMakeLists.txt @@ -57,9 +57,8 @@ set(FDBRPC_SRCS_DISABLE_ACTOR_WITHOUT_WAIT_WARNING FlowTests.actor.cpp dsltest.actor.cpp) -actor_set(FDBRPC_BUILD "${FDBRPC_SRCS};${FDBRPC_SRCS_DISABLE_ACTOR_WITHOUT_WAIT_WARNING}") -add_library(fdbrpc STATIC ${FDBRPC_BUILD}) -actor_compile(fdbrpc "${FDBRPC_SRCS}") -actor_compile(fdbrpc "${FDBRPC_SRCS_DISABLE_ACTOR_WITHOUT_WAIT_WARNING}" DISABLE_ACTOR_WITHOUT_WAIT_WARNING) +add_flow_target(STATIC_LIBRARY NAME fdbrpc + SRCS ${FDBRPC_SRCS} + DISABLE_ACTOR_WITHOUT_WAIT_WARNING ${FDBRPC_SRCS_DISABLE_ACTOR_WITHOUT_WAIT_WARNING}) target_include_directories(fdbrpc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libeio) target_link_libraries(fdbrpc PUBLIC flow) diff --git a/fdbserver/CMakeLists.txt b/fdbserver/CMakeLists.txt index ac4c205827..9d20584f7e 100644 --- a/fdbserver/CMakeLists.txt +++ b/fdbserver/CMakeLists.txt @@ -175,9 +175,7 @@ set(FDBSERVER_SRCS file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/workloads) -actor_set(FDBSERVER_BUILD "${FDBSERVER_SRCS}") -add_executable(fdbserver ${FDBSERVER_BUILD}) -actor_compile(fdbserver "${FDBSERVER_SRCS}") +add_flow_target(EXECUTABLE NAME fdbserver SRCS ${FDBSERVER_SRCS}) target_include_directories(fdbserver PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/workloads ${CMAKE_CURRENT_SOURCE_DIR}/workloads) diff --git a/flow/CMakeLists.txt b/flow/CMakeLists.txt index a827c7ba71..bd78d737c7 100644 --- a/flow/CMakeLists.txt +++ b/flow/CMakeLists.txt @@ -77,9 +77,7 @@ set(FLOW_SRCS configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hgVersion.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/hgVersion.h) -actor_set(FLOW_BUILD "${FLOW_SRCS}") -add_library(flow STATIC ${FLOW_BUILD}) -actor_compile(flow "${FLOW_SRCS}") +add_flow_target(STATIC_LIBRARY NAME flow SRCS ${FLOW_SRCS}) target_include_directories(flow SYSTEM PUBLIC ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(flow PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) if (NOT APPLE AND NOT WIN32)