Page MenuHome

[MSVC/libpng/cmake] cmake keeps finding incompatible versions of libpng and prefers those over the one in our lib folder.
ClosedPublic

Authored by Ray Molenkamp (LazyDodo) on Jul 2 2016, 12:28 AM.

Details

Summary

This is causing all kinds of problems from crashes in datatoc_icon to linker errors.

Just bumped into yet another user struggling with this on irc, time for a fix....

we can safely take out the findlib since it's in a windows specific part of the cmakefile.txt so it won't have any negative effects on other platforms.

Diff Detail

Repository
rB Blender

Event Timeline

Ray Molenkamp (LazyDodo) retitled this revision from to [MSVC/libpng/cmake] cmake keeps finding incompatible versions of libpng and prefers those over the one in our lib folder..
Ray Molenkamp (LazyDodo) updated this object.
Ray Molenkamp (LazyDodo) set the repository for this revision to rB Blender.

Think its nice to support path searching for windows, however the issues this causes aren't obvious and take a long time to solve.

How about we disable for now, but put behind a variable "WIN32_USE_FIND_LIB" for eg, then we can easily enable if we want.

Ray Molenkamp (LazyDodo) edited edge metadata.

Added WITH_WINDOWS_FIND_MODULES option which is default disabled, when disabled all libs use hardcoded path's.

Verified the paths are correct on both vc2013 and 2015.

Win 7, MSVC 2015
Worked for me-

Anaconda's libs had a sneaky way of getting into the Cmake profile. Applying this patch took care of it.

Thanks!

Updated for cmake split.

Thanks, works great :) git apply did give a warning about trailing whitespace on line 236 (line 71 of the diff)

There are several things i don't like about particular implementation:

  • It considers hardcoded locations as a WARNING, which is misleading.
  • It has fair amount of duplicated code.

Ideas:

  • Have a macro which we can invoke like:
macro(windows_find_package)
  if(WITH_WINDOWS_FIND_MODULES)
    find_package("${PACKAGE}")
  endif()
  if(NOT ${PACKAGE}_FOUND)
    use_hardcoded_locations_passed_to_the_macro()
  endif()
endmacro()

windows_find_package(OpenSubdiv
                                        INCLUDE_DIR "opensubdiv/include"
                                        LIBPATH "opensubdiv/lib"
                                        LIBRARIES "osdCPU.lib;osdGPU.lib")
  • Simply set/append FOO_ROOT_DIR at the top so later on we can use find_package().
build_files/cmake/platform/platform_win32_msvc.cmake
26

Prefer to keep options in a main file, so it's always easy to find them.

155

You can't really use WARNING in the case of disabled WITH_WINDOWS_FIND_MODULES=OFF: that would cause misleading warning prints in the console. There is nothing wrong in hardcoded locations and in fact, it's the only way to have official build done so it can't be a warning.

There are several things i don't like about particular implementation:

  • It considers hardcoded locations as a WARNING, which is misleading.

It only considers them a warning if you enable the use of find_package and it doesn't locate it, in that case it falls back to hardcoded paths and warns the user (given it is likely this is not what they expected)

  • It has fair amount of duplicated code.

I resolved some of the duplicated code by macro's

Ideas:

  • Have a macro which we can invoke like:
macro(windows_find_package)
  if(WITH_WINDOWS_FIND_MODULES)
    find_package("${PACKAGE}")
  endif()
  if(NOT ${PACKAGE}_FOUND)
    use_hardcoded_locations_passed_to_the_macro()
  endif()
endmacro()

windows_find_package(OpenSubdiv
                                        INCLUDE_DIR "opensubdiv/include"
                                        LIBPATH "opensubdiv/lib"
                                        LIBRARIES "osdCPU.lib;osdGPU.lib")
  • Simply set/append FOO_ROOT_DIR at the top so later on we can use find_package().

I'm not sure this can be generalized easily there's a lot of variation in naming of things by some of the find_xxxx scripts, INCLUDE_DIR vs INCLUDE_DIR , LIBRARY vs LIBRARIES , debug vs release libs, etc etc. While it sounds like a nice idea, it does sound like it'll require a lot more time than I have to spend right now. For now i'm just looking to get the people with anaconda installed (which seems to be the root cause of most lib errors now days) building successfully again.

build_files/cmake/platform/platform_win32_msvc.cmake
155

This will only emit the warning if WITH_WINDOWS_FIND_MODULES=ON ? I'm not sure what you're asking me to change here

Ray Molenkamp (LazyDodo) edited edge metadata.

Updated with feedback

Ah, you're right about warning only if the WITH_WINDOWS_FIND_MODULES is enabled.

But think we can still reduce amount of lines here:

macro(win_find_package NAME)
  if(WITH_WINDOWS_FIND_MODULES)
    find_package(NAME)
    if(NOT ${NAME_FOUND})
      message(WARNING "Package ${NAME} not found, will be using hardcoded locations")
    endif()
  endif()
endmacro()

Then we can only invoke the macro and skip adding if(WITH_WINDOWS_FIND_MODULES) all over the place.

How about that?

Sergey Sharybin (sergey) edited edge metadata.

Think it's fine now. Guess you've checked it actually works :)

One possible tweak could be: since macro is only ment to be used from platform_win* we can keep it in platform_win.cmake?

This revision is now accepted and ready to land.Aug 23 2016, 4:09 PM

Then we can only invoke the macro and skip adding if(WITH_WINDOWS_FIND_MODULES) all over the place.

That's already gone, only place that still has it is the boost section cause it has a bunch of parameters i didn't know how to wrap.

How about that?

I kinda like them separated as is (find & warn). I hate for windows_find_package to all confidently go 'hardcoded paths will be used!' when there might not be actually code to back up that claim.

Ray Molenkamp (LazyDodo) edited edge metadata.

Moved macro's to the platform file. And yeah i've tested it, some of the anaconda users have been using a previous incarnation of this patch for a while as well