bash-3.2$ cd -
/Users/clausklein/cmake/cmakelib/test_install/build
bash-3.2$ ninja
[0/1] Re-running CMake...
-- vcpkg is already installed at /Users/clausklein/vcpkg.
-- Running vcpkg install
Detecting compiler hashfor triplet x64-osx...
All requested packages are currently installed.
Restored 0 packages from /Users/clausklein/.cache/vcpkg/archives in 2.44 us. Use --debug to see more details.
Total elapsed time: 1.746 s
The package eigen3 provides CMake targets:
find_package(Eigen3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE Eigen3::Eigen)
The package fmt provides CMake targets:
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt)
# Or use the header-only version
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt-header-only)
-- Running vcpkg install - done
CMake Error at /Users/clausklein/vcpkg/scripts/buildsystems/vcpkg.cmake:782 (_find_package):
Found package configuration file:
/Users/clausklein/cmake/cmakelib/install/share/myproj_header_only_lib/myproj_header_only_libConfig.cmake
but it set myproj_header_only_lib_FOUND to FALSE so package
"myproj_header_only_lib" is considered to be NOT FOUND. Reason given by
package:
The following imported targets are referenced, but are missing:
myproj::project_options myproj::project_warnings
Call Stack (most recent call first):
CMakeLists.txt:45 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/clausklein/cmake/cmakelib/test_install/build/CMakeFiles/CMakeOutput.log".
See also "/Users/clausklein/cmake/cmakelib/test_install/build/CMakeFiles/CMakeError.log".
FAILED: CMakeFiles/impl-Debug.ninja build-Debug.ninja CMakeFiles/impl-Release.ninja build-Release.ninja CMakeFiles/impl-RelWithDebInfo.ninja build-RelWithDebInfo.ninja build.ninja
/usr/local/Cellar/cmake/3.22.1/bin/cmake --regenerate-during-build -S/Users/clausklein/cmake/cmakelib/test_install -B/Users/clausklein/cmake/cmakelib/test_install/build
ninja: error: rebuilding 'build.ninja': subcommand failed
bash-3.2$
Upvote & Fund
@aminya is using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog!
This flag fails on some ARM platforms including the Apple M1 (1, 2). We may be able to check whether it is supported by using clang -march=native -cx /dev/null (1, 2) before adding to the compile options.
Upvote & Fund
I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
There's a decent chance this is pure user error and I don't understand how to compose project_options properly, but I'm getting configure-time errors when trying to have multiple projects using project_options, specifically:
[cmake] CMake Error at build/_deps/_project_options-src/src/Index.cmake:125 (add_library):
[cmake] add_library cannot create target "project_options" because another target
[cmake] with the same name already exists. The existing target is an interface
[cmake] library created in source directory
[cmake] "/home/mcoding/Projects/project_options_multiple_include_mwe". See
[cmake] documentation for policy CMP0002 for more details.
Both project and the submodule mylib use project_options, which explains why cmake thinks project_options is being multiply defined, because both project and mylib do indeed define their own set of project options. Is this a situation where project_options should be defining target names that depend on the project name like ${PROJECT_NAME}_project_options instead of a global name project_options? Or is there some way to have project_options scoped to a namespace like mylib::project_options? Or should only the top-level project be defining project options (using an if TARGET guard before including it) with subprojects modifying the options using dynamic_project_options?
Any guidance here would be appreciated.
Here are the relevant list files for the minimal working example:
Top level CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
include(FetchContent)
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.24.1.zip)
FetchContent_MakeAvailable(_project_options)
include(${_project_options_SOURCE_DIR}/Index.cmake)
include(${_project_options_SOURCE_DIR}/src/DynamicProjectOptions.cmake)
project(myproject LANGUAGES CXX C)
dynamic_project_options()
add_subdirectory(external/mylib)
add_subdirectory(apps)
Sometimes it can be challenging to convince Conan to use the settings that you want it to. Conan allows users to use a profile to provide fine grain control over what settings Conan uses. See Conan instructions for using Emscripten for a common use case for Conan profiles.
Currently, project_options forces the user to use conan_cmake_autodetect() to determine settings automatically. A Conan profile, if desired, should replace this step, and allow the user to choose all of these settings explicitly.
What I would like: I think that a user should be allowed to pass a Conan profile as an argument to the project_options function. When that variable is not empty, project_options should skip conan_cmake_autodetect(), and call conan_cmake_install() with the argument PROFILE ${PATH_TO_CONAN_PROFILE}.
Trying to run a command such as: cmake -S . -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_DEVELOPER_MODE:BOOL=OFF -DOPT_ENABLE_COVERAGE:BOOL=ON -DOPT_ENABLE_INCLUDE_WHAT_YOU_USE:BOOL=OFF
Results in the options not being overriden.
The CMakeCache.txt contains
//Analyze and report on coverage
OPT_ENABLE_COVERAGE:INTERNAL=ON
//Enable include-what-you-use analysis during compilation
OPT_ENABLE_INCLUDE_WHAT_YOU_USE:INTERNAL=OFF
Which seems correct, but my compile_commands.json does not contain any coverage flags and digging further into this I found that when DynamicProjectOptions.cmake:130 is parsed
it overrides the command line option by the developer default or user default. In ENABLE_COVERAGE case it disables coverage in both configurations no matter what I pass to the command line
The C++23 standard initial support was in CMake 3.20. However, there seems to be some disagreement between GCC and Clang regarding the standard compiler flags.
For instance, while GCC accepts both -std=c++23 and -std=c++2b, Clang only accepts -std=c++2b. For this reason, when trying to enable clang-tidy and C++23 while compiling with GCC, Clang fails with a message indicating that the flag -std=c++23 does not exist.
I'm not sure if it's worthy fixing this, as Clang will eventually add the correct flag. Meanwhile, it prevents the user from enabling clang-tidy while compiling using GCC and C++23.
I don't know if this problem is related to this project, or if the problem is related to CMake or another tool. Anyway, I wrote here, because I am taking this project, and when I add ENABLE_COVERAGE, the coverage, for example, Experimental build target failed. If ENABLE_COVERAGE is off, the coverage step is skipped. This target is related and documented in CTest.
For easier repeating the problem and knowing what I am talking about, I am trying also in FTXUI template from cpp-best-practices, because I know @lefticus is a contributor of Ftxui and project_options and this will be the perfect project for repeating the problem. In this project, I just add ENABLE_COVERAGE in dynamic_project_options and run preset GCC Debug and target Experimental. Is the same problem if I am using different preset configurations. It is also the same if I change from dynamic_project_options to project_options. I am using VSCode and docker all the same setup is defined in the project.
The output of unixlike-clang-debug - Experimental in the project ftxui_template
[cmake] -- Generating done
[cmake] -- Build files have been written to: /workspaces/ftxui_template-main/out/build/unixlike-clang-debug
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /workspaces/ftxui_template-main/out/build/unixlike-clang-debug --target Experimental
[build] [0/1] cd /workspaces/ftxui_template-main/out/build/unixlike-clang-debug && /usr/bin/ctest -D Experimental
[build] Site: 06bc8536816d
[build] Build name: Linux-clang++
[build] Create new tag: 20220728-0821 - Experimental
[build] Configure project
[build] Each . represents 1024 bytes of output
[build] .... Size of output: 3K
[build] Build project
[build] Each symbol represents 1024 bytes of output.
[build] '!' represents an error and '*' a warning.
[build] .. Size of output: 1K
[build] 0 Compiler errors
[build] 0 Compiler warnings
[build] Test project /workspaces/ftxui_template-main/out/build/unixlike-clang-debug
[build] Start 1: unittests.Factorials are computed
[build] 1/5 Test #1: unittests.Factorials are computed .......................... Passed 0.07 sec
[build] Start 2: constexpr.Factorials are computed with constexpr
[build] 2/5 Test #2: constexpr.Factorials are computed with constexpr ........... Passed 0.07 sec
[build] Start 3: relaxed_constexpr.Factorials are computed with constexpr
[build] 3/5 Test #3: relaxed_constexpr.Factorials are computed with constexpr ... Passed 0.06 sec
[build] Start 4: cli.has_help
[build] 4/5 Test #4: cli.has_help ............................................... Passed 0.28 sec
[build] Start 5: cli.version_matches
[build] 5/5 Test #5: cli.version_matches ........................................ Passed 0.31 sec
[build]
[build] 100% tests passed, 0 tests failed out of 5
[build]
[build] Total Test time (real) = 0.90 sec
[build] Performing coverage
[build] Processing coverage (each . represents one file):
[build] No such file or directory
[build] Problem running coverage on file: /workspaces/ftxui_template-main/out/build/unixlike-clang-debug/src/CMakeFiles/intro.dir/main.cpp.gcda
[build] Command produced error: No such file or directory
[build] Cannot find any coverage files. Ignoring Coverage request.
The problem is in /workspaces/ftxui_template-main/out/build/unixlike-clang-debug/src/CMakeFiles/intro.dir exist .gcda, .gcno and .o file.
So my question is if I am doing something wrong? I'm new in CMake preset and with this project. Also, it seems like something is not well set for CTest when the coverage is enabled. I have the same problem in my project as in Ftxui.
Also, any help on how to investigate, test, and fix the problem will be very pleasant. Thank you for all your tips and investigations.
Upvote & Fund
I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
When including project_options via FetchContent_Declare CMake displays a couple of warnings which (to my knowledge) are not disableable.
AFAIK, there are two solutions, either set policy with cmake_policy(SET CMP0135 [NEW/OLD]) or add DOWNLOAD_EXTRACT_TIMESTAMP true to FetchContent_Declare calls in Doxygen.cmake:35, PackageProject.cmake:169 and PackageProject.cmake:191
I'm using CMake Project in Visual Studio 2022.
If I upgrade 'porject_options' to 0.22.0 from 0.21.1, it reports below error and cmake cache generation has failed.
1> [CMake] -- Using Windows MSVC toolchain
1> [CMake] -- Setting CXX/C compiler to C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
1> [CMake] -- Running `C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Auxiliary/Build/vcvarsall.bat x64` to set up the MSVC environment
1> [CMake] ERROR: The system was unable to find the specified registry key or value.
1> [CMake] -- Using Windows MSVC toolchain
1> [CMake] -- Setting CXX/C compiler to C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
1> [CMake] -- Running `C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Auxiliary/Build/vcvarsall.bat x64` to set up the MSVC environment
1> [CMake] ERROR: The system was unable to find the specified registry key or value.
The dynamic project options example in the readme does not work for me. I've debugged that I must define setting defaults before including DynamicProjectOptions.cmake.
For example, in this case ccache will always be enabled even though the default should be OFF:
I don't know if this behavior can be changed, so that the setting will always be correctly overridden by the dynamic_project_options macro. But I do think the example shown in the readme should be fixed.
task: [test_release] cmake --build ./test/build --config Release
[2/6] Building CXX object CMakeFiles/lib2.dir/Release/src/mylib2/lib.cpp.o
/Users/clausklein/cmake/cmakelib/test/src/mylib2/lib.cpp:22:47: warning: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
^
Checking /Users/clausklein/cmake/cmakelib/test/src/mylib2/lib.cpp ...
Checking /Users/clausklein/cmake/cmakelib/test/src/mylib2/lib.cpp: FMT_LOCALE=1;CMAKE_INTDIR="Release";NDEBUG=1...
[4/6] Building CXX object CMakeFiles/main.dir/Release/cmake_pch.hxx.pch
Checking /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/cmake_pch.hxx.cxx ...
Checking /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/cmake_pch.hxx.cxx: FMT_LOCALE=1;CMAKE_INTDIR="Release";NDEBUG=1...
[5/6] Building CXX object CMakeFiles/main.dir/Release/src/main/main.cpp.o
FAILED: CMakeFiles/main.dir/Release/src/main/main.cpp.o
/usr/local/Cellar/cmake/3.22.1/bin/cmake -E __run_co_compile --launcher=/usr/local/bin/ccache --tidy="/usr/local/opt/llvm/bin/clang-tidy;-extra-arg=-Wno-unknown-warning-option;-extra-arg=-std=c++20;--extra-arg-before=--driver-mode=g++" --cppcheck="/usr/local/bin/cppcheck;--template=gcc;--enable=style,performance,warning,portability;--inline-suppr;--suppress=internalAstError;--suppress=unmatchedSuppression;--inconclusive;--std=c++20" --source=/Users/clausklein/cmake/cmakelib/test/src/main/main.cpp -- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DFMT_LOCALE -DCMAKE_INTDIR=\"Release\" -isystem /Users/clausklein/cmake/cmakelib/test/build/vcpkg_installed/x64-osx/include -isystem /Users/clausklein/cmake/cmakelib/test/build/vcpkg_installed/x64-osx/include/eigen3 -O3 -DNDEBUG -flto=thin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -fcolor-diagnostics -march=native --coverage -O0 -g -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -std=c++2a -Winvalid-pch -Xclang -include-pch -Xclang /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/Release/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/Release/cmake_pch.hxx -MD -MT CMakeFiles/main.dir/Release/src/main/main.cpp.o -MF CMakeFiles/main.dir/Release/src/main/main.cpp.o.d -o CMakeFiles/main.dir/Release/src/main/main.cpp.o -c /Users/clausklein/cmake/cmakelib/test/src/main/main.cpp
error: PCH file built from a different branch ((clang-1316.0.21.2)) than the compiler () [clang-diagnostic-error]
1 error generated.
Error while processing /Users/clausklein/cmake/cmakelib/test/src/main/main.cpp.
Found compiler error(s).
ninja: build stopped: subcommand failed.
task: Failed to run task "test_install": task: Failed to run task "test_release": exit status 1
bash-3.2$ find . -name '*.pch'
./test/build/CMakeFiles/main.dir/Release/cmake_pch.hxx.pch
bash-3.2$ which gcc
/usr/bin/gcc
bash-3.2$ gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
bash-3.2$
<!-- POLAR PLEDGE BADGE START -->## Upvote & Fund
- I am using [Polar.sh](https://polar.sh/aminya) so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
<a href="https://polar.sh/aminya/project_options/issues/107"><picture><source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/aminya/project_options/issues/107/pledge.svg?darkmode=1"><img alt="Fund with Polar" src="https://polar.sh/api/github/aminya/project_options/issues/107/pledge.svg"></picture></a><!-- POLAR PLEDGE BADGE END -->
I think we should enable clang-tidy and cppcheck by default, but instead of throwing errors if they are missing, we can give warnings.
The use case is that I want to enable clang-tidy and cppcheck on my own machine because I am sure they are installed, but I want to also allow the users to build the project even if they do not have these.
We can still allow this to error out if WARNING_AS_ERRORS is enabled.
Currently, the conan section forces the addition of both the conan-center-index and bincrafters remotes by default. Even though the comments state that we can remove remotes, I can't figure out how to do it without calling conan through add_custom_command or something like that.
The thing with adding bincrafters by default is that it sometimes complains about some env variables not defined. For that reason, and the fact that not everybody is going to use dependencies from the bincrafters remote, I propose to remove its addition and let the users decide whether they want to add it or not. Maybe a wrapper around conan_add_remote could be added to ease the job for users.
Upvote & Fund
@aminya is using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog!
Afaik to inject Javascript into Doxygen you have to provide a header template like described in the install instructions of the extensions. If there would be an easier way I'd love to know about it as well!
So I think the answer is no, there is no easy way to automate the addition of the extensions with just the CMake Doxygen module. Maybe you could ship a custom header template with your CMake module, with all the extensions installed? But personally, as a user, I'd not be a fan of that bc I need control over the header template for injecting SEO-Metadata and the "github corner".
It may be worth a try to directly ask your question in doxygen/doxygen?
CMake Error at build/_deps/_project_options-src/src/Optimization.cmake:18 (target_compile_options):
Cannot specify compile options for target "PRIVATE" which is not built by
this project.
The reason is that the macro lacks a parameter to receive project_name.
# for custom toolchains
cmake ... -DOPT_TOOLCHAIN_FILE:STRING="..." -DOPT_TARGET_TRIPLET:STRING="..."## setup vcpkg and more# use project_options toolchains
cmake ... -DOPT_TARGET_TRIPLET:STRING="..."## setup vcpkg and more# use vcpkg arguments
cmake ... -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="..." -DVCPKG_TARGET_TRIPLET="..."## read vcpkg triplet and set OPT_TARGET_TRIPLET etc.
checks for ENV variables and paths, print some helpful messages if something is missing (optional)
For example, when building for Android you need to set -DANDROID_NDK and -DANDROID_ABI
Maybe add some (default) extra properties: like for example emscript, set_target_properties(${target} PROPERTIES LINK_FLAGS "-s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s USE_PTHREADS=1 --bind")
Notes
Cross compiler must setup by user
Maybe addition arguments must be pass for cross-compiler root path or other paths like Android NDK, emscripten SDK (emsdk), ...
Upvote & Fund
I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
Is it possible to exclude targets or 3rd-party libs from the static analyzer ?
Root Project
option(ENABLE_TESTING "Enable the tests"${PROJECT_IS_TOP_LEVEL})
if(ENABLE_TESTING)
set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY")
set(ENABLE_CPPCHECK "ENABLE_CPPCHECK")
set(ENABLE_COVERAGE "ENABLE_COVERAGE")
if(NOT"${CMAKE_SYSTEM_NAME}"STREQUAL"Windows")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
else()
# or it is MSVC and has run vcvarsallstring(FIND"$ENV{PATH}""$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
if(MSVC AND"${index_of_vs_install_dir}"STREQUAL"-1")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
endif()
endif()
endif()
# defaulted_project_options sets recommended defaults and provides user and developer# modes and full GUI support for choosing options at configure time# for more flexibility, look into project_options() macro# Initialize project_options variable related to this project# This overwrites `project_options` and sets `project_warnings`# uncomment the options to enable them:
dynamic_project_options(
ENABLE_CACHE
${ENABLE_CPPCHECK}${ENABLE_CLANG_TIDY}
ENABLE_VS_ANALYSIS
${ENABLE_COVERAGE}${ENABLE_SANITIZER_ADDRESS}${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}# Note: PCH is disabled by default in developer mode because these headers become# globally included and they can mask other errors
PCH_HEADERS
# This is a list of headers to pre-compile, here are some common ones
<vector>
<string>
<utility>
<array>
<algorithm>
<concepts>
CPPCHECK_OPTIONS
--enable=style,performance,warning,portability
--inline-suppr
# We cannot act on a bug/missing feature of cppcheck
--suppress=cppcheckError
--suppress=internalAstError
# if a file does not have an internalAstError, we get an unmatchedSuppression error
--suppress=unmatchedSuppression
--suppress=passedByValue
--suppress=syntaxError
--inconclusive
)
target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
Add lib cmake
# get raylib from github and build as static lib
cpmaddpackage(
NAME
raylib
GIT_TAG
4.0.0
GITHUB_REPOSITORY
raysan5/raylib
OPTIONS"BUILD_SHARED_LIBS OFF")
if(NOT MSVC)
# don't error on implicit declarations, which are invalid in C99 but commonly usedtarget_compile_options(raylib PRIVATE -Wno-error=implicit-function-declaration)
endif()
Project cmake
add_library(engine STATIC)
# more library optionstarget_link_libraries(engine PRIVATE project_warnings project_options)
# add 3rd-party libs as system libs
target_link_system_libraries(engine PUBLIC raylib)
Warnings from raylib
[2/127] Building C object _deps/raylib-build/raylib/CMakeFiles/raylib.dir/rtextures.c.o
Checking cmake-build-debug/_deps/raylib-src/src/rtextures.c ...
Checking cmake-build-debug/_deps/raylib-src/src/rtextures.c: GRAPHICS_API_OPENGL_33=1;PLATFORM_DESKTOP=1...
cmake-build-debug/_deps/raylib-src/src/external/stb_image.h:7013:37: warning: Array 'signature[8]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]
if (stbi__get8(s) != signature[i])
^
cmake-build-debug/_deps/raylib-src/src/external/stb_image_write.h:1378:16: warning: Array index 'i' is used before limits check. [arrayIndexThenCheck]
for (; DU[i]==0 && i<=end0pos; ++i) {
^
cmake-build-debug/_deps/raylib-src/src/external/stb_image.h:4316:23: warning: Condition 'c==18' is always true [knownConditionTrueFalse]
} elseif (c == 18) {
^
cmake-build-debug/_deps/raylib-src/src/external/stb_image.h:4314:23: note: Assuming that condition 'c==17' is not redundant
} elseif (c == 17) {
^
cmake-build-debug/_deps/raylib-src/src/external/stb_image.h:4305:22: note: Assuming that condition 'c>=19' is not redundant
if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");
The project as a whole is using v0.22.4 and calls dynamic_project_options with ENABLE_CONAN and CONAN_OPTIONS parameters. CMake is generating a debug build and developer mode is on.
I have a library within my project that utilizes protobuf/grpc and generates a lot of code. This library never links against project_options or project_warnings. That library is then linked to the executable that requires it using target_link_system_libraries(exe PRIVATE protoObjects). However, I still get tons of errors against that generated code. The sanitizers/linters would be great to use across the rest of the app, but not this single target. As such, I'm hoping there's an option, workaround, or otherwise to be able to prevent static analysis against this target.
There are other Clang warnings that we have not added. We have already enabled the most pedantic ones, so I think adding these will complete the list and would be beneficial.
When compiling with GCC, it complains some warnings are not for C. We may need to set different warnings for different languages.
cc1: warning: command-line option โ-Wnon-virtual-dtorโ is valid for C++/ObjC++ but not for C
cc1: warning: command-line option โ-Wold-style-castโ is valid for C++/ObjC++ but not for C
cc1: warning: command-line option โ-Woverloaded-virtualโ is valid for C++/ObjC++ but not for C
cc1: warning: command-line option โ-Wuseless-castโ is valid for C++/ObjC++ but not for C
I have written a macro in project_options to try to fix the WinMain issue in MinGW. But adding -municode as a compile option doesn't fix the issue. Adding it as a link option causes linking to the fail with undefined reference to wWinMain. Other compilers don't need such flags, and I am not sure why we should do this for MinGW.
macro(mingw_unicode)
is_mingw(_is_mingw)
if(${_is_mingw})
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-municode" _cxx_supports_municode)
if(${_cxx_supports_municode})
message(STATUS "Enabling Unicode for MinGW in the current project to fix undefined references to WinMain")
add_compile_definitions("UNICODE""_UNICODE")
add_compile_options("-municode")
endif()
endif()
endmacro()
I noticed that not all cmake warnings are turned into errors when the variable WARNING_MESSAGE is set to SEND_ERROR, hence WARNINGS_AS_ERRORS enabled.
For example a missing clang-tidy will produce an error if the corresponding option is set (see StaticAnalyzer.cmake:32).
On the other hand a missing Sanitizer is always producing a warning (see Sanitizers.cmake:27).
Same goes for a missing ccache executable (see cache.cmake:29).
I cannot find any explantation why those are treated different, which kind of confuses me.
Would it be possible to add comments why some do not use the WARNING_MESSAGE variable, if that had been done on purpose?
Which seems the case at least for clang-tidy if i correctly understand #30.
# ---- Create library ----# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface# target: add_library(${PROJECT_NAME} INTERFACE)add_library(${PROJECT_NAME}${headers}${sources})
add_library(${PROJECT_NAME}::${PROJECT_NAME}ALIAS${PROJECT_NAME})
target_compile_features(${PROJECT_NAME}PUBLIC cxx_std_20)
# being a cross-platform target, we enforce standards conformance on MSVCtarget_compile_options(${PROJECT_NAME}PRIVATE"$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
# Link dependenciestarget_link_libraries(${PROJECT_NAME}PUBLIC fmt::fmt)
# FIXME: should be PRIVATE! CKtarget_link_libraries(${PROJECT_NAME}PUBLIC project_warnings project_options)
# target_include_directories with the SYSTEM modifier will request the compiler# to omit warnings from the provided paths, if the compiler supports thattarget_include_directories(
${PROJECT_NAME}SYSTEMPUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(CMAKE_SKIP_INSTALL_RULES)
return()
endif()
# ---- Create an installable target ----# this allows users to install and find the library via `find_package()`.# Add other targets that you want installe here. Or be default we just package# all targets recursively found for the current folder if not specified.
package_project(
NAME${PROJECT_NAME}TARGETS${PROJECT_NAME} project_options project_warnings
PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include
PUBLIC_DEPENDENCIES_CONFIGURED "fmt 8.1.1"# FIXME: not yet used! PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
)
cmake -B ./build-ModernCmakeStarter-Debug -S /Users/clausklein/Workspace/cpp/ModernCmakeStarter/all -D OPT_ENABLE_COVERAGE=NO -DOPT_WARNINGS_AS_ERRORS=NO
-- CPM: adding package [email protected] (v3.0.0 at /Users/clausklein/.cache/CPM/cxxopts/0c1df694f5ab3306e541038e6a2ed62926062894)
-- CPM: adding package greeter@ (/Users/clausklein/Workspace/cpp/ModernCmakeStarter/standalone/..)
-- CPM: greeter: adding package [email protected] (v0.20.0 at /Users/clausklein/.cache/CPM/project_options/f4f28e0d6a43eb4247d834f6b906d21040cf1ef9)
-- CPM: greeter: adding package [email protected] (v1.8.0 at /Users/clausklein/.cache/CPM/packageproject.cmake/987b02f8a9fe04de3c43e0e7a1afbb29c87adc5e)
-- Module support is disabled.
-- Version: 8.1.1
-- Build type: Debug
-- CXX_STANDARD: 20
-- Required features: cxx_variadic_templates
-- CPM: greeter: adding package [email protected] (8.1.1 at /Users/clausklein/.cache/CPM/fmt/15c05aa781ab44fa13a906fe5737c1d14e5edee9)
-- Developer mode is ON. For production, use `-DENABLE_DEVELOPER_MODE:BOOL=OFF`. Building the project for the developer...
-- The default CMAKE_C_STANDARD used by external targets and tools is not set yet. Using the latest supported C standard that is 90
-- /usr/local/bin/ccache found and enabled
-- CPM: adding package [email protected] (v2.4.8 at /Users/clausklein/.cache/CPM/doctest/367f22d2dff85570a9f727b99741f9e40b17df46)
-- CPM: adding package [email protected] (v1.7.3 at /Users/clausklein/.cache/CPM/format.cmake/17e103764947115e78d95ecc29c4bee54dc64e08)
-- CPM: adding package Greeter@ (/Users/clausklein/Workspace/cpp/ModernCmakeStarter/test/..)
-- CPM: adding package m.css@0 (a0d292ec311b97fefd21e93cdefb60f88d19ede6 at /Users/clausklein/.cache/CPM/m.css/23b42fe3166cf5c34c25c267ae0664557edd2200)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clausklein/Workspace/cpp/ModernCmakeStarter/build-ModernCmakeStarter-Debug
DESTDIR=/Users/clausklein/Workspace/cpp/stage cmake --install ./build-ModernCmakeStarter-Debug --prefix /usr
-- Install configuration: "Debug"
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/cxxopts.hpp
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/pkgconfig/cxxopts.pc
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/lib/libfmtd.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-targets-debug.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/args.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/chrono.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/color.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/compile.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/core.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/format.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/format-inl.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/locale.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/os.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/ostream.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/printf.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/ranges.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/xchar.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/pkgconfig/fmt.pc
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter/greeter.h
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/lib/libgreeter.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterConfigVersion.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterConfig.cmake
-- Old export file "/Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets.cmake" will be replaced. Removing files [/Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets-debug.cmake].
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets.cmake
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets-debug.cmake
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/usage
-- # The package greeter provides the following CMake targets:
find_package(greeter CONFIG REQUIRED)
target_link_libraries(main PRIVATE greeter::greeter greeter::project_options greeter::project_warnings)
bash-3.2$
This installed CMake config packages contains:
# Create imported target greeter::greeteradd_library(greeter::greeter STATICIMPORTED)
set_target_properties(greeter::greeter PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_20"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "fmt::fmt;greeter::project_warnings;greeter::project_options"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "include"
)
# Create imported target greeter::project_optionsadd_library(greeter::project_options INTERFACEIMPORTED)
set_target_properties(greeter::project_options PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_20"
INTERFACE_COMPILE_OPTIONS "-fsanitize=address,undefined"
INTERFACE_LINK_OPTIONS "-fsanitize=address,undefined"
)
# Create imported target greeter::project_warningsadd_library(greeter::project_warnings INTERFACEIMPORTED)
set_target_properties(greeter::project_warnings PROPERTIES
INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:-Wall;-Wextra;-Wshadow;-Wnon-virtual-dtor;-Wold-style-cast;-Wcast-align;-Wunused;-Woverloaded-virtual;-Wpedantic;-Wconversion;-Wsign-conversion;-Wnull-dereference;-Wdouble-promotion;-Wformat=2;-Wimplicit-fallthrough>;\$<\$<COMPILE_LANGUAGE:C>:-Wall;-Wextra;-Wshadow;-Wcast-align;-Wunused;-Wpedantic;-Wconversion;-Wsign-conversion;-Wnull-dereference;-Wdouble-promotion;-Wformat=2;-Wimplicit-fallthrough>;\$<\$<COMPILE_LANGUAGE:CUDA>:-Wall;-Wextra;-Wunused;-Wconversion;-Wshadow>"
)
``
<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund
- I am using [Polar.sh](https://polar.sh/aminya) so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
<a href="https://polar.sh/aminya/project_options/issues/117">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/aminya/project_options/issues/117/pledge.svg?darkmode=1">
<img alt="Fund with Polar" src="https://polar.sh/api/github/aminya/project_options/issues/117/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->
It seems to be a a problem on Windows Cmake (i have no problem on Mac or Linux) but any way I open an issue if you know a turn-around....
-- extracting... [tar xfz]
CMake Error: Problem with archive_write_finish_entry(): Can't restore time
CMake Error: Problem extracting tar: K:/Project/_deps/_project_options-subbuild/_project_options-populate-prefix/src/v0.18.1.zip
-- extracting... [error clean up]
CMake Error at _project_options-subbuild/_project_options-populate-prefix/src/_project_options-populate-stamp/extract-_project_options-populate.cmake:33 (message):
error: extract of
'K:/Project/_deps/_deps/_project_options-subbuild/_project_options-populate-prefix/src/v0.18.1.zip'
failed
Manually packaging/exporting a project for external users via the built-in CMake functions like install and configure_package_config_file is cumbersome. This whole thing can be abstracted away using a simple function that does it all.
Originally, I was hoping to use the detect_architecture() function in VCEnvironment.cmake to solve this problem, but it turned out detect_architecture cannot detect the ARCH on ARM. Here is a similar issue: microsoft/vcpkg#17832
An unrelated suggestion is that I would like to move the inclusion of Utilities.cmake outside of the file VCEnvironment.cmake, since the functions in Utilities.cmake are no longer exclusively used by that single file.
Upvote & Fund
I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
Currently the dependencies (fargs, ycm, conan) are fetched from github. Unfortunately, this does not work in environments where github is only accessible via a mirror. Would it be possible to somehow parameterize the github mirror for these dependencies?
Or is it only possible to appy a patch to replace the dependent urls when calling FetchContent_Declare?