Skip to content

Commit

Permalink
CMake first working compilation for library
Browse files Browse the repository at this point in the history
  • Loading branch information
aportelli committed Jan 29, 2024
1 parent 0b5c6e8 commit 4419139
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Empty file removed config.h.in
Empty file.
19 changes: 12 additions & 7 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions lib/LatAnalyze/Core/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;\
Expand Down
9 changes: 4 additions & 5 deletions lib/LatAnalyze/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}
4 changes: 4 additions & 0 deletions lib/LatAnalyze/Numerical/MinuitMinimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Minuit2/Minuit2Minimizer.h>
#include <Math/Functor.h>
Expand Down
6 changes: 3 additions & 3 deletions lib/LatAnalyze/Statistics/XYSampleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/LatAnalyze/Statistics/XYStatData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"

0 comments on commit 4419139

Please sign in to comment.