From ddc535741996b5ed42bb4d2c1bbcd371573a5bfd Mon Sep 17 00:00:00 2001 From: Andreas Schuh Date: Wed, 19 Mar 2014 17:32:23 +0000 Subject: [PATCH] Add link dependency on shlwapi.lib during build configuration instead of #pragma comment statement. Use this library also on MinGW. --- CMakeLists.txt | 8 +++++++- src/gflags.cc | 5 ++--- test/gflags_unittest.cc | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/gflags.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index fa456ea..66bbd4c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ else () check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H) endif () endforeach () - # the following are used in #if not #ifdef + # the following are used in #if directives not #ifdef bool_to_int (HAVE_STDINT_H) bool_to_int (HAVE_SYS_TYPES_H) bool_to_int (HAVE_INTTYPES_H) @@ -219,11 +219,17 @@ include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}") set (LIB_TARGETS) if (BUILD_gflags_LIB) add_library (gflags ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS}) + if (HAVE_SHLWAPI_H) + target_link_libraries (gflags shlwapi.lib) + endif () list (APPEND LIB_TARGETS gflags) endif () if (BUILD_gflags_nothreads_LIB) add_library (gflags_nothreads ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS}) set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS) + if (HAVE_SHLWAPI_H) + target_link_libraries (gflags_nothreads shlwapi.lib) + endif () list (APPEND LIB_TARGETS gflags_nothreads) endif () diff --git a/src/gflags.cc b/src/gflags.cc old mode 100644 new mode 100755 index b314f08..285050f --- a/src/gflags.cc +++ b/src/gflags.cc @@ -95,9 +95,8 @@ #include #if defined(HAVE_FNMATCH_H) # include -#elif defined(_MSC_VER) && defined(HAVE_SHLWAPI_H) +#elif defined(HAVE_SHLWAPI_H) # include -# pragma comment(lib, "shlwapi.lib") #endif #include // For va_list and related operations #include @@ -1310,7 +1309,7 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked( #if defined(HAVE_FNMATCH_H) || fnmatch(glob.c_str(), ProgramInvocationName(), FNM_PATHNAME) == 0 || fnmatch(glob.c_str(), ProgramInvocationShortName(), FNM_PATHNAME) == 0 -#elif defined(_MSC_VER) && defined(HAVE_SHLWAPI_H) +#elif defined(HAVE_SHLWAPI_H) || PathMatchSpec(glob.c_str(), ProgramInvocationName()) || PathMatchSpec(glob.c_str(), ProgramInvocationShortName()) #endif diff --git a/test/gflags_unittest.cc b/test/gflags_unittest.cc index 7a44f64..80f7398 100644 --- a/test/gflags_unittest.cc +++ b/test/gflags_unittest.cc @@ -408,7 +408,7 @@ TEST(FlagFileTest, FilenamesOurfileFirst) { -1.0); } -#if defined(HAVE_FNMATCH_H) || (defined(_MSC_VER) && defined(HAVE_SHLWAPI_H)) // otherwise glob isn't supported +#if defined(HAVE_FNMATCH_H) || defined(HAVE_SHLWAPI_H) // otherwise glob isn't supported TEST(FlagFileTest, FilenamesOurfileGlob) { FLAGS_test_string = "initial"; FLAGS_test_bool = false; @@ -460,7 +460,7 @@ TEST(FlagFileTest, FilenamesOurfileInBigList) { 1, -1.0); } -#endif // defined(HAVE_FNMATCH_H) || (defined(_MSC_VER) && defined(HAVE_SHLWAPI_H)) +#endif // defined(HAVE_FNMATCH_H) || defined(HAVE_SHLWAPI_H) // Tests that a failed flag-from-string read keeps flags at default values TEST(FlagFileTest, FailReadFlagsFromString) {