Skip to content

Commit 66ec15a

Browse files
committed
Improved migration tool
* fixed tool to keep custom content of main CMakeLists.txt
1 parent cdf44f3 commit 66ec15a

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

CMake.in.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SET(OFBUILD_CUSTOM_CMAKE_VERSION "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.
2323
SET(OPENFLUID_VERSION_MAJOR 2)
2424
SET(OPENFLUID_VERSION_MINOR 2)
2525
SET(OPENFLUID_VERSION_PATCH 1)
26-
SET(OPENFLUID_VERSION_STATUS "alpha4") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
26+
SET(OPENFLUID_VERSION_STATUS "alpha5") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
2727

2828
SET(OPENFLUID_VERSION_FULL "${OPENFLUID_VERSION_MAJOR}.${OPENFLUID_VERSION_MINOR}.${OPENFLUID_VERSION_PATCH}")
2929

resources/tests/miscsrc/wares-dev-201xx/sim/tests.cmdline.sim-migration/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ INCLUDE(CMake.in.config)
55

66
FIND_PACKAGE(OpenFLUIDHelpers REQUIRED)
77

8+
SET(CUSTOM_VAR foo)
9+
810
OPENFLUID_ADD_SIMULATOR(SIM)
11+
12+
MESSAGE(STATUS "custom message")

src/apps/openfluid/tests/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,11 @@ OPENFLUID_ADD_TEST(NAME cmdline-openfluid-MigrateSimulator
587587
POST_TEST CHECK_FILE_EXIST "${OFBUILD_TMP_DIR}/cmdline/migrate-ware/sim/tests.cmdline.sim-migration/src/CMakeLists.txt"
588588
POST_TEST CHECK_FILE_IDENTICAL "${OFBUILD_TMP_DIR}/cmdline/migrate-ware/sim/tests.cmdline.sim-migration/"
589589
"${OFBUILD_TMP_DIR}/cmdline/migrate-ware/sim/tests.cmdline.sim-migration/src/REF/"
590-
"openfluid-ware.json")
590+
"openfluid-ware.json"
591+
POST_TEST CHECK_FILE_CONTAINS "${OFBUILD_TMP_DIR}/cmdline/migrate-ware/sim/tests.cmdline.sim-migration/src/CMakeLists.txt"
592+
"SET(CUSTOM_VAR foo)"
593+
POST_TEST CHECK_FILE_CONTAINS "${OFBUILD_TMP_DIR}/cmdline/migrate-ware/sim/tests.cmdline.sim-migration/src/CMakeLists.txt"
594+
"MESSAGE(STATUS \"custom message\")")
591595
SET_PROPERTY(TEST cmdline-openfluid-MigrateSimulator
592596
APPEND PROPERTY ENVIRONMENT "OpenFLUID_DIR=${OFBUILD_DIST_CMAKE_MODULES_DIR};OpenFLUID_EXTRA_SEARCH_PATHS=${CMAKE_BINARY_DIR}/src\;${OFBUILD_DIST_DIR};OpenFLUID_MIGRATION_INCLUDE_PATHS=${CMAKE_SOURCE_DIR}/src")
593597
set_tests_properties(cmdline-openfluid-MigrateSimulator PROPERTIES FIXTURES_SETUP SimulatorMigrated)

src/openfluid/waresdev/WareSrcMigrator.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,12 +963,14 @@ WareSrcMigrator::processCMakeFiles(const WareSrcMigrator::WareMigrationInfo& Inf
963963
mp_Listener->stageMessage("processing " + openfluid::config::WARESDEV_SRC_CMAKESTDFILE);
964964

965965
auto CMakeWareVar = Info.CMakeDefaultWareVar;
966+
std::vector<std::string> CMakeContentLines;
966967

967968
auto CMakeFileObj = m_SrcPathObj.fromThis(openfluid::config::WARESDEV_SRC_CMAKESTDFILE);
968969
if (CMakeFileObj.isFile())
969970
{
970971
// search for correct variable name
971972
auto CMakeContent = openfluid::tools::Filesystem::readFile(CMakeFileObj);
973+
CMakeContentLines = getFileLines(CMakeFileObj);
972974
if (!CMakeContent.empty())
973975
{
974976
// search for default
@@ -1020,6 +1022,36 @@ WareSrcMigrator::processCMakeFiles(const WareSrcMigrator::WareMigrationInfo& Inf
10201022
return (L.empty() || L[0] == '#');
10211023
}),
10221024
ConfigLines.end());
1025+
1026+
std::vector<std::string> CustomContentLines;
1027+
bool IsCustomCMakeContent = false;
1028+
for (std::vector<std::string>::size_type i=0; i<CMakeContentLines.size();i++)
1029+
{
1030+
std::list<std::string> DefaultLineBegins = {"PROJECT(", "CMAKE_MINIMUM_REQUIRED(", "INCLUDE(CMake.in.config)",
1031+
"FIND_PACKAGE(OpenFLUIDHelpers REQUIRED)", "OPENFLUID_ADD_"};
1032+
bool IsDefault = false;
1033+
for (const auto& Begin : DefaultLineBegins)
1034+
{
1035+
if (CMakeContentLines[i].substr(0,Begin.length()) == Begin)
1036+
{
1037+
IsDefault = true;
1038+
}
1039+
}
1040+
if (!IsDefault)
1041+
{
1042+
CustomContentLines.push_back(CMakeContentLines[i]);
1043+
if (CMakeContentLines[i].size() > 0)
1044+
{
1045+
IsCustomCMakeContent = true;
1046+
}
1047+
}
1048+
}
1049+
if (IsCustomCMakeContent)
1050+
{
1051+
ConfigLines.push_back("");
1052+
ConfigLines.push_back("# Custom content from main CMakeLists.txt");
1053+
ConfigLines.insert(ConfigLines.end(), CustomContentLines.begin(), CustomContentLines.end() );
1054+
}
10231055

10241056
const auto ConfigContent = openfluid::tools::join(ConfigLines," ");
10251057
std::map<std::string,std::string> ConfigVariables;

0 commit comments

Comments
 (0)