From 16531f5267a9aad9e20a6ddc0c0c4421767f39bf Mon Sep 17 00:00:00 2001 From: Tanmay Shah Date: Thu, 13 Jun 2024 07:28:08 -0700 Subject: [PATCH] examples: legacy_apps: build success demos - Remove version control information - Add cmake infra to find open_amp library - fix open_amp and libmetal library linking Signed-off-by: Tanmay Shah --- README.md | 33 +++++++++++++++++++ examples/legacy_apps/cmake/depends.cmake | 7 ++++ .../cmake/modules/Findopen_amp.cmake | 30 +++++++++++++++++ examples/legacy_apps/cmake/options.cmake | 16 +-------- .../legacy_apps/examples/echo/CMakeLists.txt | 8 +++-- .../examples/linux_rpc_demo/CMakeLists.txt | 8 +++-- .../examples/load_fw/CMakeLists.txt | 1 + .../examples/matrix_multiply/CMakeLists.txt | 8 +++-- .../examples/nocopy_echo/CMakeLists.txt | 9 +++-- .../examples/rpc_demo/CMakeLists.txt | 7 ++-- .../examples/rpmsg_sample_echo/CMakeLists.txt | 8 +++-- examples/legacy_apps/tests/msg/CMakeLists.txt | 8 +++-- 12 files changed, 107 insertions(+), 36 deletions(-) create mode 100644 examples/legacy_apps/cmake/modules/Findopen_amp.cmake diff --git a/README.md b/README.md index ef6983e..e92df5a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ # openamp-system-reference End-to-end system reference material showcasing all the different aspects of OpenAMP, on multiple vendor platforms. + +# Build legacy_apps + +Legacy apps are moved from open_amp library repository. + +## Build libmetal +``` + $ mkdir -p build-libmetal + $ cd build-libmetal + $ cmake -DCMAKE_INSTALL_PREFIX= + $ make VERBOSE=1 install +``` + +## Build open_amp +``` + $ mkdir -p build-openamp + $ cd build-openamp + $ cmake -DCMAKE_INCLUDE_PATH= \ + -DCMAKE_LIBRARY_PATH= \ + -DCMAKE_INSTALL_PREFIX= + $ make VERBOSE=1 install +``` +## Build legacy Apps +``` + $ mkdir -p build-openamp-demos + $ cd build-openamp-demos + $ cmake \ + -DCMAKE_INCLUDE_PATH= \ + -DCMAKE_LIBRARY_PATH= \ + -DCMAKE_INSTALL_PREFIX= + $ make VERBOSE=1 install +``` + diff --git a/examples/legacy_apps/cmake/depends.cmake b/examples/legacy_apps/cmake/depends.cmake index d202888..471117d 100644 --- a/examples/legacy_apps/cmake/depends.cmake +++ b/examples/legacy_apps/cmake/depends.cmake @@ -9,6 +9,13 @@ if (WITH_LIBMETAL_FIND) collect (PROJECT_LIB_DEPS "${LIBMETAL_LIB}") endif (WITH_LIBMETAL_FIND) +if (WITH_OPENAMP_FIND) + find_package (open_amp REQUIRED) + collect (PROJECT_INC_DIRS "${OPENAMP_INCLUDE_DIR}") + collect (PROJECT_LIB_DIRS "${OPENAMP_LIB_DIR}") + collect (PROJECT_LIB_DEPS "${OPENAMP_LIB}") +endif (WITH_OPENAMP_FIND) + if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") check_include_files (stdatomic.h HAVE_STDATOMIC_H) check_include_files (fcntl.h HAVE_FCNTL_H) diff --git a/examples/legacy_apps/cmake/modules/Findopen_amp.cmake b/examples/legacy_apps/cmake/modules/Findopen_amp.cmake new file mode 100644 index 0000000..c0bdbb9 --- /dev/null +++ b/examples/legacy_apps/cmake/modules/Findopen_amp.cmake @@ -0,0 +1,30 @@ +# Finidopen_amp +# -------- +# +# Find open_amp +# +# Find the native open_amp includes and library this module defines +# +# :: +# +# OPENAMP_INCLUDE_DIR, where to find metal/sysfs.h, etc. + +# FIX ME, CMAKE_FIND_ROOT_PATH doesn't work +# even use the following +# set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +# set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) +# set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +find_path(OPENAMP_INCLUDE_DIR NAMES openamp/ PATHS ${CMAKE_FIND_ROOT_PATH}) +find_library(OPENAMP_LIB NAMES open_amp PATHS ${CMAKE_FIND_ROOT_PATH}) +get_filename_component(OPENAMP_LIB_DIR ${OPENAMP_LIB} DIRECTORY) + +# handle the QUIETLY and REQUIRED arguments and set HUGETLBFS_FOUND to TRUE if +# all listed variables are TRUE +include (FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS (open_amp DEFAULT_MSG OPENAMP_LIB OPENAMP_INCLUDE_DIR) + +if (OPENAMP_FOUND) + set (OPENAMP_LIBS ${OPENAMP_LIB}) +endif (OPENAMP_FOUND) + +mark_as_advanced (OPENAMP_LIB OPENAMP_INCLUDE_DIR OPENAMP_LIB_DIR) diff --git a/examples/legacy_apps/cmake/options.cmake b/examples/legacy_apps/cmake/options.cmake index 2f0a749..a23cf94 100644 --- a/examples/legacy_apps/cmake/options.cmake +++ b/examples/legacy_apps/cmake/options.cmake @@ -1,18 +1,3 @@ -file(READ ${OPENAMP_ROOT_DIR}/VERSION ver) - -string(REGEX MATCH "VERSION_MAJOR = ([0-9]*)" _ ${ver}) -set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) - -string(REGEX MATCH "VERSION_MINOR = ([0-9]*)" _ ${ver}) -set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1}) - -string(REGEX MATCH "VERSION_PATCH = ([0-9]*)" _ ${ver}) -set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_1}) - -set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) - -message(STATUS "open-amp version: ${PROJECT_VERSION} (${OPENAMP_ROOT_DIR})") - if (NOT DEFINED CMAKE_BUILD_TYPE) set (CMAKE_BUILD_TYPE Debug) endif (NOT DEFINED CMAKE_BUILD_TYPE) @@ -121,6 +106,7 @@ if (WITH_ZEPHYR) endif (WITH_ZEPHYR) option (WITH_LIBMETAL_FIND "Check Libmetal library can be found" ON) +option (WITH_OPENAMP_FIND "Check libopen_amp library can be found" ON) if (DEFINED RPMSG_BUFFER_SIZE) add_definitions( -DRPMSG_BUFFER_SIZE=${RPMSG_BUFFER_SIZE} ) diff --git a/examples/legacy_apps/examples/echo/CMakeLists.txt b/examples/legacy_apps/examples/echo/CMakeLists.txt index f01de6e..894e7fe 100644 --- a/examples/legacy_apps/examples/echo/CMakeLists.txt +++ b/examples/legacy_apps/examples/echo/CMakeLists.txt @@ -25,20 +25,22 @@ foreach (_app rpmsg-echo-ping rpmsg-echo) if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_compile_options (${_app}-shared PRIVATE "-fPIC") + target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" ) diff --git a/examples/legacy_apps/examples/linux_rpc_demo/CMakeLists.txt b/examples/legacy_apps/examples/linux_rpc_demo/CMakeLists.txt index f10cb89..a2430bb 100644 --- a/examples/legacy_apps/examples/linux_rpc_demo/CMakeLists.txt +++ b/examples/legacy_apps/examples/linux_rpc_demo/CMakeLists.txt @@ -27,20 +27,22 @@ foreach (_app ${app_list}) if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_compile_options (${_app}-shared PRIVATE "-fPIC") + target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" ) endif (WITH_STATIC_LIB) diff --git a/examples/legacy_apps/examples/load_fw/CMakeLists.txt b/examples/legacy_apps/examples/load_fw/CMakeLists.txt index 041126e..9db6e2d 100644 --- a/examples/legacy_apps/examples/load_fw/CMakeLists.txt +++ b/examples/legacy_apps/examples/load_fw/CMakeLists.txt @@ -28,6 +28,7 @@ foreach (_app load_fw) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") + target_compile_options (${_app}.out PRIVATE "-static") target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections -T"${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld" -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/legacy_apps/examples/matrix_multiply/CMakeLists.txt b/examples/legacy_apps/examples/matrix_multiply/CMakeLists.txt index 8914e17..7ce4ad7 100644 --- a/examples/legacy_apps/examples/matrix_multiply/CMakeLists.txt +++ b/examples/legacy_apps/examples/matrix_multiply/CMakeLists.txt @@ -19,20 +19,22 @@ foreach (_app matrix_multiply matrix_multiplyd) if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_compile_options (${_app}-shared PRIVATE "-fPIC") + target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" ) diff --git a/examples/legacy_apps/examples/nocopy_echo/CMakeLists.txt b/examples/legacy_apps/examples/nocopy_echo/CMakeLists.txt index d82efdf..898d9f7 100644 --- a/examples/legacy_apps/examples/nocopy_echo/CMakeLists.txt +++ b/examples/legacy_apps/examples/nocopy_echo/CMakeLists.txt @@ -25,20 +25,23 @@ foreach (_app rpmsg-nocopy-ping rpmsg-nocopy-echo) if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_compile_options (${_app}-shared PRIVATE "-fPIC") + target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_compile_options (${_app}.out PRIVATE "-static") + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" ) diff --git a/examples/legacy_apps/examples/rpc_demo/CMakeLists.txt b/examples/legacy_apps/examples/rpc_demo/CMakeLists.txt index 5d5655d..cb22472 100644 --- a/examples/legacy_apps/examples/rpc_demo/CMakeLists.txt +++ b/examples/legacy_apps/examples/rpc_demo/CMakeLists.txt @@ -29,20 +29,21 @@ foreach (_app ${app_list}) if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_link_libraries (${_app}-shared -shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" ) endif (WITH_STATIC_LIB) diff --git a/examples/legacy_apps/examples/rpmsg_sample_echo/CMakeLists.txt b/examples/legacy_apps/examples/rpmsg_sample_echo/CMakeLists.txt index eda1111..f6f0aaa 100644 --- a/examples/legacy_apps/examples/rpmsg_sample_echo/CMakeLists.txt +++ b/examples/legacy_apps/examples/rpmsg_sample_echo/CMakeLists.txt @@ -21,20 +21,22 @@ foreach (_app rpmsg-sample-echo rpmsg-sample-ping) if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_compile_options (${_app}-shared PRIVATE "-fPIC") + target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" ) diff --git a/examples/legacy_apps/tests/msg/CMakeLists.txt b/examples/legacy_apps/tests/msg/CMakeLists.txt index a583fd0..286518a 100644 --- a/examples/legacy_apps/tests/msg/CMakeLists.txt +++ b/examples/legacy_apps/tests/msg/CMakeLists.txt @@ -31,20 +31,22 @@ foreach (_app msg-test-rpmsg-ping msg-test-rpmsg-nocopy-ping msg-test-rpmsg-noco if (WITH_SHARED_LIB) add_executable (${_app}-shared ${_sources}) - target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) + target_compile_options (${_app}-shared PRIVATE "-fPIC") + target_link_libraries (${_app}-shared -shared ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (WITH_SHARED_LIB) if (WITH_STATIC_LIB) if (${PROJECT_SYSTEM} STREQUAL "linux") add_executable (${_app}-static ${_sources}) - target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) + target_compile_options (${_app}-static PRIVATE "-static") + target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else (${PROJECT_SYSTEM}) add_executable (${_app}.out ${_sources}) set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") - target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) + target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif (${PROJECT_SYSTEM} STREQUAL "linux" )