-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CMake cleanup #7658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
CMake cleanup #7658
Conversation
Because of the global registration an object library will need to be used for at least cppcheck-core, but we can still wrap it in an interface library so it can propagate usage requirements though. |
Using interface libraries would be an acceptable modernization (although I personally detest them - I had to many problems with them in the past). We need to test though that things work with the currently specified minimum CMake version and raise it appropriately if necessary. But if we actually want to support shared libraries there is a lot of work to be done:
And IMO externals should not be shared libraries. Also we still have static objects in our code which possibly makes the proper usage of the shared objects impossible. Beside that I reckon there never was and never will be a single user of the shared objects. And the current implementation was only partial. We should not be supporting shared libraries at all because it just causes more work now and in the future and I do not see any upsides at all. We should be removing features instead of adding and simplifying things instead of making them even more complex (with latter I am referring to the support matrix - not the code). |
The purpose of the shared libraries would only be for local dev. I wouldn't envision us installing them. |
Please elaborate. I do not see how it would be of any use - especially given that it was never available and nobody complained. And if we want to support that we need to test it i.e. CI workflows. Otherwise it is just more stuff which rots away in this repo.
It would be possible but it would not work - so it should not be allowed. |
So with this change there is new |
Faster linking time. |
externals/tinyxml2/CMakeLists.txt
Outdated
target_include_directories(tinyxml2 SYSTEM PUBLIC .) | ||
target_include_directories(tinyxml2 PUBLIC .) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That flag needs to depend on the EXTERNALS_AS_SYSTEM
option.
lib/CMakeLists.txt
Outdated
# if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) | ||
# target_precompile_headers(cppcheck-core-private PRIVATE precompiled.h) | ||
# endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be enabled again before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, that was to test the CI. I was getting error:
../../../lib/CMakeFiles/cppcheck-core-private.dir/cmake_pch.hxx.gch: file not recognized: file format not recognized
Now with it disabled I get an error that there isnt a make rule for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you are explicitly building it in selfcheck, but its using the wrong target name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to the OBJECT
library directly fixed this issue.
if (BUILD_CORE_DLL) | ||
target_compile_definitions(tinyxml2_objs PRIVATE TINYXML2_EXPORT) | ||
endif() | ||
add_library(tinyxml2 ${srcs} ${hdrs}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be able to become a shared library.
if (BUILD_CORE_DLL) | ||
target_compile_definitions(simplecpp_objs PRIVATE SIMPLECPP_EXPORT) | ||
endif() | ||
add_library(simplecpp ${srcs} ${hdrs}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be able to become a shared library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will if we set BUILD_SHARED_LIBS
.
frontend/CMakeLists.txt
Outdated
add_library(frontend OBJECT ${hdrs} ${srcs}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this can become a shared library (which it shouldn't) it also needs the import/export handling. This is getting way more complicating than the existing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this can become a shared library (which it shouldn't) it also needs the import/export handling.
Only on windows is that needed. Either way the purpose of this PR is not to support shared libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this comment, this library shouldn't be an object library. I am not sure why its working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why this works. Since cmake 3.12, object libraries can be linked directly instead of adding the $<TARGET_OBJECTS>
to the sources. This will make it simpler.
Yes, that probably will save a few microseconds... Unlike the precompiled headers you just disabled which will actually save a lot of compilation time...
How do these occur? I did not see them in the CI failures. |
const int res = pclose(p); | ||
int res = pclose(p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes (among others) in macos-15
builds:
/Users/runner/work/cppcheck/cppcheck/cli/cppcheckexecutor.cpp:746:9: warning: cast from 'const int *' to 'int *' drops const qualifier [-Wcast-qual]
746 | if (WIFEXITED(res)) {
| ^
/Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/sys/wait.h:152:26: note: expanded from macro 'WIFEXITED'
152 | #define WIFEXITED(x) (_WSTATUS(x) == 0)
| ^
Failing builds on warnings is tracked via https://trac.cppcheck.net/ticket/12021.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its needed to fix CI, because they became errors in the CI with these changes. I am not sure why it didnt error out before in the CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope is getting way too big with a lot of questionable sidecar changes. This needs to be fixed more incrementally.
Its needed to fix CI, because they became errors in the CI with these changes. I am not sure why it didnt error out before in the CI.
That should not be happening. That indicates that something is wrong in these CMake change.
There's several things which do not look right to me. I am not feeling very well right now so it will take quite a while for me to review and even understand what this is doing since the changes are hard to follow. Also the proper fixes for the boost issues should be merged as since those will have actual tests for the behavior changes. |
Hope you feel better soon. Here is a summary/explanation of the changes which hopefully can help you review the PR. The biggest change is to move all the usage requirements into the target and link with target directly instead of using So now I removed the manual includes and linking, and just link a single target directly. I did this based on the includes in the cmake, but I didnt check the source code if its actually including headers from the component. In the future, we can probably do some more cleanup up here. I dont think every component that is linking simplecpp is using headers from simplecpp, but I didnt check the c++ source files and added it as it was being included in the cmake. For tinyxml2, I created a target even when we are using an external tinyxml2. So we just need to link the The cppcheck-core will still be an object library when Supporting In some places, we were using a couple of source files from another component and rebuilding them again(like filelister.cpp). Instead, I just link the component that builds that source file instead of doing these kind of hacks. If we want to make a subset of source files a seperate component then we could refactor that in the future. I dont do that here since I want to minimize the changes here, but it is something we can address in the future. As such, the dmake exe needs the cli lib to be built. So we still build the cli lib even when |
@firewave Are you able to review this? |
|
Thanks for the extensive description. I will take another look at this soon - need to take care of things which piled up in the past few weeks. The first time I looked at this I saw some different shortcomings in the existing code which need to be singled out/addressed first but I cannot remember what it was. My aim is to have this resolved in this dev cycle. |
This removes the object libraries and uses normal cmake targets. This helps simplifies a lot of the cmake since we can properly propagate usage requirements.