Skip to content

What to set as target_link_library? #366

@raphael10-collab

Description

@raphael10-collab

git cloned ruy repo :

(base) raphy@raohy:~$ git clone --recursive https://github.com/google/ruy.git
Cloning into 'ruy'...
remote: Enumerating objects: 3490, done.
remote: Counting objects: 100% (215/215), done.
remote: Compressing objects: 100% (120/120), done.
remote: Total 3490 (delta 140), reused 96 (delta 95), pack-reused 3275 (from 4)
Receiving objects: 100% (3490/3490), 1.85 MiB | 12.38 MiB/s, done.
Resolving deltas: 100% (2547/2547), done.
Submodule 'cpuinfo' (https://github.com/pytorch/cpuinfo) registered for path 'third_party/cpuinfo'
Submodule 'googletest' (https://github.com/google/googletest) registered for path 'third_party/googletest'
Cloning into '/home/raphy/ruy/third_party/cpuinfo'...
remote: Enumerating objects: 7125, done.
remote: Counting objects: 100% (2708/2708), done.
remote: Compressing objects: 100% (552/552), done.
remote: Total 7125 (delta 2498), reused 2158 (delta 2156), pack-reused 4417 (from 2)
Receiving objects: 100% (7125/7125), 5.29 MiB | 18.89 MiB/s, done.
Resolving deltas: 100% (5347/5347), done.
Cloning into '/home/raphy/ruy/third_party/googletest'...
remote: Enumerating objects: 28300, done.
remote: Counting objects: 100% (114/114), done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 28300 (delta 60), reused 35 (delta 33), pack-reused 28186 (from 3)
Receiving objects: 100% (28300/28300), 13.46 MiB | 29.25 MiB/s, done.
Resolving deltas: 100% (21002/21002), done.
Submodule path 'third_party/cpuinfo': checked out '082deffc80ce517f81dc2f3aebe6ba671fcd09c9'
Submodule path 'third_party/googletest': checked out '6c58c11d5497b6ee1df3cb400ce30deb72fc28c0'

Compiled, built and installed in another C++ project :

(base) raphy@raohy:~/ruy$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/Grasp/src/ruy -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja -B build -S . -Wno-dev
-- The CXX compiler identification is GNU 13.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found Python: /home/raphy/miniconda3/bin/python3.12 (found version "3.12.8") found components: Interpreter
-- Configuring done (0.8s)
-- Generating done (0.1s)
-- Build files have been written to: /home/raphy/ruy/build



(base) raphy@raohy:~/ruy$ cmake --build build --target install
[16/179] Building C object third_party/cpuinfo/deps/clog/CMakeFiles/clog.dir/src/clog.c.o

[178/179] Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /home/raphy/Grasp/src/ruy/lib/cmake/ruy/ruyTargets.cmake
-- Installing: /home/raphy/Grasp/src/ruy/lib/cmake/ruy/ruyTargets-relwithdebinfo.cmake
-- Installing: /home/raphy/Grasp/src/ruy/lib/cmake/ruy/ruyConfig.cmake
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/trace.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/platform.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/check_macros.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/opt_set.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/time.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_wait.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/wait.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/size_util.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_tune.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/tune.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_system_aligned_alloc.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/system_aligned_alloc.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_prepacked_cache.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/prepacked_cache.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_allocator.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/allocator.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/side_pair.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_block_map.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/block_map.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_blocking_counter.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/blocking_counter.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_thread_pool.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/thread_pool.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/cpu_cache_params.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_cpuinfo.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/cpuinfo.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/path.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_denormal.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/denormal.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/performance_advisory.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/matrix.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/mul_params.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/mat.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/asm_helpers.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_apply_multiplier.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/apply_multiplier.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/kernel_common.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/pack_common.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_kernel_arm.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/kernel_arm.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_pack_arm.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/pack_arm.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_kernel_avx512.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/kernel_x86.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_pack_avx512.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/pack_x86.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_have_built_path_for_avx512.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/have_built_path_for.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_kernel_avx2_fma.a
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/kernel_x86.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_pack_avx2_fma.a
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/pack_x86.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_have_built_path_for_avx2_fma.a
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/have_built_path_for.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_kernel_avx.a
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/kernel_x86.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_pack_avx.a
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/pack_x86.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_have_built_path_for_avx.a
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/have_built_path_for.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/kernel.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/pack.h
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/have_built_path_for.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_context.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/context.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_ctx.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/ctx.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/ctx_impl.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_context_get_ctx.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/context_get_ctx.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/trmul_params.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_trmul.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/trmul.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_prepare_packed_matrices.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/prepare_packed_matrices.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/create_trmul_params.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/validate.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_frontend.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/frontend.h
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/context.h
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/matrix.h
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/mul_params.h
-- Up-to-date: /home/raphy/Grasp/src/ruy/include/ruy/path.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/ruy.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/reference_mul.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_profiler_instrumentation.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/profiler/instrumentation.h
-- Installing: /home/raphy/Grasp/src/ruy/lib/libruy_profiler_profiler.a
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/profiler/profiler.h
-- Installing: /home/raphy/Grasp/src/ruy/include/ruy/profiler/treeview.h

(base) raphy@raohy:~/Grasp/src/ruy$ ls -lah
total 16K
drwxrwxr-x  4 raphy raphy 4,0K set 20 11:57 .
drwxrwxr-x 66 raphy raphy 4,0K set 20 11:48 ..
drwxrwxr-x  3 raphy raphy 4,0K set 20 11:57 include
drwxrwxr-x  3 raphy raphy 4,0K set 20 11:57 lib

In the CMakeLists.txt of the other prj:

(base) raphy@raohy:~/Grasp$ nano CMakeLists.txt : 

target_link_directories(${PROJECT_NAME} PUBLIC
    ./src/ruy/lib
)

target_include_directories(${PROJECT_NAME} PUBLIC
    ./src/ruy/include
)

If I set as target_link_library ruy :

target_link_libraries (${PROJECT_NAME} PUBLIC
    ruy
)

I get the error message: "target link library ruy not found"

The problem is that in the /lib subfolder there are a lot of potential libraries :

(base) raphy@raohy:~/Grasp/src/ruy/lib$ ls -lah
total 6,1M
drwxrwxr-x 3 raphy raphy 4,0K set 20 11:57 .
drwxrwxr-x 4 raphy raphy 4,0K set 20 11:57 ..
drwxrwxr-x 3 raphy raphy 4,0K set 20 11:57 cmake
-rw-r--r-- 1 raphy raphy 107K set 20 11:56 libruy_allocator.a
-rw-r--r-- 1 raphy raphy 26K set 20 11:56 libruy_apply_multiplier.a
-rw-r--r-- 1 raphy raphy 80K set 20 11:56 libruy_blocking_counter.a
-rw-r--r-- 1 raphy raphy 71K set 20 11:56 libruy_block_map.a
-rw-r--r-- 1 raphy raphy 326K set 20 11:56 libruy_context.a
-rw-r--r-- 1 raphy raphy 258K set 20 11:56 libruy_context_get_ctx.a
-rw-r--r-- 1 raphy raphy 50K set 20 11:56 libruy_cpuinfo.a
-rw-r--r-- 1 raphy raphy 469K set 20 11:56 libruy_ctx.a
-rw-r--r-- 1 raphy raphy 15K set 20 11:56 libruy_denormal.a
-rw-r--r-- 1 raphy raphy 74K set 20 11:56 libruy_frontend.a
-rw-r--r-- 1 raphy raphy 3,5K set 20 11:56 libruy_have_built_path_for_avx2_fma.a
-rw-r--r-- 1 raphy raphy 3,5K set 20 11:56 libruy_have_built_path_for_avx512.a
-rw-r--r-- 1 raphy raphy 3,5K set 20 11:56 libruy_have_built_path_for_avx.a
-rw-r--r-- 1 raphy raphy 38K set 20 11:56 libruy_kernel_arm.a
-rw-r--r-- 1 raphy raphy 531K set 20 11:56 libruy_kernel_avx2_fma.a
-rw-r--r-- 1 raphy raphy 736K set 20 11:56 libruy_kernel_avx512.a
-rw-r--r-- 1 raphy raphy 1,2M set 20 11:56 libruy_kernel_avx.a
-rw-r--r-- 1 raphy raphy 20K set 20 11:56 libruy_pack_arm.a
-rw-r--r-- 1 raphy raphy 227K set 20 11:56 libruy_pack_avx2_fma.a
-rw-r--r-- 1 raphy raphy 399K set 20 11:56 libruy_pack_avx512.a
-rw-r--r-- 1 raphy raphy 562K set 20 11:56 libruy_pack_avx.a
-rw-r--r-- 1 raphy raphy 236K set 20 11:56 libruy_prepacked_cache.a
-rw-r--r-- 1 raphy raphy 173K set 20 11:56 libruy_prepare_packed_matrices.a
-rw-r--r-- 1 raphy raphy 2,7K set 20 11:56 libruy_profiler_instrumentation.a
-rw-r--r-- 1 raphy raphy 9,3K set 20 11:57 libruy_profiler_profiler.a
-rw-r--r-- 1 raphy raphy 9,7K set 20 11:56 libruy_system_aligned_alloc.a
-rw-r--r-- 1 raphy raphy 239K set 20 11:56 libruy_thread_pool.a
-rw-r--r-- 1 raphy raphy 202K set 20 11:56 libruy_trmul.a
-rw-r--r-- 1 raphy raphy 43K set 20 11:56 libruy_tune.a
-rw-r--r-- 1 raphy raphy 62K set 20 11:56 libruy_wait.a

OS: Ubuntu 24.04

Which one to set as target_link_library?

Addendum:
If in the CMakeLists.txt of the other prj I define a FetchContent_Declare for ruy then, setting ruy as target_link_library works fine

(base) raphy@raohy:~/Grasp$ nano CMakeLists.txt :

message(CHECK_START "Fetching ruy")
list(APPEND CMAKE_MESSAGE_INDENT "  ")

include(FetchContent)

FetchContent_Declare(
    ruy
    GIT_REPOSITORY https://github.com/google/ruy.git
    GIT_TAG master
    GIT_SHALLOW TRUE
    GIT_PROGRESS TRUE
    DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

set(BUILD_TESTING OFF)
set(ruy_BUILD_TESTING OFF)
set(ruy_MPL2_ONLY ON)
set(ruy_BUILD_PKGCONFIG OFF)
set(ruy_BUILD_DOC OFF)
FetchContent_MakeAvailable(ruy)

list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "ruy fetched")


target_link_libraries (${PROJECT_NAME} PUBLIC
    ruy
)

But, as detailed here : https://ai.google.dev/edge/litert/build/cmake#build_installable_package ,
in order to build tflite an installable package that can be used as a dependency by another CMake project, I need to specify the path to ruy cmake:

-Druy_DIR=<install path>/lib/cmake/ruy

and, as far as I understand, it is possible to define the path to ruy cmake only
if I compile, build and install ruy in another C++ project :

(base) raphy@raohy:~/ruy$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/Grasp/src/ruy -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja -B build -S . -Wno-dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions