I want to include all filed in source directory leaving one file.
Is there any way to using aux_source_directory or anything else I can include all files leaving that file ?
There are two possible solutions:
Use file (GLOB ... instead of aux_source_directory with a globbing expression that does not match that one file but includes all the others, e.g.:
file(GLOB _srcFiles "src/f[1-3].cpp")
This will match match files f1.cpp, f2.cpp, f3.cpp, but not f4.cpp.
Or use aux_source_directory and then remove the file to be excluded explicitly with a list(REMOVE_ITEM command, e.g.:
aux_source_directory(src _srcFiles)
list(REMOVE_ITEM _srcFiles "src/f4.cpp")
Related
I want to install all the header file under a directory.
i know regular expression can do that. but i do google a lot, not found how to include these three kind of file together.
I used command like this:
file(GLOB INFRA ${LOCAL_SRC_PATH}/infra/*.h[|p|x][|p|x])
to make INFRA variable to save all header file, but i found it ignore .h
I know this is quite easy, can you kindly help on this?
A globbing expression is not a regex; you need to use 3 separate commands to match .h, .hpp and .hxx files. Even as a regex this would fail, since the character groups match characters |, p and x, but they don't match the empty string.
In this case you'd probably use
set(PATH_PREFIX "${LOCAL_SRC_PATH}/infra/*")
file(GLOB INFRA_H "${PATH_PREFIX}.h")
file(GLOB INFRA_HPP "${PATH_PREFIX}.hpp")
file(GLOB INFRA_HXX "${PATH_PREFIX}.hxx")
set(INFRA ${INFRA_H} ${INFRA_HPP} ${INFRA_HXX})
In this case I recommend using install(DIRECTORY) though; this also allows you to use a regex instead of a globbing expression:
install(DIRECTORY "${LOCAL_SRC_PATH}/infra"
TYPE INCLUDE
FILES_MATCHING REGEX ".*\\.(h|hpp|hxx)")
I have one .pro file which has inputs jars mentioned as below:
-injars \plugins\a.b.c_1.0.0.201803060704.jar
trying to provide -injars \plugins\a.b.c_1.?.?..jar or a.b.c_.jar but proguard is not recognizing it. getting an error as (No such file or directory).
The basic question is does proguard support regex in -injars section?
Yes, there's a glob style pattern matching called filtering. No, it doesn't look like it's supported for -injars (I tried using their filter syntax both with and without single quotes).
I wasn't able to use their file filtering in the proguard.cfg file loaded by maven for the -injars flag. So, not sure where all it's supported or exactly how it's implemented for files.
? matches any single character in a file name.
* matches any part of a filename not containing the directory separator.
** matches any part of a filename, possibly containing any number of directory separators.
For example, "java/**.class,javax/**.class"
matches all class files in the java and javax.
http://www.dre.vanderbilt.edu/~schmidt/android/android-4.0/external/proguard/docs/manual/usage.html#filefilters
I want to do a Macro that gets a list of the sub-sub-directories that contain a specific type of files, in my case .jar files.
This macro is getting me all the sub-sub-directories:
MACRO(SUBSUBDIRLIST 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()
SUBSUBDIRLIST(TUTORIALS ${CMAKE_CURRENT_SOURCE_DIR})
What I now need is to find a way to check if a directory contains any .jar file.
Can I change the IF to do something like IF(child ${children} AND ${child} CONTAINS *.jar)?
While if command supports many ready-made checks, not all checks can be expressed directly via if. But you are free to use other commands, and check their result via if.
For check whether given directory contains specific type of files, FILE(GLOB) can be effectively used:
FILE(GLOB jars "${child}/*.jar")
if(jars)
# There are .jar files in directory referred by 'child'
endif()
I am trying to include several header files under NAMES while using FIND_PATH, was wondering if there was a way to include them without specifying each one of them.
Currently i use below format for this purpose.
FIND_PATH(FILE_INCLUDE
NAMES "xyz/x.h"
"xy/y.h"
......
......
PATHS "${CMAKE_CURRENT_SOURCE_DIR}"
PATH_SUFFIXES xy/yx/xyz
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
I was wondering if there was a easier way to specify the list of NAMES as there are lot to be added.
CMake provides the following command for recursive files globing:
file(GLOB_RECURSE variable [RELATIVE path] [FOLLOW_SYMLINKS]
[globbing expressions]...) Command documentation:
http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:file
I'm using get_filename_component in cmake to get the absolute path of a possibly relative path given in a variable.
And I want to do an out-of-tree/out-of-source-build.
It seems to me that get_filename_component is using CMAKE_SOURCE_DIR as reference-path.
Is there a way to change that or to workaround it?
One way I tried is to prefix my potential relative path with ${CMAKE_BINARY_DIR} but that stops working of the path given is not relative.
Assuming your relative path is always relative to CMAKE_BINARY_DIR, then you can handle this pretty easily using if(IS_ABSOLUTE ...):
if(NOT IS_ABSOLUTE ${MyPath})
set(MyAbsPath ${CMAKE_BINARY_DIR}/${MyPath})
endif()
If the subject file or dir exists at CMake run time, then you can always do a find_file call, passing the possible NAMES and PATHS. If the file exists and is found, the resulting variable will hold the full path to the file.
Or you can use the if(EXISTS ...) signature of if to check for the existence or not of the given file.