Fix #11680 - Completely Remove the use of link_options / add_compile_options in third_party#11683
Conversation
… advanced option ENABLE_WARNINGS_IN_THIRD_PARTY
third_party was doing link_libraries and add_compile_options global calls, which leaks everywhere downstream
We use target_link_libraries specifically now.
third_party/CMakeLists.txt used to apply project_options and project_fp_options to every subsequently-added target via directory-scoped
link_libraries() calls. Because that's the plain (default-PUBLIC) form, it silently propagated project_options' interface requirements -- most
importantly the ${PROJECT_SOURCE_DIR}/src include dir and -Werror -- to anything that happened to link a third-party target, whether or not that
consumer asked for it.
Each third-party target now links project_options and project_fp_options explicitly and PRIVATE, tracked in a new all_third_party_targets list so the warning-suppression loop below doesn't need to be updated by hand every time a target is added.
Add an advanced ENABLE_WARNINGS_IN_THIRD_PARTY option (default OFF):
- OFF (default): every third-party target links turn_off_warnings (-w), fully silencing the compiler for vendored code, same as before.
- ON: most third-party targets link project_warnings plus a new warnings_as_not_error target (-Wno-error / /WX-) so the extra diagnostics
surface without turning -Werror on vendored code into hard build failures. This is useful for sanity once in a while
Fix ssc/ssc/CMakeLists.txt's own target_link_libraries calls to use the PUBLIC keyword form (matching upstream) instead of the plain signature -- CMake forbids mixing plain and keyword signatures for the same target, and this file already needed one or the other once third_party/CMakeLists.txt started using keywords.
Also normalize third_party/FMUParser/CMakeLists.txt to lowercase commands and the keyword target_link_libraries signature, since parser needed the
same signature fix.
…ject_warnings currently as it won't build with it
[ 97%][154/158] Building CXX object src/EnergyPlus/AirflowNetwork/CMakeFiles/airflownetworklib.dir/src/Elements.cpp.o
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Elements.cpp:448:49: warning: unused parameter 'state' [-Wunused-parameter]
448 | int SurfaceCrack::calculate(EnergyPlusData &state,
| ^
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Elements.cpp:787:42: warning: unused parameter 'i' [-Wunused-parameter]
787 | int const i, // Linkage number
| ^
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Elements.cpp:1074:37: warning: unused parameter 'i' [-Wunused-parameter]
1074 | int const i, // Linkage number
| ^
3 warnings generated.
[ 98%][155/158] Building CXX object src/EnergyPlus/AirflowNetwork/CMakeFiles/airflownetworklib.dir/src/Solver.cpp.o
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Solver.cpp:147:45: warning: field 'm_state' will be initialized after field 'properties' [-Wreorder-ctor]
147 | Solver::Solver(EnergyPlusData &state) : m_state(state), properties(state)
| ^~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
| properties(state) m_state(state)
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Solver.cpp:10742:17: warning: unused variable 'j' [-Wunused-variable]
10742 | int j = AirflowNetworkLinkageData(i).NodeNums[0];
| ^
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Solver.cpp:10743:17: warning: unused variable 'k' [-Wunused-variable]
10743 | int k = AirflowNetworkLinkageData(i).NodeNums[1];
| ^
/home/julien/Software/Others/EnergyPlus2/src/EnergyPlus/AirflowNetwork/src/Solver.cpp:13393:78: warning: unused parameter 'state' [-Wunused-parameter]
13393 | bool OccupantVentilationControlProp::closing_probability(EnergyPlusData &state,
| ^
4 warnings generated.
[100%][158/158] Linking CXX static library Products/libairflownetworklib.a
| # COMPILER FLAGS | ||
| target_compile_options(project_options INTERFACE -pipe) # Faster compiler processing | ||
| target_compile_options(project_options INTERFACE -Werror) # Compiler Driven Development | ||
| target_compile_options(project_warnings INTERFACE -Werror) # Compiler Driven Development |
There was a problem hiding this comment.
I move Werror from project_options to project_warnings, that makes more sense.
| # ADD_CXX_RELEASE_DEFINITIONS("-Ofast") # -Ofast (or -ffast-math) needed to auto-vectorize floating point loops | ||
|
|
||
| target_compile_options(turn_off_warnings INTERFACE -w) | ||
| target_compile_options(warnings_as_not_error INTERFACE -Wno-error) # Disable treating warnings as errors |
There was a problem hiding this comment.
New interface lib for not treating as an error (overwrites -Werror as long as it's linked after the project_warnings)
| # Useful for checking once in a while if a third-party library is generating scary warnings, but too noisy for normal development | ||
| option(ENABLE_WARNINGS_IN_THIRD_PARTY "Enable warnings in third-party libraries" OFF) | ||
| mark_as_advanced(ENABLE_WARNINGS_IN_THIRD_PARTY) |
There was a problem hiding this comment.
new option, OFF, advanced
| mark_as_advanced(ENABLE_WARNINGS_IN_THIRD_PARTY) | ||
|
|
||
| add_library(turn_off_warnings INTERFACE) | ||
| add_library(warnings_as_not_error INTERFACE) # -Wno-error |
There was a problem hiding this comment.
new interface lib declared here
| # END of INTERFACE targets | ||
|
|
||
| # SAM Is included up here to make sure it doesn't get the C++17 flags | ||
| set(all_third_party_targets "") |
There was a problem hiding this comment.
For convenience later when linking the warning/no warnings libs, I collect the libs into a list
| void change_file_date(filename, dosdate, tmu_date) const char *filename; | ||
| uLong dosdate; | ||
| tm_unz tmu_date; | ||
| void change_file_date(const char* filename, uLong dosdate, tm_unz tmu_date) |
There was a problem hiding this comment.
I fixed the K&R style here, then I also aligned from FMU's copy and FMI's copy to match, picking left and right as needed
| for (StdIntMap::iterator it2 = entry.parents->begin(); | ||
| it2 != entry.parents->end(); | ||
| ++it2) { | ||
| int j = it2->first; |
There was a problem hiding this comment.
An iterator override in a nested loop, worth fixing.
Our re2 copy is ancient FYI
There was a problem hiding this comment.
I believe we have a handful of outdated third-party libs.
| target_link_libraries(ssc PUBLIC ${name}) | ||
| endforeach() | ||
|
|
||
| if (UNIX) | ||
| find_package(Threads REQUIRED) | ||
| target_link_libraries(ssc Threads::Threads ${CMAKE_DL_LIBS}) | ||
| target_link_libraries(ssc PUBLIC Threads::Threads ${CMAKE_DL_LIBS}) | ||
| find_library(MATH_LIBRARY m) | ||
| if(MATH_LIBRARY) | ||
| target_link_libraries(ssc ${MATH_LIBRARY}) | ||
| target_link_libraries(ssc PUBLIC ${MATH_LIBRARY}) |
There was a problem hiding this comment.
ssc is now using the keyword-based target_link_libraries, so I can link PRIVATE to the warnings / turn_off_warnings
| add_executable(parser ${SRC}) | ||
|
|
||
| TARGET_LINK_LIBRARIES( parser epexpat miniziplib ) | ||
| target_link_libraries(parser PRIVATE epexpat miniziplib) |
There was a problem hiding this comment.
SAme for FMUParser (I also linted the CMake code, and used POSITION_INDEPENDENT_CODE)
|
|
||
| target_include_directories(airflownetworklib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
| target_link_libraries(airflownetworklib PUBLIC objexx PRIVATE btwxt nlohmann_json re2 Windows-CalcEngine) | ||
| target_link_libraries(airflownetworklib PUBLIC objexx PRIVATE btwxt nlohmann_json re2 Windows-CalcEngine project_options project_fp_options project_warnings) |
There was a problem hiding this comment.
AFN was getting project_options from third_party...
It wouldn't build with project_warnings, so I fixed a couple of minor things, mostly Wunused-parameter, Unused variable, and a Ctor member initialization order
There was a problem hiding this comment.
Actually it won't build on Windows, C4458 all around https://github.com/NatLabRockies/EnergyPlus/actions/runs/29093537497/job/86364398475?pr=11683
``` [ 40%][2/5] Building CXX object src\EnergyPlus\AirflowNetwork\CMakeFiles\airflownetworklib.dir\src\Elements.cpp.obj cl : Command line warning D9025 : overriding '/WX' with '/WX-' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(113): warning C4458: declaration of 'A1' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Elements.hpp(1001): note: see declaration of 'EnergyPlus::AirflowNetwork::Duct::A1' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(125): warning C4458: declaration of 'g' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Elements.hpp(1000): note: see declaration of 'EnergyPlus::AirflowNetwork::Duct::g' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(262): warning C4458: declaration of 'A1' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Elements.hpp(1001): note: see declaration of 'EnergyPlus::AirflowNetwork::Duct::A1' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(274): warning C4458: declaration of 'g' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Elements.hpp(1000): note: see declaration of 'EnergyPlus::AirflowNetwork::Duct::g' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(722): warning C4458: declaration of 'AirLoopNum' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Elements.hpp(1096): note: see declaration of 'EnergyPlus::AirflowNetwork::ConstantVolumeFan::AirLoopNum' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(1847): warning C4458: declaration of 'OpenFactor' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Elements.hpp(536): note: see declaration of 'EnergyPlus::AirflowNetwork::SimpleOpening::OpenFactor' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(1521) : warning C4701: potentially uninitialized local variable 'WFact' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(1522) : warning C4701: potentially uninitialized local variable 'HFact' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(1523) : warning C4701: potentially uninitialized local variable 'Cfact' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(1638) : warning C4701: potentially uninitialized local variable 'Lextra' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Elements.cpp(1707) : warning C4701: potentially uninitialized local variable 'Axishght' used [ 60%][3/5] Building CXX object src\EnergyPlus\AirflowNetwork\CMakeFiles\airflownetworklib.dir\src\Solver.cpp.obj cl : Command line warning D9025 : overriding '/WX' with '/WX-' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(4699): warning C4458: declaration of 'compnum' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(418): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::compnum' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(4837): warning C4458: declaration of 'compnum' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(418): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::compnum' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(4965): warning C4458: declaration of 'compnum' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(418): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::compnum' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14334): warning C4458: declaration of 'AU' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(454): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::AU' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14335): warning C4458: declaration of 'AD' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(453): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::AD' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14337): warning C4458: declaration of 'IK' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(452): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::IK' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14485): warning C4458: declaration of 'AU' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(454): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::AU' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14486): warning C4458: declaration of 'AD' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(453): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::AD' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14489): warning C4458: declaration of 'IK' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(452): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::IK' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14593): warning C4458: declaration of 'IK' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(452): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::IK' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14594): warning C4458: declaration of 'AU' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(454): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::AU' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(14595): warning C4458: declaration of 'AD' hides class member C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\include\AirflowNetwork/Solver.hpp(453): note: see declaration of 'EnergyPlus::AirflowNetwork::Solver::AD' C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(9119) : warning C4701: potentially uninitialized local variable 'RepOnOffFanRunTimeFraction' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(6715) : warning C4701: potentially uninitialized local variable 'PressureSet' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12027) : warning C4701: potentially uninitialized local variable 'X1' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12027) : warning C4701: potentially uninitialized local variable 'Y1' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12019) : warning C4701: potentially uninitialized local variable 'ZoneAng1' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12027) : warning C4701: potentially uninitialized local variable 'X2' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12027) : warning C4701: potentially uninitialized local variable 'Y2' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12019) : warning C4701: potentially uninitialized local variable 'ZoneAng2' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12838) : warning C4701: potentially uninitialized local variable 'Velocity' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(12964) : warning C4701: potentially uninitialized local variable 'Velocity' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(13086) : warning C4701: potentially uninitialized local variable 'Velocity' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(1465) : warning C4701: potentially uninitialized local variable 'inletNode' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(1466) : warning C4701: potentially uninitialized local variable 'outletNode' used C:\src\EnergyPlus\src\EnergyPlus\AirflowNetwork\src\Solver.cpp(2237) : warning C4701: potentially uninitialized local variable 'NumAPL' used [ 80%][4/5] Linking CXX static library Products\airflownetworklib.lib ```
… getting ffp-contract from third_party... 22 1702: [ RUN ] EnergyPlusFixture.OutputReportTabular_GatherHeatEmissionReport 1702: /Users/runner/work/EnergyPlus/EnergyPlus/tst/EnergyPlus/unit/OutputReportTabular.unit.cc:3773: Failure 1702: Expected equality of these values: 1702: 2 * condenserReject * Constant::convertJtoGJ + coilReject * Constant::convertJtoGJ 1702: Which is: 0.00010831 1702: state->dataHeatBal->BuildingPreDefRep.emiHVACReject 1702: Which is: 0.00010831 1/1 Test #1702: EnergyPlusFixture.OutputReportTabular_GatherHeatEmissionReport ...***Exception: SegFault 0.07 sec
8eacdea to
e103192
Compare
I didn't get that C4127 on MSVC 2026 but CI reported it And exclude a warning that is thrown anyways regardles off /W0 in shared (ssc)
e103192 to
25e3884
Compare
mitchute
left a comment
There was a problem hiding this comment.
Nice set of cleanups. As long as everything builds and tests pass, this is ready.
| # COMPILER FLAGS | ||
| target_compile_options(project_options INTERFACE -pipe) # Faster compiler processing | ||
| target_compile_options(project_options INTERFACE -Werror) # Compiler Driven Development | ||
| target_compile_options(project_warnings INTERFACE -Werror) # Compiler Driven Development |
| void change_file_date(filename, dosdate, tmu_date) const char *filename; | ||
| uLong dosdate; | ||
| tm_unz tmu_date; | ||
| void change_file_date(const char* filename, uLong dosdate, tm_unz tmu_date) |
| for (StdIntMap::iterator it2 = entry.parents->begin(); | ||
| it2 != entry.parents->end(); | ||
| ++it2) { | ||
| int j = it2->first; |
There was a problem hiding this comment.
I believe we have a handful of outdated third-party libs.
| if(NOT MSVC) | ||
| add_compile_options(-Wno-pedantic -Wno-unused-parameter -Wno-unknown-pragmas) | ||
| if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0) | ||
| add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-dangling-reference> $<$<COMPILE_LANGUAGE:CXX>:-Wno-restrict>) | ||
| endif() | ||
| else() | ||
| add_compile_options(/wd4267 /wd4996 /wd4068 /wd4244 /wd4589) | ||
| endif() |
| foreach(target IN LISTS all_third_party_targets) | ||
| # Skip | ||
| if("${target}" IN_LIST skip_libs) | ||
| message(DEBUG "Skipping ${target} for project_warnings") | ||
| continue() | ||
| endif() | ||
|
|
||
| if(TARGET ${target}) | ||
| target_link_libraries(${target} PRIVATE project_warnings warnings_as_not_error skip_common_warnings) | ||
| endif() | ||
| endforeach() |
There was a problem hiding this comment.
I like having this option to toggle these.
|
I built the Windows-debug-python config locally on this with #11699 merged in temporarily to confirm nothing is broken. |
Pull request overview
Fixes Completely Remove the use of link_options / add_compile_options in third_party #11680
This builds upon Fix #11678 - Enforce the use of override keyword + clean up third_party CMake #11679 - review and merge that one first
Description of the purpose of this PR
PRIVATEalways to make sure it doesn't leakAdd an advanced ENABLE_WARNINGS_IN_THIRD_PARTY option (default OFF):
add_subdirectory(third_party SYSTEM)only suppresses warnings for headers you are importing in your own code, it wont silence warnings from building third_party libs themselves.warnings_as_not_errortarget (-Wno-error/WX-) so the extra diagnostics surface without turning-Werroron vendored code into hard build failures. This is useful for sanity once in a whileI fixed a few hard warnings such as K&R style deprecation in C code in third_party while I was at it
Pull Request Author
Reviewer