Fix monolithic build in cmake (wxBUILD_MONOLITHIC)
- Functions that set wxMONO_* vars need to set them in parent scope, from macros instead of functions (functions would need grandparent scope) - Fix a conflict with xml library linking Mono which made core include the wrong png headers - Fix setting of NOPCH on windows to go through the wx_lib_compile_definitions instead of target_compile_definitions so it carries to monolithic build - Allow use of precompiled header in MSVC via calling wx_finalize_lib(mono) - Introduce wxMONO_NONCOMPILED_CPP_FILES to deal with set_source_files_properties only applying within the current CMakeLists file - Fix demos building against monolithic library by using wx_exe_link_libraries instead of target_link_libraries (similar to what the tests already do) Closes #18074
This commit is contained in:
@@ -35,7 +35,7 @@ function(wx_add_demo name)
|
||||
if(wxBUILD_SHARED)
|
||||
target_compile_definitions(${DEMO_NAME} PRIVATE WXUSINGDLL)
|
||||
endif()
|
||||
target_link_libraries(${DEMO_NAME} core ${DEMO_LIBRARIES})
|
||||
wx_exe_link_libraries(${DEMO_NAME} core ${DEMO_LIBRARIES})
|
||||
wx_set_common_target_properties(${DEMO_NAME})
|
||||
set_target_properties(${DEMO_NAME} PROPERTIES FOLDER "Demos")
|
||||
set_target_properties(${DEMO_NAME} PROPERTIES
|
||||
|
@@ -20,19 +20,24 @@ include(CMakePrintHelpers)
|
||||
|
||||
# This function adds a list of headers to a variable while prepending
|
||||
# include/ to the path
|
||||
function(wx_add_headers src_var)
|
||||
macro(wx_add_headers src_var)
|
||||
set(headers)
|
||||
list(REMOVE_AT ARGV 0)
|
||||
foreach(header ${ARGV})
|
||||
foreach(header ${ARGN})
|
||||
list(APPEND headers ${wxSOURCE_DIR}/include/${header})
|
||||
if(header MATCHES "\\.cpp$")
|
||||
# .cpp files in include directory should not be compiled
|
||||
set_source_files_properties(${wxSOURCE_DIR}/include/${header}
|
||||
PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
if (wxBUILD_MONOLITHIC)
|
||||
# set_source_files_properties only works within the same CMakeLists.txt
|
||||
list(APPEND wxMONO_NONCOMPILED_CPP_FILES ${wxSOURCE_DIR}/include/${header})
|
||||
set(wxMONO_NONCOMPILED_CPP_FILES ${wxMONO_NONCOMPILED_CPP_FILES} PARENT_SCOPE)
|
||||
else()
|
||||
set_source_files_properties(${wxSOURCE_DIR}/include/${header}
|
||||
PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
set(${src_var} ${${src_var}} ${headers} PARENT_SCOPE)
|
||||
endfunction()
|
||||
list(APPEND ${src_var} ${headers})
|
||||
endmacro()
|
||||
|
||||
# Add sources from a ..._SRC variable and headers from a ..._HDR
|
||||
macro(wx_append_sources src_var source_base_name)
|
||||
@@ -269,45 +274,45 @@ endfunction()
|
||||
# first parameter is the name of the library
|
||||
# if the second parameter is set to IS_BASE a non UI lib is created
|
||||
# all additional parameters are source files for the library
|
||||
function(wx_add_library name)
|
||||
macro(wx_add_library name)
|
||||
cmake_parse_arguments(wxADD_LIBRARY "IS_BASE" "" "" ${ARGN})
|
||||
set(src_files ${wxADD_LIBRARY_UNPARSED_ARGUMENTS})
|
||||
|
||||
if(wxBUILD_MONOLITHIC AND NOT name STREQUAL "mono")
|
||||
if(wxBUILD_MONOLITHIC AND NOT ${name} STREQUAL "mono")
|
||||
# collect all source files for mono library
|
||||
set(wxMONO_SRC_FILES ${wxMONO_SRC_FILES} ${src_files} PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(wxBUILD_PRECOMP AND MSVC)
|
||||
# Add dummy source file to be used by cotire for PCH creation
|
||||
list(INSERT src_files 0 "${wxSOURCE_DIR}/src/common/dummy.cpp")
|
||||
endif()
|
||||
list(APPEND src_files ${wxSETUP_HEADER_FILE})
|
||||
|
||||
if(wxBUILD_SHARED)
|
||||
set(wxBUILD_LIB_TYPE SHARED)
|
||||
if(WIN32)
|
||||
# Add WIN32 version information
|
||||
list(APPEND src_files "${wxSOURCE_DIR}/src/msw/version.rc" "${wxSOURCE_DIR}/include/wx/msw/genrcdefs.h")
|
||||
endif()
|
||||
else()
|
||||
set(wxBUILD_LIB_TYPE STATIC)
|
||||
|
||||
if(wxBUILD_PRECOMP AND MSVC)
|
||||
# Add dummy source file to be used by cotire for PCH creation
|
||||
list(INSERT src_files 0 "${wxSOURCE_DIR}/src/common/dummy.cpp")
|
||||
endif()
|
||||
list(APPEND src_files ${wxSETUP_HEADER_FILE})
|
||||
|
||||
if(wxBUILD_SHARED)
|
||||
set(wxBUILD_LIB_TYPE SHARED)
|
||||
if(WIN32)
|
||||
# Add WIN32 version information
|
||||
list(APPEND src_files "${wxSOURCE_DIR}/src/msw/version.rc" "${wxSOURCE_DIR}/include/wx/msw/genrcdefs.h")
|
||||
endif()
|
||||
else()
|
||||
set(wxBUILD_LIB_TYPE STATIC)
|
||||
endif()
|
||||
|
||||
add_library(${name} ${wxBUILD_LIB_TYPE} ${src_files})
|
||||
wx_set_target_properties(${name} ${wxADD_LIBRARY_IS_BASE})
|
||||
|
||||
# Setup install
|
||||
wx_install(TARGETS ${name}
|
||||
LIBRARY DESTINATION "lib${wxPLATFORM_LIB_DIR}"
|
||||
ARCHIVE DESTINATION "lib${wxPLATFORM_LIB_DIR}"
|
||||
RUNTIME DESTINATION "lib${wxPLATFORM_LIB_DIR}"
|
||||
BUNDLE DESTINATION Applications/wxWidgets
|
||||
)
|
||||
|
||||
list(APPEND wxLIB_TARGETS ${name})
|
||||
endif()
|
||||
|
||||
add_library(${name} ${wxBUILD_LIB_TYPE} ${src_files})
|
||||
wx_set_target_properties(${name} ${wxADD_LIBRARY_IS_BASE})
|
||||
|
||||
# Setup install
|
||||
wx_install(TARGETS ${name}
|
||||
LIBRARY DESTINATION "lib${wxPLATFORM_LIB_DIR}"
|
||||
ARCHIVE DESTINATION "lib${wxPLATFORM_LIB_DIR}"
|
||||
RUNTIME DESTINATION "lib${wxPLATFORM_LIB_DIR}"
|
||||
BUNDLE DESTINATION Applications/wxWidgets
|
||||
)
|
||||
|
||||
set(wxLIB_TARGETS ${wxLIB_TARGETS} ${name} PARENT_SCOPE)
|
||||
endfunction()
|
||||
endmacro()
|
||||
|
||||
# Enable cotire for target if precompiled headers are enabled
|
||||
macro(wx_target_enable_precomp target_name)
|
||||
@@ -336,13 +341,15 @@ endmacro()
|
||||
# Enable precompiled headers for wx libraries
|
||||
macro(wx_finalize_lib target_name)
|
||||
set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE)
|
||||
if(wxBUILD_PRECOMP AND TARGET ${target_name})
|
||||
target_compile_definitions(${target_name} PRIVATE WX_PRECOMP)
|
||||
set_target_properties(${target_name} PROPERTIES
|
||||
COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/include/wx/wxprec.h")
|
||||
wx_target_enable_precomp(${target_name})
|
||||
if(wxBUILD_PRECOMP)
|
||||
if(TARGET ${target_name})
|
||||
target_compile_definitions(${target_name} PRIVATE WX_PRECOMP)
|
||||
set_target_properties(${target_name} PROPERTIES
|
||||
COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/include/wx/wxprec.h")
|
||||
wx_target_enable_precomp(${target_name})
|
||||
endif()
|
||||
elseif(MSVC)
|
||||
target_compile_definitions(${target_name} PRIVATE NOPCH)
|
||||
wx_lib_compile_definitions(${target_name} PRIVATE NOPCH)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
@@ -354,6 +361,8 @@ macro(wx_lib_link_libraries name)
|
||||
cmake_parse_arguments(_LIB_LINK "" "" "PUBLIC;PRIVATE" ${ARGN})
|
||||
list(APPEND wxMONO_LIBS_PUBLIC ${_LIB_LINK_PUBLIC})
|
||||
list(APPEND wxMONO_LIBS_PRIVATE ${_LIB_LINK_PRIVATE})
|
||||
set(wxMONO_LIBS_PUBLIC ${wxMONO_LIBS_PUBLIC} PARENT_SCOPE)
|
||||
set(wxMONO_LIBS_PRIVATE ${wxMONO_LIBS_PRIVATE} PARENT_SCOPE)
|
||||
else()
|
||||
target_link_libraries(${name};${ARGN})
|
||||
endif()
|
||||
@@ -377,6 +386,8 @@ macro(wx_lib_include_directories name)
|
||||
cmake_parse_arguments(_LIB_INCLUDE_DIRS "" "" "PUBLIC;PRIVATE" ${ARGN})
|
||||
list(APPEND wxMONO_INCLUDE_DIRS_PUBLIC ${_LIB_INCLUDE_DIRS_PUBLIC})
|
||||
list(APPEND wxMONO_INCLUDE_DIRS_PRIVATE ${_LIB_INCLUDE_DIRS_PRIVATE})
|
||||
set(wxMONO_INCLUDE_DIRS_PUBLIC ${wxMONO_INCLUDE_DIRS_PUBLIC} PARENT_SCOPE)
|
||||
set(wxMONO_INCLUDE_DIRS_PRIVATE ${wxMONO_INCLUDE_DIRS_PRIVATE} PARENT_SCOPE)
|
||||
else()
|
||||
target_include_directories(${name};BEFORE;${ARGN})
|
||||
endif()
|
||||
@@ -390,6 +401,8 @@ macro(wx_lib_compile_definitions name)
|
||||
cmake_parse_arguments(_LIB_DEFINITIONS "" "" "PUBLIC;PRIVATE" ${ARGN})
|
||||
list(APPEND wxMONO_DEFINITIONS_PUBLIC ${_LIB_DEFINITIONS_PUBLIC})
|
||||
list(APPEND wxMONO_DEFINITIONS_PRIVATE ${_LIB_DEFINITIONS_PRIVATE})
|
||||
set(wxMONO_DEFINITIONS_PUBLIC ${wxMONO_DEFINITIONS_PUBLIC} PARENT_SCOPE)
|
||||
set(wxMONO_DEFINITIONS_PRIVATE ${wxMONO_DEFINITIONS_PRIVATE} PARENT_SCOPE)
|
||||
else()
|
||||
target_compile_definitions(${name};${ARGN})
|
||||
endif()
|
||||
|
@@ -17,6 +17,7 @@ if(wxBUILD_MONOLITHIC)
|
||||
set(wxMONO_LIBS_PUBLIC)
|
||||
set(wxMONO_INCLUDE_DIRS_PRIVATE)
|
||||
set(wxMONO_INCLUDE_DIRS_PUBLIC)
|
||||
set(wxMONO_NONCOMPILED_CPP_FILES)
|
||||
endif()
|
||||
|
||||
# Define third party libraries
|
||||
@@ -39,7 +40,6 @@ endmacro()
|
||||
# Define base libraries
|
||||
set(LIBS base)
|
||||
add_opt_lib(net wxUSE_SOCKETS)
|
||||
add_opt_lib(xml wxUSE_XML)
|
||||
|
||||
# Define UI libraries
|
||||
if(wxUSE_GUI)
|
||||
@@ -62,6 +62,12 @@ if(wxUSE_GUI)
|
||||
add_opt_lib(qa wxUSE_DEBUGREPORT)
|
||||
endif() # wxUSE_GUI
|
||||
|
||||
# Include XML library last
|
||||
# In the monolithic build, where all target properties (include dirs) from different targets are concatenated,
|
||||
# wxml might include system expat, which might use Mono, which has it's own copy of png.
|
||||
# Thus to ensure wx's core library includes the right png class, core must be processed first before xml
|
||||
add_opt_lib(xml wxUSE_XML)
|
||||
|
||||
# Include cmake file for every library
|
||||
foreach(LIB ${LIBS})
|
||||
add_subdirectory(${LIB})
|
||||
@@ -87,6 +93,10 @@ if(wxBUILD_MONOLITHIC)
|
||||
target_compile_definitions(mono ${vis} ${wxMONO_DEFINITIONS_${vis}})
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(file ${wxMONO_NONCOMPILED_CPP_FILES})
|
||||
set_source_files_properties(${file} PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
endforeach()
|
||||
wx_finalize_lib(mono)
|
||||
endif()
|
||||
|
||||
# Propagate variable(s) to parent scope
|
||||
|
Reference in New Issue
Block a user