Skip to content

Commit

Permalink
Enhance/generate stubs (#119)
Browse files Browse the repository at this point in the history
* CMake: Generate cpp stubs, smooth out API for dependent projects

* Remove old stubs and scripts

* CMake: Ensure correct MSVC runtime by default

* Correct variable setting logic in macro
  • Loading branch information
weefuzzy authored May 26, 2022
1 parent 1993e87 commit 3291b01
Show file tree
Hide file tree
Showing 145 changed files with 153 additions and 2,581 deletions.
102 changes: 41 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,37 @@
# under the European Union’s Horizon 2020 research and innovation programme
# (grant agreement No 725899).

cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.18)

cmake_policy(SET CMP0074 NEW)
# cmake_policy(SET CMP0074 NEW)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

if (APPLE)
set(CMAKE_XCODE_GENERATE_SCHEME ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.8)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/script")
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/script
PARENT_SCOPE)
endif()

project (flucoma-docs LANGUAGES CXX)

set_property(GLOBAL PROPERTY FLUID_DOCS_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY ON)

set(FLUID_PATH "" CACHE PATH "The top level of the flucoma-core repo. Will clone from repo if blank")

set(MAX_DOC_OUT "${CMAKE_BINARY_DIR}/max_ref" CACHE PATH "")
set(PD_DOC_OUT "${CMAKE_BINARY_DIR}/pd_ref" CACHE PATH "")
set(CLI_DOC_OUT "${CMAKE_BINARY_DIR}/cli_ref" CACHE PATH "")
set(SC_DOC_OUT "${CMAKE_BINARY_DIR}/sc_ref" CACHE PATH "")
set(RAW_DOC_OUT "${CMAKE_BINARY_DIR}" CACHE PATH "")
# option(TESTS,"Run tests?")

include(FetchContent)

set(FETCHCONTENT_QUIET FALSE)
Expand Down Expand Up @@ -90,60 +94,36 @@ set(FLUID_GENERATED_DOC "${CMAKE_BINARY_DIR}/json")
set(FLUID_HUMAN_DOC "${CMAKE_CURRENT_SOURCE_DIR}/doc")
set(FLIUD_JINJA_TEMPLATES "${CMAKE_CURRENT_SOURCE_DIR}/flucoma/doc/templates")

# Make sure to build targets from flucoma-core
macro(subdirlist result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
list(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist})
endmacro()

# Generate a project for every folder in the "src/clients" folder
subdirlist(PROJECT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/clients)
foreach (project_dir ${PROJECT_DIRS})
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/clients/${project_dir}/CMakeLists.txt")
message("Generating: ${project_dir}")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/clients/${project_dir})
list(APPEND json_files "${CMAKE_BINARY_DIR}/json/${project_dir}.json")

add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/json/${project_dir}.json"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/json/"
COMMAND $<TARGET_FILE:${project_dir}> ARGS "${CMAKE_BINARY_DIR}/json/"
COMMENT "Generating JSON for ${project_dir}"
DEPENDS ${project_dir}
)
endif ()
endforeach ()


macro(add_ref_target platform comment)
string(TOUPPER ${platform} platform_uc)
string(TOLOWER ${platform} platform_lc)

get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(FLUID_${platform_uc}_REF_TARGET MAKE_${platform_uc}_REF PARENT_SCOPE)
set(FLUID_${platform_uc}_REF_PATH "${CMAKE_BINARY_DIR}/${platform_lc}_ref" PARENT_SCOPE)
endif()

add_custom_target(MAKE_${platform_uc}_REF
COMMAND ${CMAKE_COMMAND} -E make_directory "${${platform_uc}_DOC_OUT}"
COMMAND ${PYTHON_3} "-mflucoma.MakeRef" "${platform_lc}" ${FLUID_GENERATED_DOC} ${FLUID_HUMAN_DOC} "${${platform_uc}_DOC_OUT}" ${FLIUD_JINJA_TEMPLATES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${comment}
DEPENDS ${json_files}
VERBATIM
)
endmacro()

add_ref_target(max "Making Max ref")
add_ref_target(pd "Making PD ref")
add_ref_target(cli "Making CLI ref")
add_ref_target(sc "Making SC ref")
include(MakeDocSource)

get_core_clients(client_list)

foreach(client ${client_list})
get_core_client_header(${client} header)
get_core_client_class(${client} class)
list(APPEND FLUID_CLIENTS ${client})
list(APPEND FLUID_HEADERS ${header})
list(APPEND FLUID_CLASSES ${class})
endforeach()

generate_doc_exe(
CLIENTS ${FLUID_CLIENTS}
HEADERS ${FLUID_HEADERS}
CLASSES ${FLUID_CLASSES}
FILENAME DumpParams
)

set(JSON_FILES ${FLUID_CLIENTS})
list(TRANSFORM FLUID_CLIENTS APPEND .json)
list(TRANSFORM JSON_FILES PREPEND "${CMAKE_BINARY_DIR}/json/")

add_custom_command(TARGET DumpParams POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/json/"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/json/"
COMMAND $<TARGET_FILE:DumpParams> ARGS "${CMAKE_BINARY_DIR}/json/"
)

include(FlucomaDocs)
add_ref_target(raw "Making raw API JSON")

enable_testing()
Expand Down
33 changes: 33 additions & 0 deletions script/FlucomaDocs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Part of the Fluid Corpus Manipulation Project (http://www.flucoma.org/)
# Copyright 2017-2019 University of Huddersfield.
# Licensed under the BSD-3 License.
# See license.md file in the project root for full license information.
# This project has received funding from the European Research Council (ERC)
# under the European Union’s Horizon 2020 research and innovation programme
# (grant agreement No 725899).

cmake_minimum_required(VERSION 3.18)

macro(add_ref_target platform comment)
string(TOUPPER ${platform} platform_uc)
string(TOLOWER ${platform} platform_lc)

set(FLUID_${platform_uc}_REF_TARGET MAKE_${platform_uc}_REF)
set(FLUID_${platform_uc}_REF_PATH "${CMAKE_BINARY_DIR}/${platform_lc}_ref")

get_property(DOC_ROOT GLOBAL PROPERTY FLUID_DOCS_ROOT)

set(FLUID_GENERATED_DOC "${CMAKE_BINARY_DIR}/json")
set(FLUID_HUMAN_DOC "${DOC_ROOT}/doc")
set(FLIUD_JINJA_TEMPLATES "${DOC_ROOT}/flucoma/doc/templates")

add_custom_target(MAKE_${platform_uc}_REF
COMMAND ${CMAKE_COMMAND} -E make_directory "${${platform_uc}_DOC_OUT}"
COMMAND ${PYTHON_3} "-mflucoma.MakeRef" "${platform_lc}" ${FLUID_GENERATED_DOC} ${FLUID_HUMAN_DOC} "${${platform_uc}_DOC_OUT}" ${FLIUD_JINJA_TEMPLATES}
WORKING_DIRECTORY ${DOC_ROOT}
COMMENT ${comment}
# DEPENDS ${json_files}
VERBATIM
)
add_dependencies(MAKE_${platform_uc}_REF DumpParams)
endmacro()
79 changes: 79 additions & 0 deletions script/MakeDocSource.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Part of the Fluid Corpus Manipulation Project (http://www.flucoma.org/)
# Copyright 2017-2019 University of Huddersfield.
# Licensed under the BSD-3 License.
# See license.md file in the project root for full license information.
# This project has received funding from the European Research Council (ERC)
# under the European Union’s Horizon 2020 research and innovation programme
# (grant agreement No 725899).

cmake_minimum_required(VERSION 3.18)

include(FLuidClientStub)

function(add_doc_gen name source)

add_executable(${name} ${source})

target_link_libraries(${name} PRIVATE
FLUID_DECOMPOSITION FLUID_DUMP
)

target_include_directories (
${name}
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../../include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../../thirdparty"
)

if(APPLE)
set_target_properties(${name} PROPERTIES
XCODE_GENERATE_SCHEME ON
)
#If we target 10.7 (actually < 10.9), we have to manually include this:
target_compile_options(${name} PRIVATE -stdlib=libc++)
endif()

if(MSVC)
target_compile_options(${name} PRIVATE /W3)
else()
target_compile_options(${name} PRIVATE -Wall -Wextra -Wpedantic -Wno-return-type -Wno-c++11-narrowing)
endif()

get_property(HEADERS TARGET FLUID_DECOMPOSITION PROPERTY INTERFACE_SOURCES)
source_group(TREE "${flucoma-core_SOURCE_DIR}/include" FILES ${HEADERS})

endfunction()

function(make_external_name client header var)
set(${var} ${client} PARENT_SCOPE)
endfunction()

function(generate_doc_exe)
# # Define the supported set of keywords
set(noValues "")
set(singleValues FILENAME EXTERNALS_OUT FILE_OUT)
set(multiValues CLIENTS HEADERS CLASSES)
# # Process the arguments passed in
include(CMakeParseArguments)
cmake_parse_arguments(ARG
"${noValues}"
"${singleValues}"
"${multiValues}"
${ARGN})

if(ARG_FILENAME)
set(external_name ${ARG_FILENAME})
else()
list(GET ARG_CLIENTS 0 external_name)
endif()

set(ENTRY_POINT "int main(int argc, char *argv[])")
set(WRAPPER_TEMPLATE [=[ParameterDump<${class}>::dump("${external}", argv[1]);]=])
set(CCE_WRAPPER "#include \"FluidParameterDump.hpp\"")

generate_source(${ARGN} EXTERNALS_OUT external FILE_OUT outfile)

message(STATUS "Generating: ${external_name}")
add_doc_gen(${external_name} ${outfile})

endfunction()
58 changes: 0 additions & 58 deletions script/dump-posttarget.cmake

This file was deleted.

10 changes: 0 additions & 10 deletions script/dump-pretarget.cmake

This file was deleted.

19 changes: 0 additions & 19 deletions src/clients/AmpFeature/AmpFeature.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/clients/AmpFeature/CMakeLists.txt

This file was deleted.

19 changes: 0 additions & 19 deletions src/clients/AmpGate/AmpGate.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/clients/AmpGate/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 3291b01

Please sign in to comment.