FindwxWidgets.cmake fails when the path to the package contains a -D or -I in the name
FindwxWidgets.cmake parses the output of wx-config --cxxflags to get the defines and include path. And the way it parses the string is not robust enough when the path to the package (and thus the include paths) contain a -D or -I in the name.
Currently it does this:
# parse definitions from cxxflags;
# drop -D* from CXXFLAGS and the -D prefix
string(REGEX MATCHALL "-D[^;]+"
wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
string(REGEX REPLACE "-D[^;]+(;|$)" ""
wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
string(REGEX REPLACE ";$" ""
wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
string(REPLACE "-D" ""
wxWidgets_DEFINITIONS "${wxWidgets_DEFINITIONS}")
# parse include dirs from cxxflags; drop -I prefix
string(REGEX MATCHALL "-I[^;]+"
wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
string(REGEX REPLACE "-I[^;]+;" ""
wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
string(REPLACE "-I" ""
wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
And this means that with CXXFLAGS=-I/home/username/Dev/wxWidgets-3.0.2-DB6-gcc493/lib/wx/include/gtk2-unicode-3.0;-I/home/username/Dev/wxWidgets-3.0.2-DB6-gcc493/include/wx-3.0;-D_FILE_OFFSET_BITS=64;-DWXUSINGDLL;-D__WXGTK__;-pthread
we end up with:
wxWidgets_DEFINITIONS=B6-gcc493/lib/wx/include/gtk2-unicode-3.0;B6-gcc493/include/wx-3.0;_FILE_OFFSET_BITS=64;WXUSINGDLL;__WXGTK__`
wxWidgets_INCLUDE_DIRS=/home/username/Dev/wxWidgets-3.0.2/home/username/Dev/wxWidgets-3.0.2-pthread
and it later fails to find wx/version.h.
One way to fix this would be to use slightly different regular expressions to only match -D and -I when at the start of the string or preceded with a semi-column (so something like "(^|;)-D").
My suggestion is to use list to do part of the work though as it is slightly simpler:
# parse definitions from cxxflags;
# drop -D* from CXXFLAGS and the -D prefix
set(wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
list(FILTER wxWidgets_DEFINITIONS INCLUDE REGEX "^-D")
list(FILTER wxWidgets_CXX_FLAGS EXCLUDE REGEX "^-D")
string(REGEX REPLACE "(;|^)-D" "\\1"
wxWidgets_DEFINITIONS "${wxWidgets_DEFINITIONS}")
# parse include dirs from cxxflags; drop -I prefix
set(wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
list(FILTER wxWidgets_INCLUDE_DIRS INCLUDE REGEX "^-I")
list(FILTER wxWidgets_CXX_FLAGS EXCLUDE REGEX "^-I")
string(REGEX REPLACE "(;|^)-I" "\\1"
wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")