ellipticaldoor
ellipticaldoor

Reputation: 1272

Is it possible to write a GLOB_RECURSE in cmake that ignores files ending in a certain way?

I have the following GLOB_RECURSE in my cmake config to add to my project all the cpp files

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp)

Will be possible to add some rule to ignore certain files? I will like to ignore files ending with test.cpp in their name.

Maybe there is something like this?

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*{!(test),}.cpp)

Upvotes: 0

Views: 245

Answers (1)

yflelion
yflelion

Reputation: 1746

May be you can try with Negative Look ahead. However it will be easier to do t like this:

file(GLOB_RECURSE FILES CONFIGURE_DEPENDS src/*.cpp)

foreach( FILE ${FILES})
  if (${FILE} MATCHES test.cpp)
    list(APPEND TESTS ${FILE})
  else()
    list(APPEND SOURCES ${FILE})
  endif()
endforeach()

This way you can use sources to compile and you will also have the test list ready.

Upvotes: 2

Related Questions