Adds option ("-gs") to generate git submodule downloading/checking code to the root cmake file

master
Joey Pollack 4 years ago
parent ceadcc1802
commit 8423f5e40c

@ -44,6 +44,7 @@ int main(int argc, char** argv)
argParser.AddArg(ArgDesc("-a", true, 1, "Add library projects, separated by ',' (ex: -a first,second,third)")); argParser.AddArg(ArgDesc("-a", true, 1, "Add library projects, separated by ',' (ex: -a first,second,third)"));
argParser.AddArg(ArgDesc("-x", true, 1, "Add executable submodule projects, separated by ',' (ex: -x first,second,third)")); argParser.AddArg(ArgDesc("-x", true, 1, "Add executable submodule projects, separated by ',' (ex: -x first,second,third)"));
argParser.AddArg(ArgDesc("-r", true, 0, "Remove the root project executable")); argParser.AddArg(ArgDesc("-r", true, 0, "Remove the root project executable"));
argParser.AddArg(ArgDesc("-gs", true, 0, "Add git subsystem updating to the main cmake file."));
bool result = argParser.Parse(); bool result = argParser.Parse();
@ -223,7 +224,7 @@ int main(int argc, char** argv)
ofs << "\nset(CMAKE_CXX_STANDARD " << cversion << ")"; ofs << "\nset(CMAKE_CXX_STANDARD " << cversion << ")";
ofs << "\nset(CMAKE_CXX_STANDARD_REQUIRED True)"; ofs << "\nset(CMAKE_CXX_STANDARD_REQUIRED True)";
ofs << "\n# setup target output directories"; ofs << "\n\n# setup target output directories";
ofs << "\nset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)"; ofs << "\nset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)";
ofs << "\nset(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)"; ofs << "\nset(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)";
ofs << "\nset(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)"; ofs << "\nset(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)";
@ -246,7 +247,46 @@ int main(int argc, char** argv)
ofs << "\n\tPUBLIC src"; ofs << "\n\tPUBLIC src";
ofs << "\n)"; ofs << "\n)";
// Link to any libs that exist if (argParser.ContainsOption("-gs"))
{
ofs << "\n\n# DOWNLOAD ALL SUBMODULES";
ofs << "\nfind_package(Git QUIET)";
ofs << "\nif(GIT_FOUND AND EXISTS \"${PROJECT_SOURCE_DIR}/.git\")";
ofs << "\n# Update submodules as needed";
ofs << "\n option(GIT_SUBMODULE \"Check submodules during build\" ON)";
ofs << "\n if(GIT_SUBMODULE)";
ofs << "\n message(STATUS \"Submodule update\")";
ofs << "\n execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive";
ofs << "\n WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}";
ofs << "\n RESULT_VARIABLE GIT_SUBMOD_RESULT)";
ofs << "\n if(NOT GIT_SUBMOD_RESULT EQUAL \"0\")";
ofs << "\n message(FATAL_ERROR \"git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules\")";
ofs << "\n endif()";
ofs << "\n endif()";
ofs << "\nendif()";
ofs << "\n";
ofs << "\n# CHECK THAT ALL SUBMODULES EXIST";
ofs << "\n#if(NOT EXISTS \"${PROJECT_SOURCE_DIR}/external/<PROJECT ROOT DIRECTORY>/CMakeLists.txt\")";
ofs << "\n# message(FATAL_ERROR \"<PROJECT NAME> submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.\")";
ofs << "\n#endif()";
}
// include the libraries and submodules
ofs << "\n\n# add subdirectories here";
for (int i = 0; i < libraries.size(); i++)
{
ofs << "\nadd_subdirectory(src/" << libraries[i].c_str() << ")";
}
for (int i = 0; i < submods.size(); i++)
{
ofs << "\nadd_subdirectory(src/" << submods[i].c_str() << ")";
}
// Link to any libs that exist or add space to link to submodules added through git
if (libraries.size() > 0 || argParser.ContainsOption("-gs"))
{
ofs << "\n\ntarget_link_directories(${PROJECT_NAME} "; ofs << "\n\ntarget_link_directories(${PROJECT_NAME} ";
for (int i = 0; i < libraries.size(); i++) for (int i = 0; i < libraries.size(); i++)
{ {
@ -262,16 +302,6 @@ int main(int argc, char** argv)
ofs << ")"; ofs << ")";
} }
// include the libraries and submodules
for (int i = 0; i < libraries.size(); i++)
{
ofs << "\nadd_subdirectory(src/" << libraries[i].c_str() << ")";
}
for (int i = 0; i < submods.size(); i++)
{
ofs << "\nadd_subdirectory(src/" << submods[i].c_str() << ")";
} }
ofs.close(); ofs.close();

Loading…
Cancel
Save