Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android cmakelist add multi source file?

I write NDK project using Android Studio & CMakelist.

But when I want to include lots cpp/c files to CMakelists.txt , I can not find a easy way to do it gently.

I need your help.

Here is my code's file tree sample:

Cmakelists.txt
src
|__main
     |__cpp
         |___a.cpp   // cpp file 
         |___a.h
         |___aa.c   //   c file
         |___...
         |___dirA    //  a dir
              |__b.c  // also has c file 
              |__b.h
              |__d.cpp  // and cpp file
              |__...
              |___dirB  // another dir
                   |__xxx.c
                   |__...

In my Cmakelist, I used

file(GLOB cpp_srcs "src/main/cpp/*.cpp")

This seems only include the fist directory layer's cpp files , NOT include c files, and the sub dir's cpp/c files .

Any way to make it ? The dir is too deep, I don't want to add cpp/c files manually.

like image 568
I'm SuperMan Avatar asked Oct 30 '25 22:10

I'm SuperMan


1 Answers

You can try:

file(GLOB_RECURSE cpp_srcs "src/main/cpp/*.c" "src/main/cpp/*.cpp")

or maybe:

file(GLOB_RECURSE cpp_srcs_c "src/main/cpp/*.c")
file(GLOB_RECURSE cpp_srcs_cpp "src/main/cpp/*.cpp")
set(cpp_srcs ${cpp_srcs_c} ${cpp_srcs_cpp})

I'm not sure if the first pattern works and I can't test now, but the second should do it.

like image 161
Bungow Avatar answered Nov 03 '25 02:11

Bungow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!