improve wx GCC ABI check #142

Following some suggestions from @ArtiiP, first check if there are no
issues without an -fabi-version flag, and then instead of incrementing
from 0, decrement from 15 to find the highest working ABI version.

This is very slow if the needed ABI version is 2 for example, but not
much to do about that for the time being.
This commit is contained in:
Rafael Kitover 2017-09-04 12:28:24 -07:00
parent b1937fe9cb
commit ceef480e70
1 changed files with 44 additions and 27 deletions

View File

@ -110,20 +110,7 @@ ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
INCLUDE(CheckCXXSourceRuns)
UNSET(WX_ABI_MATCHES)
SET(WX_ABI_VERSION 0)
SET(CURRENT_DEFS ${CMAKE_REQUIRED_DEFINITIONS})
SET(CURRENT_LIBS ${CMAKE_REQUIRED_LIBRARIES})
# currently goes up to 11 with gcc7, but we give it some room
WHILE(NOT WX_ABI_VERSION GREATER 15)
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS} "-fabi-version=${WX_ABI_VERSION}")
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS} "-fabi-version=${WX_ABI_VERSION}")
SET(WX_ABI_VAR "WX_ABI_VERSION_${WX_ABI_VERSION}")
CHECK_CXX_SOURCE_RUNS("
CHECK_CXX_SOURCE_RUNS("
#include <cstdlib>
#include <wx/wx.h>
@ -137,22 +124,52 @@ bool MyApp::OnInit() {
}
wxIMPLEMENT_APP(MyApp);
" ${WX_ABI_VAR})
" WX_DEFAULT_ABI_VERSION_COMPATIBLE)
IF(NOT WX_DEFAULT_ABI_VERSION_COMPATIBLE)
# currently goes up to 11 with gcc7, but we give it some room
SET(WX_ABI_VERSION 15)
SET(CURRENT_DEFS ${CMAKE_REQUIRED_DEFINITIONS})
SET(CURRENT_LIBS ${CMAKE_REQUIRED_LIBRARIES})
WHILE(NOT WX_ABI_VERSION EQUAL -1)
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS} "-fabi-version=${WX_ABI_VERSION}")
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS} "-fabi-version=${WX_ABI_VERSION}")
SET(WX_ABI_VAR "WX_ABI_VERSION_${WX_ABI_VERSION}")
CHECK_CXX_SOURCE_RUNS("
#include <cstdlib>
#include <wx/wx.h>
class MyApp : public wxAppConsole {
public:
virtual bool OnInit();
};
bool MyApp::OnInit() {
exit(0);
}
wxIMPLEMENT_APP(MyApp);
" ${WX_ABI_VAR})
IF(${${WX_ABI_VAR}})
BREAK()
ENDIF()
MATH(EXPR WX_ABI_VERSION "${WX_ABI_VERSION} - 1")
ENDWHILE()
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS})
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS})
IF(${${WX_ABI_VAR}})
BREAK()
# add C++ flags
STRING(REGEX REPLACE "<FLAGS>" "<FLAGS> -fabi-version=${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT})
SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -fabi-version=${WX_ABI_VERSION}")
ENDIF()
MATH(EXPR WX_ABI_VERSION "${WX_ABI_VERSION} + 1")
ENDWHILE()
SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_DEFS})
SET(CMAKE_REQUIRED_LIBRARIES ${CURRENT_LIBS})
IF(${${WX_ABI_VAR}} AND (NOT WX_ABI_VERSION EQUAL 0))
# add C++ flags
STRING(REGEX REPLACE "<FLAGS>" "<FLAGS> -fabi-version=${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT})
SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -fabi-version=${WX_ABI_VERSION}")
ENDIF()
ENDIF()