cmake: try to validate the user option

* GTK3_API requires a wxWidget that support it too
=> avoid complexe compilation error
* SDL2_API requires a wxWidget without SDL support (wxUSE_LIBSDL = 0)
=> avoid run time  crash

SDL check hypothesis: wx is linked against SDL1.2 and not SDL2. It would need to be improved on a distant future
This commit is contained in:
Gregory Hainaut 2015-01-04 20:38:36 +01:00
parent 0346da2fa0
commit 90d27bf5f6
2 changed files with 69 additions and 0 deletions

61
cmake/ApiValidation.cmake Normal file
View File

@ -0,0 +1,61 @@
set(wx_sdl_c_code "
#include <wx/setup.h>
#if (wxUSE_LIBSDL != 0)
#error cmake_WX_SDL
#endif
")
set(wx_gtk3_c_code "
#include <wx/setup.h>
#ifdef __WXGTK3__
#error cmake_WX_GTK3
#endif
")
function(WX_vs_SDL)
file(WRITE "${CMAKE_BINARY_DIR}/wx_sdl.c" "${wx_sdl_c_code}")
enable_language(C)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/wx_sdl.c"
COMPILE_OUTPUT_VARIABLE OUT
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${wxWidgets_INCLUDE_DIRS}"
)
if (${OUT} MATCHES "cmake_WX_SDL" AND SDL2_API)
message(FATAL_ERROR "WxWidget is linked to SDL (wxUSE_LIBSDL) and it is likely SDL1.2.
Unfortunately you try to build PCSX2 with SDL2 support which is not compatible
Please use -DSDL2_API=FALSE")
endif()
endfunction()
function(WX_vs_GTK3)
file(WRITE "${CMAKE_BINARY_DIR}/wx_gtk3.c" "${wx_gtk3_c_code}")
enable_language(C)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/wx_gtk3.c"
COMPILE_OUTPUT_VARIABLE OUT
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${wxWidgets_INCLUDE_DIRS}"
)
if (${OUT} MATCHES "cmake_WX_GTK3")
if (NOT GTK3_API)
message(FATAL_ERROR "Your current WxWidget version requires GTK3. Please use -DGTK3_API=TRUE option")
endif()
else()
if (GTK3_API)
message(FATAL_ERROR "Your current WxWidget version doesn't support GTK3. Please use -DGTK3_API=FALSE option")
endif()
endif()
endfunction()

View File

@ -140,3 +140,11 @@ include_directories(${CMAKE_SOURCE_DIR}/common/include
# File generated by Cmake
${CMAKE_BINARY_DIR}/common/include
)
#----------------------------------------
# Check correctness of the parameter
# Note: wxWidgets_INCLUDE_DIRS must be defined
#----------------------------------------
include(ApiValidation)
WX_vs_SDL()
WX_vs_GTK3()