From 56148fd2bc5ddbf32b89bbf94034ea4b14c6716d Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 20 Jun 2012 11:04:35 -0400 Subject: Do not crash on SHARED library without language (#13324) Since commit e1409ac5 (Support building shared libraries or modules without soname, 2012-04-22) CMake crashes on the code add_library(foo SHARED foo.nolang) because the logic to lookup the language's soname flag was moved from cmTarget::GetLibraryNames to cmMakefile::GetSONameFlag without its check for a NULL language. Restore the check for NULL. Add RunCMake.Languages test to cover language error cases like this one. --- Source/cmMakefile.cxx | 8 ++++++-- Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/Languages/CMakeLists.txt | 3 +++ Tests/RunCMake/Languages/NoLangSHARED-result.txt | 1 + Tests/RunCMake/Languages/NoLangSHARED-stderr.txt | 1 + Tests/RunCMake/Languages/NoLangSHARED.cmake | 1 + Tests/RunCMake/Languages/RunCMakeTest.cmake | 3 +++ Tests/RunCMake/Languages/foo.nolang | 0 8 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/Languages/CMakeLists.txt create mode 100644 Tests/RunCMake/Languages/NoLangSHARED-result.txt create mode 100644 Tests/RunCMake/Languages/NoLangSHARED-stderr.txt create mode 100644 Tests/RunCMake/Languages/NoLangSHARED.cmake create mode 100644 Tests/RunCMake/Languages/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/Languages/foo.nolang diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0a709ae..1d78b3a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2197,8 +2197,12 @@ bool cmMakefile::PlatformIs64Bit() const const char* cmMakefile::GetSONameFlag(const char* language) const { - std::string name = "CMAKE_SHARED_LIBRARY_SONAME_"; - name += language; + std::string name = "CMAKE_SHARED_LIBRARY_SONAME"; + if(language) + { + name += "_"; + name += language; + } name += "_FLAG"; return GetDefinition(name.c_str()); } diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 1c6db39..23fc086 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -45,6 +45,7 @@ macro(add_RunCMake_test test) ) endmacro() +add_RunCMake_test(Languages) add_RunCMake_test(ObjectLibrary) add_RunCMake_test(build_command) diff --git a/Tests/RunCMake/Languages/CMakeLists.txt b/Tests/RunCMake/Languages/CMakeLists.txt new file mode 100644 index 0000000..e8db6b0 --- /dev/null +++ b/Tests/RunCMake/Languages/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/Languages/NoLangSHARED-result.txt b/Tests/RunCMake/Languages/NoLangSHARED-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Languages/NoLangSHARED-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Languages/NoLangSHARED-stderr.txt b/Tests/RunCMake/Languages/NoLangSHARED-stderr.txt new file mode 100644 index 0000000..3f93cf8 --- /dev/null +++ b/Tests/RunCMake/Languages/NoLangSHARED-stderr.txt @@ -0,0 +1 @@ +CMake Error: CMake can not determine linker language for target:NoLang diff --git a/Tests/RunCMake/Languages/NoLangSHARED.cmake b/Tests/RunCMake/Languages/NoLangSHARED.cmake new file mode 100644 index 0000000..de6adf7 --- /dev/null +++ b/Tests/RunCMake/Languages/NoLangSHARED.cmake @@ -0,0 +1 @@ +add_library(NoLang SHARED foo.nolang) diff --git a/Tests/RunCMake/Languages/RunCMakeTest.cmake b/Tests/RunCMake/Languages/RunCMakeTest.cmake new file mode 100644 index 0000000..a99548f --- /dev/null +++ b/Tests/RunCMake/Languages/RunCMakeTest.cmake @@ -0,0 +1,3 @@ +include(RunCMake) + +run_cmake(NoLangSHARED) diff --git a/Tests/RunCMake/Languages/foo.nolang b/Tests/RunCMake/Languages/foo.nolang new file mode 100644 index 0000000..e69de29 -- cgit v0.12