diff options
author | Brad King <brad.king@kitware.com> | 2009-10-21 17:10:24 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-10-21 17:10:24 (GMT) |
commit | 22cbfefb76b66d12e2e7346b08e08dec19305f70 (patch) | |
tree | d435c6215ff5404daa0e0474ddcc14d35b3aac40 /Source | |
parent | 3c326476ee63b91a2a240641da7e405d3e770bb3 (diff) | |
download | CMake-22cbfefb76b66d12e2e7346b08e08dec19305f70.zip CMake-22cbfefb76b66d12e2e7346b08e08dec19305f70.tar.gz CMake-22cbfefb76b66d12e2e7346b08e08dec19305f70.tar.bz2 |
Factor out "cmake -E cmake_symlink_*" code
We factor the implementation of
cmake -E cmake_symlink_library
cmake -E cmake_symlink_executable
out of cmake::ExecuteCMakeCommand into methods
cmake::SymlinkLibrary
cmake::SymlinkExecutable
plus a helper method cmake::SymlinkInternal.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmake.cxx | 108 | ||||
-rw-r--r-- | Source/cmake.h | 4 |
2 files changed, 61 insertions, 51 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 48a0e83..24b6443 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1377,61 +1377,12 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args) // Internal CMake shared library support. else if (args[1] == "cmake_symlink_library" && args.size() == 5) { - int result = 0; - std::string realName = args[2]; - std::string soName = args[3]; - std::string name = args[4]; - if(soName != realName) - { - std::string fname = cmSystemTools::GetFilenameName(realName); - if(cmSystemTools::FileExists(soName.c_str()) || - cmSystemTools::FileIsSymlink(soName.c_str())) - { - cmSystemTools::RemoveFile(soName.c_str()); - } - if(!cmSystemTools::CreateSymlink(fname.c_str(), soName.c_str())) - { - cmSystemTools::ReportLastSystemError("cmake_symlink_library"); - result = 1; - } - } - if(name != soName) - { - std::string fname = cmSystemTools::GetFilenameName(soName); - if(cmSystemTools::FileExists(name.c_str()) || - cmSystemTools::FileIsSymlink(name.c_str())) - { - cmSystemTools::RemoveFile(name.c_str()); - } - if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str())) - { - cmSystemTools::ReportLastSystemError("cmake_symlink_library"); - result = 1; - } - } - return result; + return cmake::SymlinkLibrary(args); } // Internal CMake versioned executable support. else if (args[1] == "cmake_symlink_executable" && args.size() == 4) { - int result = 0; - std::string realName = args[2]; - std::string name = args[3]; - if(name != realName) - { - std::string fname = cmSystemTools::GetFilenameName(realName); - if(cmSystemTools::FileExists(name.c_str()) || - cmSystemTools::FileIsSymlink(name.c_str())) - { - cmSystemTools::RemoveFile(name.c_str()); - } - if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str())) - { - cmSystemTools::ReportLastSystemError("cmake_symlink_executable"); - result = 1; - } - } - return result; + return cmake::SymlinkExecutable(args); } #if defined(CMAKE_HAVE_VS_GENERATORS) @@ -3128,6 +3079,61 @@ void cmake::GenerateGraphViz(const char* fileName) const } //---------------------------------------------------------------------------- +int cmake::SymlinkLibrary(std::vector<std::string>& args) +{ + int result = 0; + std::string realName = args[2]; + std::string soName = args[3]; + std::string name = args[4]; + if(soName != realName) + { + if(!cmake::SymlinkInternal(realName, soName)) + { + cmSystemTools::ReportLastSystemError("cmake_symlink_library"); + result = 1; + } + } + if(name != soName) + { + if(!cmake::SymlinkInternal(soName, name)) + { + cmSystemTools::ReportLastSystemError("cmake_symlink_library"); + result = 1; + } + } + return result; +} + +//---------------------------------------------------------------------------- +int cmake::SymlinkExecutable(std::vector<std::string>& args) +{ + int result = 0; + std::string realName = args[2]; + std::string name = args[3]; + if(name != realName) + { + if(!cmake::SymlinkInternal(realName, name)) + { + cmSystemTools::ReportLastSystemError("cmake_symlink_executable"); + result = 1; + } + } + return result; +} + +//---------------------------------------------------------------------------- +bool cmake::SymlinkInternal(std::string const& file, std::string const& link) +{ + if(cmSystemTools::FileExists(link.c_str()) || + cmSystemTools::FileIsSymlink(link.c_str())) + { + cmSystemTools::RemoveFile(link.c_str()); + } + std::string linktext = cmSystemTools::GetFilenameName(file); + return cmSystemTools::CreateSymlink(linktext.c_str(), link.c_str()); +} + +//---------------------------------------------------------------------------- #ifdef CMAKE_BUILD_WITH_CMAKE int cmake::ExecuteEchoColor(std::vector<std::string>& args) { diff --git a/Source/cmake.h b/Source/cmake.h index f983dc2..37e38b7 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -414,6 +414,10 @@ protected: void GenerateGraphViz(const char* fileName) const; + static int SymlinkLibrary(std::vector<std::string>& args); + static int SymlinkExecutable(std::vector<std::string>& args); + static bool SymlinkInternal(std::string const& file, + std::string const& link); static int ExecuteEchoColor(std::vector<std::string>& args); static int ExecuteLinkScript(std::vector<std::string>& args); static int VisualStudioLink(std::vector<std::string>& args, int type); |