Skip to content

Commit

Permalink
Clean up cmake organisation (#946)
Browse files Browse the repository at this point in the history
- Clean up CMake organisation. Place headers in include directories
- Include directories follow the convention
<project-name/inner/directory/header.h>
- Remove use of "get properties" and use target_include/target_link
CMake convention

---------

Co-authored-by: Abdoulbari Zaher <[email protected]>
  • Loading branch information
JasonMarechal25 and a-zakir authored Oct 16, 2024
1 parent b73e383 commit c042044
Show file tree
Hide file tree
Showing 342 changed files with 1,294 additions and 1,162 deletions.
Empty file added CMakeGraphVizOptions.cmake
Empty file.
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_by_batch/BatchCollection.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "BatchCollection.h"
#include "antares-xpansion/benders/benders_by_batch/BatchCollection.h"

#include <cmath>
#include <iostream>
Expand Down
8 changes: 4 additions & 4 deletions src/cpp/benders/benders_by_batch/BendersByBatch.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "BendersByBatch.h"
#include "antares-xpansion/benders/benders_by_batch/BendersByBatch.h"

#include <algorithm>
#include <functional>
#include <mutex>
#include <numeric>

#include "BatchCollection.h"
#include "CustomVector.h"
#include "RandomBatchShuffler.h"
#include "antares-xpansion/benders/benders_by_batch/BatchCollection.h"
#include "antares-xpansion/benders/benders_core/CustomVector.h"
#include "antares-xpansion/benders/benders_by_batch/RandomBatchShuffler.h"

BendersByBatch::BendersByBatch(
BendersBaseOptions const &options, Logger logger, Writer writer,
Expand Down
57 changes: 31 additions & 26 deletions src/cpp/benders/benders_by_batch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,41 @@
# Targets
# ===========================================================================
find_package(MPI REQUIRED)
find_package (MPI REQUIRED COMPONENTS C)
message ("MPI_C_INCLUDE_PATH ${MPI_C_INCLUDE_PATH}")
message ("MPI_C_INCLUDE_DIRS ${MPI_C_INCLUDE_DIRS}")
message ("MPI_C_LIBRARIES ${MPI_C_LIBRARIES}")
find_package(MPI REQUIRED COMPONENTS C)
message("MPI_C_INCLUDE_PATH ${MPI_C_INCLUDE_PATH}")
message("MPI_C_INCLUDE_DIRS ${MPI_C_INCLUDE_DIRS}")
message("MPI_C_LIBRARIES ${MPI_C_LIBRARIES}")


if(UNIX)
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})
endif()
add_library (benders_by_batch_core STATIC
${CMAKE_CURRENT_SOURCE_DIR}/BendersByBatch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BatchCollection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RandomBatchShuffler.cpp
)
if (UNIX)
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})
endif ()
add_library(benders_by_batch_core)
target_sources(benders_by_batch_core PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/BatchCollection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersByBatch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RandomBatchShuffler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_by_batch/BatchCollection.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_by_batch/BendersByBatch.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_by_batch/RandomBatchShuffler.h
)

target_include_directories (benders_by_batch_core
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
target_include_directories(benders_by_batch_core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries (benders_by_batch_core
PUBLIC
benders_core
benders_sequential_core
benders_mpi_core
helpers
output_core
solvers
target_link_libraries(benders_by_batch_core
PUBLIC
antaresXpansion::benders_core
antaresXpansion::benders_sequential_core
antaresXpansion::benders_mpi_core
antaresXpansion::helpers
antaresXpansion::output_core
antaresXpansion::solvers
)

add_library (${PROJECT_NAME}::benders_by_batch_core ALIAS benders_by_batch_core)
add_library(${PROJECT_NAME}::benders_by_batch_core ALIAS benders_by_batch_core)
install(DIRECTORY include/antares-xpansion
DESTINATION "include"
)
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_by_batch/RandomBatchShuffler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "RandomBatchShuffler.h"
#include "antares-xpansion/benders/benders_by_batch/RandomBatchShuffler.h"

std::vector<unsigned> RandomBatchShuffler::GetCyclicBatchOrder(
unsigned batch_counter) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <vector>

#include "ILogger.h"
#include "antares-xpansion/xpansion_interfaces/ILogger.h"

struct Batch {
std::vector<std::string> sub_problem_names;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SRC_CPP_BENDERS_BENDERS_BY_BATCH_INCLUDE_BENDERSBYBATCH_H_
#define SRC_CPP_BENDERS_BENDERS_BY_BATCH_INCLUDE_BENDERSBYBATCH_H_
#include "BatchCollection.h"
#include "BendersMPI.h"
#include "common_mpi.h"
#include "antares-xpansion/benders/benders_mpi/BendersMPI.h"
#include "antares-xpansion/benders/benders_mpi/common_mpi.h"

class BendersByBatch : public BendersMpi {
std::vector<unsigned> random_batch_permutation_;
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/benders/benders_core/BendersBase.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "BendersBase.h"
#include "antares-xpansion/benders/benders_core/BendersBase.h"

#include <memory>
#include <mutex>
#include <numeric>
#include <utility>

#include "LastIterationPrinter.h"
#include "LastIterationReader.h"
#include "LastIterationWriter.h"
#include "LogUtils.h"
#include "solver_utils.h"
#include "antares-xpansion/benders/benders_core/LastIterationPrinter.h"
#include "antares-xpansion/benders/benders_core/LastIterationReader.h"
#include "antares-xpansion/benders/benders_core/LastIterationWriter.h"
#include "antares-xpansion/xpansion_interfaces/LogUtils.h"
#include "antares-xpansion/helpers/solver_utils.h"

BendersBase::BendersBase(const BendersBaseOptions &options, Logger logger,
Writer writer,
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/benders/benders_core/BendersMathLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "BendersMathLogger.h"
#include "antares-xpansion/benders/benders_core/BendersMathLogger.h"

#include <iomanip>
#include <sstream>

#include "LogUtils.h"
#include "LoggerUtils.h"
#include "antares-xpansion/xpansion_interfaces/LogUtils.h"
#include "antares-xpansion/helpers/LoggerUtils.h"

HeadersManager::HeadersManager(HEADERSTYPE type, const BENDERSMETHOD& method)
: type_(type), method_(method) {}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/BendersStructsDatas.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "BendersStructsDatas.h"
#include "antares-xpansion/benders/benders_core/BendersStructsDatas.h"

/*!
* \brief Get point
Expand Down
73 changes: 47 additions & 26 deletions src/cpp/benders/benders_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,56 @@
# Targets
# ===========================================================================

add_library (benders_core STATIC
${CMAKE_CURRENT_SOURCE_DIR}/SubproblemWorker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SimulationOptions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersBase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/WorkerMaster.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersStructsDatas.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Worker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationWriter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationReader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationPrinter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StartUp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersMathLogger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MasterUpdateBase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/CutsManagement.cpp
add_library(benders_core)
target_sources(benders_core PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/BendersBase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersMathLogger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersStructsDatas.cpp
${CMAKE_CURRENT_SOURCE_DIR}/CutsManagement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationPrinter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationReader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationWriter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MasterUpdateBase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SimulationOptions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StartUp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SubproblemWorker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Worker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/WorkerMaster.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/BendersBase.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/BendersMathLogger.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/BendersStructsDatas.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/CustomVector.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/CutsManagement.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/LastIterationPrinter.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/LastIterationReader.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/LastIterationWriter.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/MasterUpdate.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/SimulationOptions.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/StartUp.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/SubproblemWorker.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/Worker.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/WorkerMaster.h
${CMAKE_CURRENT_SOURCE_DIR}/include/antares-xpansion/benders/benders_core/common.h
)

)
add_library(antaresXpansion::benders_core ALIAS benders_core)


target_include_directories (benders_core
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
target_include_directories(benders_core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries (benders_core
PUBLIC
helpers
output_core
solvers
${JSONCPP_LIB}
outer_loop_lib
target_link_libraries(benders_core
PUBLIC
antaresXpansion::helpers
antaresXpansion::output_core
antaresXpansion::solvers
${JSONCPP_LIB}
antaresXpansion::outer_loop_lib
)

install(DIRECTORY include/antares-xpansion
DESTINATION "include"
)
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/CutsManagement.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "CutsManagement.h"
#include "antares-xpansion/benders/benders_core/CutsManagement.h"

using namespace Outerloop;

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/LastIterationPrinter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "LastIterationPrinter.h"
#include "antares-xpansion/benders/benders_core/LastIterationPrinter.h"

#include <iostream>

Expand Down
4 changes: 2 additions & 2 deletions src/cpp/benders/benders_core/LastIterationReader.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include "LastIterationReader.h"
#include "antares-xpansion/benders/benders_core/LastIterationReader.h"

#include <fstream>
#include <iostream>

#include "common.h"
#include "antares-xpansion/benders/benders_core/common.h"

LastIterationReader::LastIterationReader(
const std::filesystem::path& last_iteration_file)
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/LastIterationWriter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "LastIterationWriter.h"
#include "antares-xpansion/benders/benders_core/LastIterationWriter.h"

#include <fstream>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/MasterUpdateBase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <utility>

#include "MasterUpdate.h"
#include "antares-xpansion/benders/benders_core/MasterUpdate.h"

using namespace Outerloop;

Expand Down
10 changes: 5 additions & 5 deletions src/cpp/benders/benders_core/SimulationOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "SimulationOptions.h"
#include "antares-xpansion/benders/benders_core/SimulationOptions.h"

#include <json/json.h>

#include <filesystem>

#include "LogUtils.h"
#include "antares-xpansion/xpansion_interfaces/LogUtils.h"
Json::Value SimulationOptions::get_value_from_json(
const std::filesystem::path &file_name) {
Json::Value _input;
Expand All @@ -28,7 +28,7 @@ SimulationOptions::SimulationOptions()
#define BENDERS_OPTIONS_MACRO(name__, type__, default__, \
deserialization_method__) \
name__(default__),
#include "SimulationOptions.hxx"
#include "antares-xpansion/benders/benders_core/SimulationOptions.hxx"
#undef BENDERS_OPTIONS_MACRO
_weights() {
}
Expand Down Expand Up @@ -64,7 +64,7 @@ void SimulationOptions::read(const std::filesystem::path &file_name) {
deserialization_method__) \
if (#var__ == var_name) \
var__ = options_values[var_name].deserialization_method__;
#include "SimulationOptions.hxx"
#include "antares-xpansion/benders/benders_core/SimulationOptions.hxx"
#undef BENDERS_OPTIONS_MACRO
}
set_weights();
Expand Down Expand Up @@ -116,7 +116,7 @@ void SimulationOptions::print(std::ostream &stream) const {
#define BENDERS_OPTIONS_MACRO(name__, type__, default__, \
deserialization_method__) \
stream << std::setw(30) << #name__ << std::setw(50)<<std::boolalpha << name__ << std::endl;
#include "SimulationOptions.hxx"
#include "antares-xpansion/benders/benders_core/SimulationOptions.hxx"
#undef BENDERS_OPTIONS_MACRO
stream << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/StartUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by marechaljas on 02/08/22.
//

#include "StartUp.h"
#include "antares-xpansion/benders/benders_core/StartUp.h"

namespace Benders {

Expand Down
4 changes: 2 additions & 2 deletions src/cpp/benders/benders_core/SubproblemWorker.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "SubproblemWorker.h"
#include "antares-xpansion/benders/benders_core/SubproblemWorker.h"

#include "solver_utils.h"
#include "antares-xpansion/helpers/solver_utils.h"

/*!
* \brief Constructor of a Worker Slave
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/benders/benders_core/Worker.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Worker.h"
#include "antares-xpansion/benders/benders_core/Worker.h"

#include "LogUtils.h"
#include "antares-xpansion/xpansion_interfaces/LogUtils.h"

#include "solver_utils.h"
#include "antares-xpansion/helpers/solver_utils.h"
/*!
* \brief Free the problem
*/
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/benders/benders_core/WorkerMaster.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "WorkerMaster.h"
#include "antares-xpansion/benders/benders_core/WorkerMaster.h"


#include "solver_utils.h"
#include "antares-xpansion/helpers/solver_utils.h"

WorkerMaster::WorkerMaster(Logger logger) : Worker(logger) {
_is_master = true;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/common.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.h"
#include "antares-xpansion/benders/benders_core/common.h"

/*!
* \brief Return the distance between two point using 2-norm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#include "BendersMathLogger.h"
#include "BendersStructsDatas.h"
#include "ILogger.h"
#include "OutputWriter.h"
#include "antares-xpansion/xpansion_interfaces/ILogger.h"
#include "antares-xpansion/xpansion_interfaces/OutputWriter.h"
#include "SimulationOptions.h"
#include "SubproblemCut.h"
#include "SubproblemWorker.h"
#include "Timer.h"
#include "antares-xpansion/helpers/Timer.h"
#include "Worker.h"
#include "WorkerMaster.h"
#include "common.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <memory>

#include "BendersStructsDatas.h"
#include "ILogger.h"
#include "antares-xpansion/xpansion_interfaces/ILogger.h"
#include "common.h"
const std::string MATHLOGGERCONTEXT = "Benders";

Expand Down
Loading

0 comments on commit c042044

Please sign in to comment.