I'm working on a C++ project that uses wxWidgets with a CMake script I wrote to resolve this dependency when I build it. To accomplish that I used CMake's module FetchContent and it currently works properly, resolving the dependency, compiling and running.
However, it keeps showing me warnings relative to the wxWidgets files and I do not desire that, since it mixes with my code's warnings, making it hard for me to track them down and resolve them (VS Code showed over a thousand warnings in my project).
Right now my CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(my_project LANGUAGES CXX)
# Using C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Use wxWidgets static libraries
set(wxWidgets_USE_STATIC 1)
set(wxBUILD_SHARED OFF)
# Include FetchContent module
include(FetchContent)
# Fetch wxWidgets dependency statement declaration
FetchContent_Declare(
wxWidgets
GIT_REPOSITORY
https://github.com/wxWidgets/wxWidgets.git
GIT_TAG
v3.1.4
)
# Message to inform user that script is not bugged, just busy resolving dependecy
message(STATUS "Baixando wxWidgets e incluindo-o no projeto")
# Effectively fetch wxWidgets dependency
FetchContent_GetProperties(wxWidgets)
if(NOT wxWidgets_POPULATED)
FetchContent_Populate(wxWidgets)
add_subdirectory(${wxwidgets_SOURCE_DIR} ${wxwidgets_BUILD_DIR})
endif()
# Include all of the program's header and source files
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_LIST_DIR}/include/*.h)
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_LIST_DIR}/source/*.cpp)
# Create program executable and link against all of the program's header and source files
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# Link wxWidgets libraries against program executable
target_include_directories(${PROJECT_NAME} PRIVATE ${wxwidgets_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE wx::base wx::core)
# Copy all assets to build directory to make them available to the program
add_custom_target(copy_assets
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/assets ${CMAKE_CURRENT_BINARY_DIR}/assets
)
add_dependencies(${PROJECT_NAME} copy_assets)
I am looking for a way to make this script apply warnings only to my code, but looking for it on the internet I haven't found anything particularly helpful (saw some similar stuff, but nothing that I could adapt to my specific case). Am I doing this whole FetchContent thing wrong? It is my first time trying anything of the kind so it is very possible. In that case, how should I do it? My intention is to link those libraries statically to my program.