cmake: move wx funcs and macros into separate file

In 2097b5aa I added a function that is used both in the non-vcpkg block
and outside of it, but the function was defined in the non-vcpkg block,
and this broke the visual studio build.

Move functions and macros into an include file so that they are globally
available.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-04-09 02:04:50 +00:00
parent 468fe26678
commit 2beb561838
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
3 changed files with 116 additions and 116 deletions

View File

@ -4,3 +4,118 @@ function(JOIN VALUES GLUE OUTPUT)
string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE) set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction() endfunction()
# convert msys paths like /c/foo to windows paths like c:/foo
# for variables set by FindWxWidgets
function(normalize_wx_paths)
if(MSYS)
unset(new_paths)
foreach(p ${wxWidgets_LIBRARY_DIRS})
execute_process(COMMAND cygpath -m "${p}" OUTPUT_VARIABLE p_win OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND new_paths "${p_win}")
endforeach()
set(wxWidgets_LIBRARY_DIRS ${new_paths} PARENT_SCOPE)
string(REGEX REPLACE "((^| )[^/]*)/([a-zA-Z])/" "\\1\\3:/" new_libs "${wxWidgets_LIBRARIES}")
set(wxWidgets_LIBRARIES ${new_libs} PARENT_SCOPE)
endif()
endfunction()
macro(cleanup_wx_vars)
if(wxWidgets_CXX_FLAGS)
list(REMOVE_ITEM wxWidgets_CXX_FLAGS -fpermissive)
endif()
endmacro()
function(cygpath var path)
execute_process(
COMMAND cygpath -m ${path}
OUTPUT_VARIABLE cyg_path
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
set(${var} ${cyg_path} PARENT_SCOPE)
endfunction()
function(check_clean_exit var)
execute_process(
COMMAND ${ARGN}
RESULT_VARIABLE exit_status
OUTPUT_QUIET
ERROR_QUIET
)
if(NOT ${exit_status} EQUAL 0)
# special case for msys2, where programs might complain about
# not being win32 programs
unset(cmd_str)
foreach(param IN LISTS ARGN)
set(cmd_str "${cmd_str} ${param}")
endforeach()
string(STRIP "${cmd_str}" cmd_str)
execute_process(
COMMAND sh -c "${cmd_str}"
RESULT_VARIABLE exit_status
OUTPUT_QUIET
ERROR_QUIET
)
endif()
set(${var} ${exit_status} PARENT_SCOPE)
endfunction()
function(find_wx_util var util)
# on win32, including cross builds we prefer the plain utility name first from PATH
if(WIN32)
set(conf_suffixes "" gtk4 gtk3)
set(major_versions "" 4 3 2)
else()
set(conf_suffixes gtk4 gtk3 "")
set(major_versions 4 3 2 "")
endif()
foreach(conf_suffix IN LISTS conf_suffixes)
foreach(major_version IN LISTS major_versions)
foreach(minor_version RANGE 100 0 -1)
unset(suffix)
if(conf_suffix)
set(suffix "-${conf_suffix}")
endif()
if(major_version)
set(suffix "${suffix}-${major_version}")
if(NOT minor_version EQUAL 0)
set(suffix "${suffix}.${minor_version}")
endif()
endif()
# find_program caches the result
set(exe NOTFOUND CACHE INTERNAL "" FORCE)
find_program(exe NAMES "${util}${suffix}")
if(EXISTS ${exe})
# check that the utility can be executed cleanly
# in case we find e.g. the wrong architecture binary
# when cross-compiling
check_clean_exit(exit_status ${exe} --help)
if(exit_status EQUAL 0)
set(${var} ${exe} PARENT_SCOPE)
return()
endif()
endif()
# don't iterate over minor versions for empty major version
if(major_version STREQUAL "")
break()
endif()
endforeach()
endforeach()
# default to util name if not found, so the error is more clear
set(${var} ${util} PARENT_SCOPE)
endforeach()
endfunction()

View File

@ -126,127 +126,12 @@ else()
# set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -luuid -lwinspool") # set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -luuid -lwinspool")
#endif() #endif()
# convert msys paths like /c/foo to windows paths like c:/foo
# for variables set by FindWxWidgets
function(normalize_wx_paths)
if(MSYS)
unset(new_paths)
foreach(p ${wxWidgets_LIBRARY_DIRS})
execute_process(COMMAND cygpath -m "${p}" OUTPUT_VARIABLE p_win OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND new_paths "${p_win}")
endforeach()
set(wxWidgets_LIBRARY_DIRS ${new_paths} PARENT_SCOPE)
string(REGEX REPLACE "((^| )[^/]*)/([a-zA-Z])/" "\\1\\3:/" new_libs "${wxWidgets_LIBRARIES}")
set(wxWidgets_LIBRARIES ${new_libs} PARENT_SCOPE)
endif()
endfunction()
macro(cleanup_wx_vars)
if(wxWidgets_CXX_FLAGS)
list(REMOVE_ITEM wxWidgets_CXX_FLAGS -fpermissive)
endif()
endmacro()
if(CMAKE_PREFIX_PATH) if(CMAKE_PREFIX_PATH)
set(wxWidgets_CONFIG_OPTIONS "--prefix=${CMAKE_PREFIX_PATH}") set(wxWidgets_CONFIG_OPTIONS "--prefix=${CMAKE_PREFIX_PATH}")
endif() endif()
set(wxWidgets_USE_UNICODE ON) set(wxWidgets_USE_UNICODE ON)
function(cygpath var path)
execute_process(
COMMAND cygpath -m ${path}
OUTPUT_VARIABLE cyg_path
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
set(${var} ${cyg_path} PARENT_SCOPE)
endfunction()
function(check_clean_exit var)
execute_process(
COMMAND ${ARGN}
RESULT_VARIABLE exit_status
OUTPUT_QUIET
ERROR_QUIET
)
if(NOT ${exit_status} EQUAL 0)
# special case for msys2, where programs might complain about
# not being win32 programs
unset(cmd_str)
foreach(param IN LISTS ARGN)
set(cmd_str "${cmd_str} ${param}")
endforeach()
string(STRIP "${cmd_str}" cmd_str)
execute_process(
COMMAND sh -c "${cmd_str}"
RESULT_VARIABLE exit_status
OUTPUT_QUIET
ERROR_QUIET
)
endif()
set(${var} ${exit_status} PARENT_SCOPE)
endfunction()
function(find_wx_util var util)
# on win32, including cross builds we prefer the plain utility name first from PATH
if(WIN32)
set(conf_suffixes "" gtk4 gtk3)
set(major_versions "" 4 3 2)
else()
set(conf_suffixes gtk4 gtk3 "")
set(major_versions 4 3 2 "")
endif()
foreach(conf_suffix IN LISTS conf_suffixes)
foreach(major_version IN LISTS major_versions)
foreach(minor_version RANGE 100 0 -1)
unset(suffix)
if(conf_suffix)
set(suffix "-${conf_suffix}")
endif()
if(major_version)
set(suffix "${suffix}-${major_version}")
if(NOT minor_version EQUAL 0)
set(suffix "${suffix}.${minor_version}")
endif()
endif()
# find_program caches the result
set(exe NOTFOUND CACHE INTERNAL "" FORCE)
find_program(exe NAMES "${util}${suffix}")
if(EXISTS ${exe})
# check that the utility can be executed cleanly
# in case we find e.g. the wrong architecture binary
# when cross-compiling
check_clean_exit(exit_status ${exe} --help)
if(exit_status EQUAL 0)
set(${var} ${exe} PARENT_SCOPE)
return()
endif()
endif()
# don't iterate over minor versions for empty major version
if(major_version STREQUAL "")
break()
endif()
endforeach()
endforeach()
# default to util name if not found, so the error is more clear
set(${var} ${util} PARENT_SCOPE)
endforeach()
endfunction()
# Check for gtk4 then gtk3 packages first, some dists like arch rename the # Check for gtk4 then gtk3 packages first, some dists like arch rename the
# wx-config utility for these packages to e.g. wx-config-gtk3 # wx-config utility for these packages to e.g. wx-config-gtk3
# #

2
vcpkg

@ -1 +1 @@
Subproject commit c2ad1baafccc91bf7e9e60a390eb91cf4e130062 Subproject commit b5ae25cf3d1e8c28095f5379f18f1a47390b33a0