Merge pull request #5316 from ligfx/cmakewxwidgets

Various CMake cleanups for DolphinWX
This commit is contained in:
Mat M 2017-04-25 21:21:54 -04:00 committed by GitHub
commit 255fd14db6
3 changed files with 130 additions and 194 deletions

View File

@ -789,79 +789,27 @@ if(NOT ANDROID)
endif() endif()
if(NOT DISABLE_WX) if(NOT DISABLE_WX)
find_package(wxWidgets COMPONENTS core aui adv) find_package(wxWidgets 3.1.0 COMPONENTS core aui adv)
if(_ARCH_32) if(_ARCH_32)
add_definitions(-DwxSIZE_T_IS_UINT) add_definitions(-DwxSIZE_T_IS_UINT)
endif() endif()
if(wxWidgets_FOUND) if(wxWidgets_FOUND)
EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
${wxWidgets_CONFIG_OPTIONS} --version
OUTPUT_VARIABLE wxWidgets_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
message(STATUS "Found wxWidgets version ${wxWidgets_VERSION}")
set(wxMIN_VERSION "3.1.0")
if(${wxWidgets_VERSION} VERSION_LESS ${wxMIN_VERSION})
message(STATUS "At least ${wxMIN_VERSION} is required; ignoring found version")
unset(wxWidgets_FOUND)
endif()
endif()
if(UNIX AND NOT APPLE AND NOT HAIKU)
# There is a bug in the FindGTK module in cmake version 2.8.2 that
# does not find gdk-pixbuf-2.0. On the other hand some 2.8.3
# users have complained that pkg-config does not find
# gdk-pixbuf-2.0. On yet another hand, cmake version 2.8.3 in
# Ubuntu Natty does not find the glib libraries correctly.
# Ugly!!!
execute_process(COMMAND lsb_release -c -s
OUTPUT_VARIABLE DIST_NAME
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}
VERSION_EQUAL 2.8.2 OR "${DIST_NAME}" STREQUAL "natty")
check_lib(GTK2 gtk+-2.0 gtk+-2.0 gtk.h REQUIRED)
else()
find_package(GTK2)
if(GTK2_FOUND)
include_directories(${GTK2_INCLUDE_DIRS})
list(APPEND LIBS ${GTK2_LIBRARIES})
else()
message(FATAL_ERROR "GTK is required to build the WX UI. Please install the GTK development libraries.")
endif()
endif()
endif()
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
message(STATUS "wxWidgets found, enabling GUI build") message(STATUS "wxWidgets found, enabling GUI build")
if(NOT TARGET wxWidgets::wxWidgets)
add_library(wxWidgets::wxWidgets INTERFACE IMPORTED)
set_target_properties(wxWidgets::wxWidgets PROPERTIES
INTERFACE_LINK_LIBRARIES "${wxWidgets_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${wxWidgets_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${wxWidgets_DEFINITIONS}"
INTERFACE_COMPILE_OPTIONS "${wxWidgets_CXX_FLAGS}"
)
endif()
else() else()
message(STATUS "Using static wxWidgets from Externals") message(STATUS "Using static wxWidgets from Externals")
# These definitions and includes are used when building dolphin against wx,
# not when building wx itself (see wxw3 CMakeLists.txt for that)
if(APPLE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD")
# Check for required libs
check_lib(GTHREAD2 gthread-2.0 gthread-2.0 glib/gthread.h REQUIRED)
check_lib(PANGOCAIRO pangocairo pangocairo pango/pangocairo.h REQUIRED)
# On Linux "backtrace" is part of glibc. FreeBSD has a separate library.
# Required for wxUSE_STACKWALKER in Externals/wxWidgets3/wx/wxgtk.h
find_package(Backtrace REQUIRED)
elseif(WIN32)
else()
message(FATAL_ERROR "wxWidgets in Externals is not compatible with your platform")
endif()
include_directories(SYSTEM
Externals/wxWidgets3
Externals/wxWidgets3/include)
add_subdirectory(Externals/wxWidgets3) add_subdirectory(Externals/wxWidgets3)
set(wxWidgets_FOUND TRUE) set(wxWidgets_FOUND TRUE)
set(wxWidgets_LIBRARIES "wx")
endif() endif()
endif() endif()

View File

@ -818,23 +818,20 @@ set(SRCS_UNIXGTK
"src/unix/uiactionx11.cpp" "src/unix/uiactionx11.cpp"
"src/unix/utilsx11.cpp") "src/unix/utilsx11.cpp")
include_directories(.) add_library(wx STATIC ${SRCS_AUI} ${SRCS_COMMON} ${SRCS_GENERIC})
include_directories(include) target_include_directories(wx PUBLIC . include)
target_compile_definitions(wx PRIVATE "WXBUILDING")
set(SRCS # wxWidgets warnings are not our problem.
${SRCS_AUI} target_compile_options(wx PRIVATE "-w")
${SRCS_COMMON}
${SRCS_GENERIC})
if(APPLE) if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98") target_compile_definitions(wx PRIVATE "__WXOSX_COCOA__")
add_definitions(-D__WXOSX_COCOA__) target_sources(wx PRIVATE
set(SRCS
${SRCS}
${SRCS_GENERICOSX} ${SRCS_GENERICOSX}
${SRCS_OSX} ${SRCS_OSX}
${SRCS_UNIX}) ${SRCS_UNIX}
set(LIBS )
target_link_libraries(wx PRIVATE
png png
iconv iconv
${APPKIT_LIBRARY} ${APPKIT_LIBRARY}
@ -847,23 +844,32 @@ if(APPLE)
${OPENGL_LIBRARY} ${OPENGL_LIBRARY}
) )
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") target_compile_options(wx PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++11>")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-D__LINUX__=1) target_compile_definitions(wx PRIVATE "__LINUX__=1")
else() else()
add_definitions(-D__BSD__=1) target_compile_definitions(wx PRIVATE "__BSD__=1")
endif() endif()
add_definitions(-D__WXGTK__) target_compile_definitions(wx PRIVATE "__WXGTK__")
set(SRCS target_sources(wx PRIVATE
${SRCS}
${SRCS_GENERICGTK} ${SRCS_GENERICGTK}
${SRCS_GTK} ${SRCS_GTK}
${SRCS_UNIX} ${SRCS_UNIX}
${SRCS_UNIXGTK}) ${SRCS_UNIXGTK}
)
if (NOT X11_xf86vmode_FOUND OR NOT X11_Xinerama_FOUND) if (NOT X11_xf86vmode_FOUND OR NOT X11_Xinerama_FOUND)
message(FATAL_ERROR "wxGTK2 needs Xinerama and Xxf86vm") message(FATAL_ERROR "wxGTK2 needs Xinerama and Xxf86vm")
endif() endif()
set(LIBS
find_package(GTK2 REQUIRED)
check_lib(GTHREAD2 gthread-2.0 gthread-2.0 glib/gthread.h REQUIRED)
check_lib(PANGOCAIRO pangocairo pangocairo pango/pangocairo.h REQUIRED)
# On Linux "backtrace" is part of glibc. FreeBSD has a separate library.
# Required for wxUSE_STACKWALKER in Externals/wxWidgets3/wx/wxgtk.h
find_package(Backtrace REQUIRED)
target_include_directories(wx PUBLIC ${GTK2_INCLUDE_DIRS})
target_link_libraries(wx PRIVATE
png png
${GTHREAD2_LIBRARIES} ${GTHREAD2_LIBRARIES}
${PANGOCAIRO_LIBRARIES} ${PANGOCAIRO_LIBRARIES}
@ -871,25 +877,22 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD")
${Backtrace_LIBRARY} ${Backtrace_LIBRARY}
${X11_X11_LIB} ${X11_X11_LIB}
${X11_Xxf86vm_LIB} ${X11_Xxf86vm_LIB}
${X11_Xinerama_LIB}) ${X11_Xinerama_LIB}
else() )
add_definitions(-D__WXMSW__) elseif(WIN32)
add_definitions(-DNOPCH)
remove_definitions(-DWIN32_LEAN_AND_MEAN) remove_definitions(-DWIN32_LEAN_AND_MEAN)
set(SRCS target_compile_definitions(wx PRIVATE "__WXMSW__" "NOPCH")
${SRCS} target_sources(wx PRIVATE
${SRCS_GENERICMSW} ${SRCS_GENERICMSW}
${SRCS_MSW}) ${SRCS_MSW}
set(LIBS )
Comctl32.lib target_link_libraries(wx PRIVATE
Comctl32.lib
Rpcrt4.lib Rpcrt4.lib
${OPENGL_LIBRARIES} ${OPENGL_LIBRARIES}
) )
else()
message(FATAL_ERROR "wxWidgets in Externals is not compatible with your platform")
endif() endif()
add_definitions(-DWXBUILDING) add_library(wxWidgets::wxWidgets ALIAS wx)
# wxWidgets warnings are not our problem.
add_definitions(-w)
add_library(wx STATIC ${PNG_SRCS} ${SRCS})
target_link_libraries(wx ${LIBS})

View File

@ -1,4 +1,8 @@
set(GUI_SRCS if(NOT wxWidgets_FOUND)
return()
endif()
set(SRCS
AboutDolphin.cpp AboutDolphin.cpp
ControllerConfigDiag.cpp ControllerConfigDiag.cpp
Cheats/ActionReplayCodesPanel.cpp Cheats/ActionReplayCodesPanel.cpp
@ -78,21 +82,14 @@ set(GUI_SRCS
WxUtils.cpp WxUtils.cpp
) )
set(WXLIBS ${wxWidgets_LIBRARIES}) set(LIBS
core
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") uicommon
set(WXLIBS ${WXLIBS} dl) cpp-optparse
endif() wxWidgets::wxWidgets
)
list(APPEND LIBS core uicommon cpp-optparse)
if(APPLE) if(APPLE)
if(wxWidgets_FOUND)
list(APPEND WXLIBS
${APPSERV_LIBRARY}
${COCOA_LIBRARY}
)
endif()
# Add resource files to application bundle. # Add resource files to application bundle.
set(RESOURCES resources/Dolphin.icns) set(RESOURCES resources/Dolphin.icns)
list(APPEND SRCS ${RESOURCES}) list(APPEND SRCS ${RESOURCES})
@ -107,88 +104,76 @@ if(WIN32)
) )
endif() endif()
add_executable(dolphin-emu ${SRCS})
target_link_libraries(dolphin-emu ${LIBS})
# Handle localization
find_package(Gettext)
if(GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE)
set(pot_file "${CMAKE_SOURCE_DIR}/Languages/po/dolphin-emu.pot")
file(GLOB LINGUAS ${CMAKE_SOURCE_DIR}/Languages/po/*.po)
target_sources(dolphin-emu PRIVATE ${pot_file} ${LINGUAS})
source_group("Localization" FILES ${LINGUAS})
source_group("Localization\\\\Generated" FILES ${pot_file})
foreach(po ${LINGUAS})
get_filename_component(lang ${po} NAME_WE)
set(mo_dir ${CMAKE_CURRENT_BINARY_DIR}/${lang})
set(mo ${mo_dir}/dolphin-emu.mo)
target_sources(dolphin-emu PRIVATE ${mo})
source_group("Localization\\\\Generated" FILES ${mo})
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_source_files_properties(${mo} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${lang}.lproj")
else()
install(FILES ${mo} DESTINATION share/locale/${lang}/LC_MESSAGES)
endif()
add_custom_command(OUTPUT ${mo}
COMMAND mkdir -p ${mo_dir}
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${po} ${pot_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
DEPENDS ${po}
)
endforeach()
endif()
if(APPLE) if(APPLE)
set(DOLPHIN_EXE_BASE Dolphin) # Ask for an application bundle.
set_target_properties(dolphin-emu PROPERTIES
MACOSX_BUNDLE true
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in
OUTPUT_NAME Dolphin
)
# Copy resources in the bundle
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/Data/Sys")
file(GLOB_RECURSE resources RELATIVE "${CMAKE_SOURCE_DIR}/Data" "${CMAKE_SOURCE_DIR}/Data/Sys/*")
foreach(res ${resources})
target_sources(dolphin-emu PRIVATE "${CMAKE_SOURCE_DIR}/Data/${res}")
get_filename_component(resdir "${res}" DIRECTORY)
set_source_files_properties("${CMAKE_SOURCE_DIR}/Data/${res}" PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources/${resdir}")
source_group("Resources" FILES "${CMAKE_SOURCE_DIR}/Data/${res}")
endforeach()
# Update library references to make the bundle portable
include(DolphinPostprocessBundle)
dolphin_postprocess_bundle(dolphin-emu)
# Install bundle into systemwide /Applications directory.
install(TARGETS dolphin-emu DESTINATION /Applications)
elseif(WIN32)
set_target_properties(dolphin-emu PROPERTIES
WIN32_EXECUTABLE ON
)
add_custom_command(TARGET dolphin-emu
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Data/Sys $<TARGET_FILE_DIR:dolphin-emu>/Sys
)
else() else()
set(DOLPHIN_EXE_BASE dolphin-emu) install(TARGETS dolphin-emu RUNTIME DESTINATION ${bindir})
endif() endif()
set(DOLPHIN_EXE ${DOLPHIN_EXE_BASE}) set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} dolphin-emu)
if(wxWidgets_FOUND)
add_executable(${DOLPHIN_EXE} ${SRCS} ${GUI_SRCS})
target_link_libraries(${DOLPHIN_EXE} ${LIBS} ${WXLIBS})
# Handle localization
find_package(Gettext)
if(GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE)
set(pot_file "${CMAKE_SOURCE_DIR}/Languages/po/dolphin-emu.pot")
file(GLOB LINGUAS ${CMAKE_SOURCE_DIR}/Languages/po/*.po)
target_sources(${DOLPHIN_EXE} PRIVATE ${pot_file} ${LINGUAS})
source_group("Localization" FILES ${LINGUAS})
source_group("Localization\\\\Generated" FILES ${pot_file})
foreach(po ${LINGUAS})
get_filename_component(lang ${po} NAME_WE)
set(mo_dir ${CMAKE_CURRENT_BINARY_DIR}/${lang})
set(mo ${mo_dir}/dolphin-emu.mo)
target_sources(${DOLPHIN_EXE} PRIVATE ${mo})
source_group("Localization\\\\Generated" FILES ${mo})
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_source_files_properties(${mo} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${lang}.lproj")
else()
install(FILES ${mo} DESTINATION share/locale/${lang}/LC_MESSAGES)
endif()
add_custom_command(OUTPUT ${mo}
COMMAND mkdir -p ${mo_dir}
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${po} ${pot_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
DEPENDS ${po}
)
endforeach()
endif()
if(APPLE)
set(BUNDLE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DOLPHIN_EXE}.app)
# Ask for an application bundle.
set_target_properties(${DOLPHIN_EXE} PROPERTIES
MACOSX_BUNDLE true
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in
)
# Copy resources in the bundle
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/Data/Sys")
file(GLOB_RECURSE resources RELATIVE "${CMAKE_SOURCE_DIR}/Data" "${CMAKE_SOURCE_DIR}/Data/Sys/*")
foreach(res ${resources})
target_sources(${DOLPHIN_EXE} PRIVATE "${CMAKE_SOURCE_DIR}/Data/${res}")
get_filename_component(resdir "${res}" DIRECTORY)
set_source_files_properties("${CMAKE_SOURCE_DIR}/Data/${res}" PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources/${resdir}")
source_group("Resources" FILES "${CMAKE_SOURCE_DIR}/Data/${res}")
endforeach()
# Update library references to make the bundle portable
include(DolphinPostprocessBundle)
dolphin_postprocess_bundle(${DOLPHIN_EXE})
# Install bundle into systemwide /Applications directory.
install(TARGETS ${DOLPHIN_EXE} DESTINATION /Applications)
elseif(WIN32)
set_target_properties(${DOLPHIN_EXE} PROPERTIES
WIN32_EXECUTABLE ON
)
add_custom_command(TARGET ${DOLPHIN_EXE}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Data/Sys $<TARGET_FILE_DIR:${DOLPHIN_EXE}>/Sys
)
else()
install(TARGETS ${DOLPHIN_EXE} RUNTIME DESTINATION ${bindir})
endif()
set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} ${DOLPHIN_EXE})
endif()