From 4419139bd1d7ee5bd89aa0c004e3a6c23ecd6005 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 29 Jan 2024 17:00:32 +0100 Subject: [PATCH] CMake first working compilation for library --- CMakeLists.txt | 2 +- config.h.in | 0 lib/CMakeLists.txt | 19 ++++++++++++------- lib/LatAnalyze/Core/Plot.cpp | 4 ++-- lib/LatAnalyze/Global.cpp | 9 ++++----- lib/LatAnalyze/Numerical/MinuitMinimizer.cpp | 4 ++++ lib/LatAnalyze/Statistics/XYSampleData.cpp | 6 +++--- lib/LatAnalyze/Statistics/XYStatData.cpp | 6 +++--- lib/config.h.in | 2 ++ 9 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 config.h.in create mode 100644 lib/config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cbc817..2f1a540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project( LatAnalyze VERSION 3.6 LANGUAGES C CXX) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) include(FetchContent) include(FindPackageMessage) diff --git a/config.h.in b/config.h.in deleted file mode 100644 index e69de29..0000000 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 91cbb62..da7bdd5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,33 +1,37 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") +configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) + include(FindBISON) include(FindFLEX) find_package(BISON REQUIRED) find_package(FLEX REQUIRED) -bison_target(AsciiParser LatAnalyze/Io/AsciiParser.ypp - ${CMAKE_CURRENT_BINARY_DIR}/AsciiParser.cpp - COMPILE_FLAGS "-Wno-deprecated") +bison_target( + AsciiParser LatAnalyze/Io/AsciiParser.ypp + ${CMAKE_CURRENT_BINARY_DIR}/AsciiParser.cpp COMPILE_FLAGS "-Wno-deprecated") flex_target(AsciiLexer LatAnalyze/Io/AsciiLexer.lpp ${CMAKE_CURRENT_BINARY_DIR}/AsciiLexer.cpp) add_flex_bison_dependency(AsciiLexer AsciiParser) -bison_target(MathParser LatAnalyze/Core/MathParser.ypp - ${CMAKE_CURRENT_BINARY_DIR}/MathParser.cpp - COMPILE_FLAGS "-Wno-deprecated") +bison_target( + MathParser LatAnalyze/Core/MathParser.ypp + ${CMAKE_CURRENT_BINARY_DIR}/MathParser.cpp COMPILE_FLAGS "-Wno-deprecated") flex_target(MathLexer LatAnalyze/Core/MathLexer.lpp ${CMAKE_CURRENT_BINARY_DIR}/MathLexer.cpp) add_flex_bison_dependency(MathLexer MathParser) add_library(LatAnalyze SHARED) file(GLOB_RECURSE EIGEN_HEADERS Eigen/*) +target_include_directories(LatAnalyze PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_sources( LatAnalyze PRIVATE ${BISON_AsciiParser_OUTPUTS} ${FLEX_AsciiLexer_OUTPUTS} ${BISON_MathParser_OUTPUTS} ${FLEX_MathLexer_OUTPUTS} + ${CMAKE_CURRENT_BINARY_DIR}/config.h LatAnalyze/Core/Exceptions.cpp LatAnalyze/Core/Mat.cpp LatAnalyze/Core/Math.cpp @@ -128,4 +132,5 @@ target_sources( LatAnalyze/Statistics/XYSampleData.hpp LatAnalyze/Statistics/XYStatData.hpp LatAnalyze/includes.hpp) -target_link_libraries(LatAnalyze PUBLIC GSL::gsl HDF5 Minuit2 NLopt) +target_link_libraries(LatAnalyze PUBLIC GSL::gsl hdf5::hdf5 hdf5::hdf5_cpp + Minuit2::Minuit2 NLopt::nlopt) diff --git a/lib/LatAnalyze/Core/Plot.cpp b/lib/LatAnalyze/Core/Plot.cpp index 8377e90..143e45d 100644 --- a/lib/LatAnalyze/Core/Plot.cpp +++ b/lib/LatAnalyze/Core/Plot.cpp @@ -72,7 +72,7 @@ string PlotObject::dumpToTmpFile(const DMat &m) for (Index j = 0; j < m.cols(); ++j) { } - sprintf(tmpFileName, "%s/latan_plot_tmp.XXXXXX.dat", P_tmpdir); + snprintf(tmpFileName, sizeof(tmpFileName), "%s/latan_plot_tmp.XXXXXX.dat", P_tmpdir); fd = mkstemps(tmpFileName, 4); if (fd == -1) { @@ -699,7 +699,7 @@ Plot & Plot::operator<<(PlotModifier &&modifier) // find gnuplot //////////////////////////////////////////////////////////////// #define SEARCH_DIR(dir) \ -sprintf(buf, "%s/%s", dir, gnuplotBin_.c_str());\ +snprintf(buf, sizeof(buf), "%s/%s", dir, gnuplotBin_.c_str());\ if (access(buf, X_OK) == 0)\ {\ return dir;\ diff --git a/lib/LatAnalyze/Global.cpp b/lib/LatAnalyze/Global.cpp index 2b25d75..88cc082 100644 --- a/lib/LatAnalyze/Global.cpp +++ b/lib/LatAnalyze/Global.cpp @@ -25,11 +25,10 @@ using namespace Latan; PlaceHolder Latan::_; -const string Env::fullName = PACKAGE_STRING; -const string Env::name = PACKAGE_NAME; -const string Env::version = PACKAGE_VERSION; -const string Env::msgPrefix = "[" + strFrom(PACKAGE_NAME) + " v" - + strFrom(PACKAGE_VERSION) + "] "; +const string Env::fullName = strFrom(PROJECT_NAME) + " v" + strFrom(PROJECT_VERSION); +const string Env::name = PROJECT_NAME; +const string Env::version = PROJECT_VERSION; +const string Env::msgPrefix = "[" + Env::fullName + "] "; void Env::function(void) {} diff --git a/lib/LatAnalyze/Numerical/MinuitMinimizer.cpp b/lib/LatAnalyze/Numerical/MinuitMinimizer.cpp index bab7638..b39f90e 100644 --- a/lib/LatAnalyze/Numerical/MinuitMinimizer.cpp +++ b/lib/LatAnalyze/Numerical/MinuitMinimizer.cpp @@ -30,8 +30,12 @@ namespace ROOT }; // macros necessary in the ROOT-based version of Minuit2 +#ifndef ROOT_Math_VecTypes #define ROOT_Math_VecTypes +#endif +#ifndef MATHCORE_STANDALONE #define MATHCORE_STANDALONE +#endif #include #include diff --git a/lib/LatAnalyze/Statistics/XYSampleData.cpp b/lib/LatAnalyze/Statistics/XYSampleData.cpp index 8b5e0d9..d24a21a 100644 --- a/lib/LatAnalyze/Statistics/XYSampleData.cpp +++ b/lib/LatAnalyze/Statistics/XYSampleData.cpp @@ -108,15 +108,15 @@ void SampleFitResult::print(const bool printXsi, ostream &out) const Index pMax = printXsi ? size() : nPar_; DMat err = this->variance().cwiseSqrt(); - sprintf(buf, "chi^2/dof= %.1e/%d= %.2e -- chi^2 CCDF= %.2e -- p-value= %.2e", + snprintf(buf, sizeof(buf), "chi^2/dof= %.1e/%d= %.2e -- chi^2 CCDF= %.2e -- p-value= %.2e", getChi2(), static_cast(getNDof()), getChi2PerDof(), getCcdf(), getPValue()); out << buf << endl; - sprintf(buf, "correlation dynamic range= %.1f dB", getCorrRangeDb()); + snprintf(buf, sizeof(buf), "correlation dynamic range= %.1f dB", getCorrRangeDb()); out << buf << endl; for (Index p = 0; p < pMax; ++p) { - sprintf(buf, "%12s= % e +/- %e", parName_[p].c_str(), + snprintf(buf, sizeof(buf), "%12s= % e +/- %e", parName_[p].c_str(), (*this)[central](p), err(p)); out << buf << endl; } diff --git a/lib/LatAnalyze/Statistics/XYStatData.cpp b/lib/LatAnalyze/Statistics/XYStatData.cpp index b83397f..35833cd 100644 --- a/lib/LatAnalyze/Statistics/XYStatData.cpp +++ b/lib/LatAnalyze/Statistics/XYStatData.cpp @@ -76,15 +76,15 @@ void FitResult::print(const bool printXsi, ostream &out) const char buf[256]; Index pMax = printXsi ? size() : nPar_; - sprintf(buf, "chi^2/dof= %.1e/%d= %.2e -- chi^2 CCDF= %.2e -- p-value= %.2e", + snprintf(buf, sizeof(buf), "chi^2/dof= %.1e/%d= %.2e -- chi^2 CCDF= %.2e -- p-value= %.2e", getChi2(), static_cast(getNDof()), getChi2PerDof(), getCcdf(), getPValue()); out << buf << endl; - sprintf(buf, "correlation dynamic range= %.1f dB", getCorrRangeDb()); + snprintf(buf, sizeof(buf), "correlation dynamic range= %.1f dB", getCorrRangeDb()); out << buf << endl; for (Index p = 0; p < pMax; ++p) { - sprintf(buf, "%12s= %e", parName_[p].c_str(), (*this)(p)); + snprintf(buf, sizeof(buf), "%12s= %e", parName_[p].c_str(), (*this)(p)); out << buf << endl; } } diff --git a/lib/config.h.in b/lib/config.h.in new file mode 100644 index 0000000..a447c65 --- /dev/null +++ b/lib/config.h.in @@ -0,0 +1,2 @@ +#cmakedefine PROJECT_NAME "@PROJECT_NAME@" +#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"