cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.
MIT License
3.07k stars 188 forks source link

Unitialized variable warnings #436

Open FuturehomeDinoSaric opened 1 year ago

FuturehomeDinoSaric commented 1 year ago

When using the latest version of CPM.cmake (0.37.0) and configuring the cmake with flags --warn-unused-vars and --warn-uninitialized I get warnings:

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:105 (option):
  uninitialized variable 'CPM_USE_LOCAL_PACKAGES'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:108 (option):
  uninitialized variable 'CPM_LOCAL_PACKAGES_ONLY'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:111 (option):
  uninitialized variable 'CPM_DOWNLOAD_ALL'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:112 (option):
  uninitialized variable 'CPM_DONT_UPDATE_MODULE_PATH'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:115 (option):
  uninitialized variable 'CPM_DONT_CREATE_PACKAGE_LOCK'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:118 (option):
  uninitialized variable 'CPM_INCLUDE_ALL_IN_PACKAGE_LOCK'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:122 (option):
  uninitialized variable 'CPM_USE_NAMED_CACHE_DIRECTORIES'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:622 (if):
  uninitialized variable 'CPM_Catch2_SOURCE'
Call Stack (most recent call first):
  test/CMakeLists.txt:3 (CPMAddPackage)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:639 (if):
  uninitialized variable 'CPM_DECLARATION_Catch2'
Call Stack (most recent call first):
  test/CMakeLists.txt:3 (CPMAddPackage)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- CPM: Adding package Catch2@3.3.1 (v3.3.1)
CMake Warning (dev) at cmake-build-debug-armv6/_deps/catch2-src/CMake/CatchConfigOptions.cmake:71 (set):
  uninitialized variable 'BUILD_SHARED_LIBS'
Call Stack (most recent call first):
  cmake-build-debug-armv6/_deps/catch2-src/CMakeLists.txt:55 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Performing Test HAVE_FLAG__ffile_prefix_map__home_lola_Desktop_future_home_core_vinculum_cmake_build_debug_armv6__deps_catch2_src__
-- Performing Test HAVE_FLAG__ffile_prefix_map__home_lola_Desktop_future_home_core_vinculum_cmake_build_debug_armv6__deps_catch2_src__ - Success
CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:796 (if):
  uninitialized variable 'download_directory'
Call Stack (most recent call first):
  test/CMakeLists.txt:3 (CPMAddPackage)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
TheLartians commented 1 year ago

Hey, thanks for raising the issue! I wasn't aware of these checks and agree that CPM should not create warnings if possible. Once we manage to resolve it, probably it would be a good idea to add these checks in CI as well.

fng97 commented 1 year ago

I believe I'm having the same problem. I tried bumping CPM to v0.38.1 and using the SYSTEM keyword to resolve this but it did not. Would you expect that to fix this or is it a separate issue?

TheLartians commented 1 year ago

I don't think setting the SYSTEM keyword would help here, we rather should initialise the variables with reasonable defaults.

fng97 commented 1 year ago

I don't think setting the SYSTEM keyword would help here, we rather should initialise the variables with reasonable defaults.

Sorry, still very new to CMake. I'm not too sure what you mean by the above. However, the following fixed my problem. I suppressed the warning emitted by the dependency using target_compile_options. Does this seem appropriate to you?

CPMAddPackage("gh:pboettch/json-schema-validator#2.2.0")

target_compile_options(nlohmann_json_schema_validator PRIVATE -Wno-error=unused-const-variable)
TheLartians commented 1 year ago

@fng97 I think we're confusing warnings coming from CMake and the C / C++ compiler. From my understanding this issue is about CMake warning that CPM specific variables are not properly initialised in CMake. Your fix targets compiler options relevant for building the actual C / C++ source code.

fng97 commented 1 year ago

@TheLartians

@fng97 I think we're confusing warnings coming from CMake and the C / C++ compiler. From my understanding this issue is about CMake warning that CPM specific variables are not properly initialised in CMake. Your fix targets compiler options relevant for building the actual C / C++ source code.

Oops, I think you're right 😅

ChrisThrasher commented 2 months ago

I would like to bump this issue as I'm still encountering these warnings in the latest release. I think it would be a great user experience benefit to address this.