diff --git a/.clang-tidy b/.clang-tidy index 3a28501e426bc83cfadd4e907ffa20c5f9023ccc..fbf639ef6f684bc8396fe1db15541adb9e8089c5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,7 @@ Checks: '*, -cert-err61-cpp, -clang-analyzer-alpha.deadcode.UnreachableCode, -clang-analyzer-security.insecureAPI.strcpy, +-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-member-init, @@ -17,6 +18,7 @@ Checks: '*, -cppcoreguidelines-pro-type-vararg, -fuchsia-default-arguments-calls, -fuchsia-overloaded-operator, +-fuchsia-trailing-return, -google-build-using-namespace, -google-default-arguments, -google-readability-todo, @@ -46,10 +48,16 @@ Checks: '*, -bugprone-narrowing-conversions, -bugprone-unhandled-self-assignment, -bugprone-unused-return-value, +-bugprone-use-after-move, -bugprone-parent-virtual-call, +-cert-dcl21-cpp, -cert-msc30-c, +-cert-msc50-cpp, -cert-oop54-cpp, +-clang-analyzer-core.CallAndMessage, -clang-analyzer-cplusplus.NewDeleteLeaks, +-cppcoreguidelines-explicit-virtual-functions, +-cppcoreguidelines-macro-usage, -cppcoreguidelines-pro-type-const-cast, -cppcoreguidelines-pro-type-cstyle-cast, -cppcoreguidelines-pro-type-static-cast-downcast, @@ -59,6 +67,7 @@ Checks: '*, -google-readability-casting, -google-runtime-references, -hicpp-move-const-arg, +-hicpp-multiway-paths-covered, -hicpp-no-array-decay, -hicpp-noexcept-move, -hicpp-signed-bitwise, @@ -69,6 +78,7 @@ Checks: '*, -misc-uniqueptr-reset-release, -modernize-loop-convert, -modernize-loop-convert, +-modernize-make-shared, -modernize-make-unique, -modernize-pass-by-value, -modernize-raw-string-literal, @@ -82,6 +92,7 @@ Checks: '*, -performance-move-const-arg, -performance-noexcept-move-constructor, -performance-unnecessary-value-param, +-performance-unnecessary-copy-initialization, -readability-avoid-const-params-in-decls, -readability-const-return-type, -readability-delete-null-pointer, @@ -91,4 +102,6 @@ Checks: '*, -readability-redundant-control-flow, -readability-redundant-string-cstr, -readability-uppercase-literal-suffix, + +-clang-analyzer-core.NonNullParamChecker, ' diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 2f47e9f932eadc8b46fd4d337baa109b13a341e6..81ce7618023d4004b0092d83d1c5c212a5c95931 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -8,10 +8,15 @@ set(lib BornAgain${name}) # --- source and include files --- file(GLOB source_files */*.cpp) +file(GLOB include_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} */*.h) + if((NOT Cerf_IS_CPP) AND (NOT WIN32)) # TEMPORARY list(APPEND source_files ${CMAKE_SOURCE_DIR}/ThirdParty/Core/cerf_wrapper/cerf_ptr.c) endif() -file(GLOB include_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} */*.h) +if(${Cerf_IS_CPP}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERF_AS_CPP=ON") +endif() + if(BORNAGAIN_PYTHON) @@ -83,6 +88,23 @@ if(BORNAGAIN_PYTHON) endif(BORNAGAIN_PYTHON) +# --- making library --- + +if(WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBA_CORE_BUILD_DLL") +endif() + +add_library(${lib} SHARED ${source_files}) +set_target_properties(${lib} PROPERTIES PREFIX ${libprefix} SUFFIX ${libsuffix}) +set(${lib}_LIBRARY_TYPE SHARED) + +if(BORNAGAIN_PYTHON) + add_dependencies(${lib} ${lib}_python) +endif() + +# exposing library name and list of include directories outside +set(${lib}_LIBRARY ${lib} PARENT_SCOPE) + if(BORNAGAIN_PYTHON) if(CONFIGURE_BINDINGS) @@ -93,6 +115,7 @@ if(BORNAGAIN_PYTHON) ) endif() add_custom_target(${lib}_runtime DEPENDS ${AUTO_DIR}/swig_runtime.h) + add_dependencies(${lib} ${lib}_runtime) configure_file(${WRAP_DIR}/python/plot_utils.py ${CMAKE_BINARY_DIR}/lib/bornagain/plot_utils.py COPYONLY) @@ -111,26 +134,6 @@ if(BORNAGAIN_PYTHON) endif() -# --- making library --- - -if(WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBA_CORE_BUILD_DLL") -endif() - -if(${Cerf_IS_CPP}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERF_AS_CPP=ON") -endif() -add_library(${lib} SHARED ${source_files}) -set_target_properties(${lib} PROPERTIES PREFIX ${libprefix} SUFFIX ${libsuffix}) -set(${lib}_LIBRARY_TYPE SHARED) - -if(BORNAGAIN_PYTHON) - add_dependencies(${lib} ${lib}_python) - add_dependencies(${lib} ${lib}_runtime) -endif() - -# exposing library name and list of include directories outside -set(${lib}_LIBRARY ${lib} PARENT_SCOPE) # --- external dependencies --- @@ -165,7 +168,7 @@ endif() if(BORNAGAIN_PYTHON) target_compile_definitions(${lib} PUBLIC -DBORNAGAIN_PYTHON) - include_directories(${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS}) + target_include_directories(${lib} PUBLIC ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS}) target_link_libraries(${lib} ${Python3_LIBRARIES}) endif() @@ -176,6 +179,15 @@ endif() # --- installation --- +install(TARGETS ${lib} DESTINATION ${destination_lib} COMPONENT Libraries) +install(FILES ${CMAKE_BINARY_DIR}/lib/lib${lib}.py + DESTINATION ${destination_lib} COMPONENT Libraries) # required by swig + +foreach(file ${include_files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} DESTINATION ${destination_include}/${name}/${dir}) +endforeach() + install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.py" ) install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ @@ -186,17 +198,8 @@ install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.png") install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/cpp DESTINATION ${destination_examples} COMPONENT Examples) -install(TARGETS ${lib} DESTINATION ${destination_lib} COMPONENT Libraries) -install(FILES ${CMAKE_BINARY_DIR}/lib/lib${lib}.py - DESTINATION ${destination_lib} COMPONENT Libraries) # required by swig - -foreach(file ${include_files}) - get_filename_component(dir ${file} DIRECTORY) - install(FILES ${file} DESTINATION ${destination_include}/${name}/${dir}) -endforeach() install(FILES "${AUTO_DIR}/swig_runtime.h" DESTINATION ${destination_include}/Wrap COMPONENT Headers) - install(FILES ${CMAKE_SOURCE_DIR}/Wrap/WinDllMacros.h DESTINATION ${destination_include}/Wrap COMPONENT Headers) diff --git a/Core/Detector/Convolve.cpp b/Core/Detector/Convolve.cpp index 6b451fad297a1c2047d1c4b901534bcf9103efd9..4e15a34278c2fab4e7c1a5dae96ec53f739ae913 100644 --- a/Core/Detector/Convolve.cpp +++ b/Core/Detector/Convolve.cpp @@ -204,6 +204,7 @@ void Convolve::init(int h_src, int w_src, int h_kernel, int w_kernel) ws.w_offset = ws.w_kernel - 1; break; case FFTW_CIRCULAR_SAME: + case FFTW_CIRCULAR_SAME_SHIFTED: // Circular convolution, modulo N // We don't padd with zeros because if we do, we need to padd with at least h_kernel/2; // w_kernel/2 elements plus the wrapp around, which in facts leads to too much @@ -216,20 +217,6 @@ void Convolve::init(int h_src, int w_src, int h_kernel, int w_kernel) ws.h_offset = 0; ws.w_offset = 0; break; - case FFTW_CIRCULAR_SAME_SHIFTED: - // Circular convolution, modulo N, shifted by M/2 - // We don't padd with zeros because if we do, we need to padd with at least h_kernel/2; - // w_kernel/2 elements plus the wrapp around, which in facts leads to too much - // computations compared to the gain obtained with the optimal size - ws.h_fftw = h_src; - ws.w_fftw = w_src; - ws.h_dst = h_src; - ws.w_dst = w_src; - // We copy the [h_kernel/2:h_kernel/2+h_dst-1 ; w_kernel/2:w_kernel/2+w_dst-1] - // real part elements of out_src - ws.h_offset = 0; - ws.w_offset = 0; - break; default: std::cout << "Unrecognized convolution mode, possible modes are " diff --git a/Core/Detector/RectangularDetector.cpp b/Core/Detector/RectangularDetector.cpp index de5d0de7d6b9eceea7d2494213958cfd28838d9f..985b9ad9efec3496cd5c3e62ef9f389dabde0109 100644 --- a/Core/Detector/RectangularDetector.cpp +++ b/Core/Detector/RectangularDetector.cpp @@ -261,12 +261,8 @@ void RectangularDetector::initNormalVector(const kvector_t central_k) m_normal_to_detector = m_distance * central_k_unit; } - else if (m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM) { - m_normal_to_detector = m_distance * central_k_unit; - m_normal_to_detector.setZ(-m_normal_to_detector.z()); - } - - else if (m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM_DPOS) { + else if (m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM || + m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM_DPOS) { m_normal_to_detector = m_distance * central_k_unit; m_normal_to_detector.setZ(-m_normal_to_detector.z()); } diff --git a/Core/Fitting/FitObjective.cpp b/Core/Fitting/FitObjective.cpp index 4a8a5c671eb7bc1b5f1008083110ff2e365b7306..ea011148717e4a124c50aafed7aa543f3cf13363 100644 --- a/Core/Fitting/FitObjective.cpp +++ b/Core/Fitting/FitObjective.cpp @@ -35,7 +35,7 @@ public: class ChiModuleWrapper : public IMetricWrapper { public: - ChiModuleWrapper(std::unique_ptr<IChiSquaredModule> module); + explicit ChiModuleWrapper(std::unique_ptr<IChiSquaredModule> module); double compute(const std::vector<SimDataPair>& fit_objects, size_t n_pars) const override; private: @@ -45,7 +45,7 @@ private: class ObjectiveMetricWrapper : public IMetricWrapper { public: - ObjectiveMetricWrapper(std::unique_ptr<ObjectiveMetric> module); + explicit ObjectiveMetricWrapper(std::unique_ptr<ObjectiveMetric> module); double compute(const std::vector<SimDataPair>& fit_objects, size_t n_pars) const override; private: diff --git a/Fit/CMakeLists.txt b/Fit/CMakeLists.txt index ea3f1e0dc37a6766df29b144c06e8b3f77af72f1..f46b075435f0ff9a5a64b4b90d78e0761dfb2abc 100644 --- a/Fit/CMakeLists.txt +++ b/Fit/CMakeLists.txt @@ -103,34 +103,13 @@ target_include_directories(${lib} PUBLIC ${RootMinimizers_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}) target_link_libraries(${lib} ${RootMinimizers_LIBRARY} ${Boost_LIBRARIES}) + if(BORNAGAIN_PYTHON) - target_include_directories(${lib} - PUBLIC ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS}) + target_compile_definitions(${lib} PUBLIC -DBORNAGAIN_PYTHON) + target_include_directories(${lib} PUBLIC ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS}) target_link_libraries(${lib} ${Python3_LIBRARIES}) endif() -# --- custom actions --- - -# python in windows required .pyd extention for the library name -if(WIN32 AND BORNAGAIN_PYTHON) - add_custom_command( - TARGET ${lib} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/bin/${libprefix}${lib}${libsuffix} - ${CMAKE_BINARY_DIR}/lib/${libprefix}${lib}".pyd" - ) - # for functional tests - add_custom_command( - TARGET ${lib} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/bin/${libprefix}${lib}${libsuffix} - ${CMAKE_BINARY_DIR}/lib/${libprefix}${lib}${libsuffix} - ) - -endif() - if(APPLE AND BORNAGAIN_APPLE_BUNDLE) set(link_flags "-Wl,-rpath,@loader_path/../../Frameworks") set_target_properties(${lib} PROPERTIES LINK_FLAGS ${link_flags}) @@ -159,5 +138,12 @@ if(WIN32) ) install(FILES ${CMAKE_BINARY_DIR}/lib/${libprefix}${lib}.pyd DESTINATION ${destination_lib} COMPONENT Libraries) + add_custom_command( + TARGET ${lib} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/bin/${libprefix}${lib}${libsuffix} + ${CMAKE_BINARY_DIR}/lib/${libprefix}${lib}${libsuffix} + ) endif() endif() diff --git a/GUI/coregui/Models/JobModelFunctions.cpp b/GUI/coregui/Models/JobModelFunctions.cpp index 552c0cc3046af5f3bab72f33f05cbcf9c4b54a3a..bdb2cc71ae9199fdc95856053736fd513591064f 100644 --- a/GUI/coregui/Models/JobModelFunctions.cpp +++ b/GUI/coregui/Models/JobModelFunctions.cpp @@ -281,7 +281,7 @@ void createFitContainers(JobItem* jobItem) "a second FitParameterContainer."); } - parsContainerItem = model->insertNewItem("FitParameterContainer", fitSuiteItem->index(), -1, + model->insertNewItem("FitParameterContainer", fitSuiteItem->index(), -1, FitSuiteItem::T_FIT_PARAMETERS_CONTAINER); // Minimizer settings @@ -291,7 +291,7 @@ void createFitContainers(JobItem* jobItem) "a second MinimizerContainer."); } - minimizerContainerItem = model->insertNewItem("MinimizerContainer", fitSuiteItem->index(), -1, + model->insertNewItem("MinimizerContainer", fitSuiteItem->index(), -1, FitSuiteItem::T_MINIMIZER); } diff --git a/GUI/main/main.cpp b/GUI/main/main.cpp index a1fa6610b1c49188fc6f4cce3bbcb9f3daf98fb1..8272b1aa8c814126f3afc0cb628c2fe814c52c0b 100644 --- a/GUI/main/main.cpp +++ b/GUI/main/main.cpp @@ -54,5 +54,5 @@ int main(int argc, char* argv[]) if (splash) splash->finish(&win); - return app.exec(); + return QApplication::exec(); } diff --git a/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp b/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp index f2154dad3b309c63c44c40515075aca962a48b8f..2a992a0b460ee80b12ace996bd7b9123367624e0 100644 --- a/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp +++ b/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp @@ -50,7 +50,7 @@ TEST_F(BatchSimulation, BatchSimulation) batch->runSimulation(); auto batch_result = batch->result(); std::unique_ptr<OutputData<double>> batchResult(batch_result.data()); - *result += *batchResult.get(); + *result += *batchResult; } double diff = IntensityDataFunctions::getRelativeDifference(*result, *reference); diff --git a/Tests/Performance/Core/Mesocrystal.cpp b/Tests/Performance/Core/Mesocrystal.cpp index babad9965f3776a7c82cf153cb2c954e9c9daf97..1d40be16472d0585aec431e33379ed9cb64b5d59 100644 --- a/Tests/Performance/Core/Mesocrystal.cpp +++ b/Tests/Performance/Core/Mesocrystal.cpp @@ -75,7 +75,7 @@ public: ~MesoCrystalPerformanceBuilder(); protected: - MultiLayer* buildSample() const; + MultiLayer* buildSample() const override; private: std::unique_ptr<MesoCrystal> createMeso(Material material, @@ -146,7 +146,7 @@ MultiLayer* MesoCrystalPerformanceBuilder::buildSample() const RotationX rotX(tilt); mesocrystal->setRotation(rotZ); mesocrystal->rotate(rotX); - particle_decoration.addParticle(*mesocrystal.get(), 1.0, + particle_decoration.addParticle(*mesocrystal, 1.0, kvector_t(0, 0, -m_meso_height)); } } @@ -198,7 +198,7 @@ int main() auto detector = create_detector(); - simulation.setDetector(*detector.get()); + simulation.setDetector(*detector); simulation.setBeamParameters(1.77 * Units::angstrom, 0.4 * Units::deg, 0.0); simulation.setBeamIntensity(6.1e+12); diff --git a/Tests/UnitTests/Core/Sample/ParticleTest.cpp b/Tests/UnitTests/Core/Sample/ParticleTest.cpp index c6c2e7a6029f31560182f9fab70e7faa66b8d6a8..94d8c06a6e72892ed5e2b0f141e62d8c496f8300 100644 --- a/Tests/UnitTests/Core/Sample/ParticleTest.cpp +++ b/Tests/UnitTests/Core/Sample/ParticleTest.cpp @@ -7,12 +7,8 @@ class ParticleTest : public ::testing::Test { -protected: - ~ParticleTest(); }; -ParticleTest::~ParticleTest() = default; - TEST_F(ParticleTest, InitialState) { Particle particle; diff --git a/Tests/UnitTests/Core/Sample/RTTest.cpp b/Tests/UnitTests/Core/Sample/RTTest.cpp index f0a51e328700e11ad735dab853992b74356c084f..1f8eee908c04648f67e370b80f235c6232ea1923 100644 --- a/Tests/UnitTests/Core/Sample/RTTest.cpp +++ b/Tests/UnitTests/Core/Sample/RTTest.cpp @@ -13,7 +13,6 @@ class RTTest : public ::testing::Test { protected: - ~RTTest(); void printCoeffs(const std::vector<ScalarRTCoefficients>& coeffs) { // for debug phases for (size_t i = 0; i < coeffs.size(); ++i) { @@ -49,8 +48,6 @@ protected: std::vector<ScalarRTCoefficients> coeffs1, coeffs2; }; -RTTest::~RTTest() = default; - TEST_F(RTTest, SplitLayer) { const int n = 40; diff --git a/Tests/UnitTests/GUI/TestMapperForItem.cpp b/Tests/UnitTests/GUI/TestMapperForItem.cpp index 7b9d844c8b7a083bfa2299f52444a55f6e3a42bb..f4549c7e2688ada7a7b2de8272789e32214cd70a 100644 --- a/Tests/UnitTests/GUI/TestMapperForItem.cpp +++ b/Tests/UnitTests/GUI/TestMapperForItem.cpp @@ -96,7 +96,6 @@ class TestMapperForItem : public ::testing::Test { public: TestMapperForItem() : m_mapped_item(0) {} - ~TestMapperForItem(); void setItem(SessionItem* item, Widget* widget = 0, bool with_subscription = false) { @@ -111,8 +110,6 @@ public: std::unique_ptr<ModelMapper> m_mapper; }; -TestMapperForItem::~TestMapperForItem() = default; - TEST_F(TestMapperForItem, test_initialCondition) { Widget w; diff --git a/Tests/UnitTests/GUI/TestMessageService.cpp b/Tests/UnitTests/GUI/TestMessageService.cpp index b3089712decfe11de2dcc9fb3a8d679ebdf347e3..3ed72f0fb48b708d569484f1f350f17d827ebf96 100644 --- a/Tests/UnitTests/GUI/TestMessageService.cpp +++ b/Tests/UnitTests/GUI/TestMessageService.cpp @@ -26,7 +26,7 @@ public: class Sender : public QObject { public: - Sender(const QString& name) { setObjectName(name); } + explicit Sender(const QString& name) { setObjectName(name); } }; }; diff --git a/Tests/UnitTests/GUI/TestModelUtils.cpp b/Tests/UnitTests/GUI/TestModelUtils.cpp index cfaadcfa4e19c5dd3039f23b4343872ebaff3c12..4735e92a07707920638d289acb6357cc45175269 100644 --- a/Tests/UnitTests/GUI/TestModelUtils.cpp +++ b/Tests/UnitTests/GUI/TestModelUtils.cpp @@ -34,7 +34,7 @@ TEST_F(TestModelUtils, test_topItemNames) // inserting three top items auto item = model.insertNewItem("MultiLayer"); item->setItemName("name1"); - item = model.insertNewItem("Layer"); + model.insertNewItem("Layer"); item = model.insertNewItem("MultiLayer"); item->setItemName("name2"); diff --git a/Tests/UnitTests/GUI/TestSavingSpecularData.cpp b/Tests/UnitTests/GUI/TestSavingSpecularData.cpp index b5e6666bab93340737d4c61872d04189a979d9b7..c6c650ad1c6cb1da385090c63b1bc4c39173bc1b 100644 --- a/Tests/UnitTests/GUI/TestSavingSpecularData.cpp +++ b/Tests/UnitTests/GUI/TestSavingSpecularData.cpp @@ -150,7 +150,7 @@ TEST_F(TestSavingSpecularData, test_setLastModified) EXPECT_FALSE(info.wasModifiedSinceLastSave()); QTest::qSleep(nap_time); - item->init(*m_axis.get(), "Degrees"); + item->init(*m_axis, "Degrees"); EXPECT_TRUE(info.wasModifiedSinceLastSave()); info = OutputDataSaveInfo::createSaved(item);