[CMake] Forcing CMake to never search install path

Michael Jackson mike.jackson at bluequartz.net
Mon May 16 09:33:06 EDT 2011

On May 15, 2011, at 9:12 PM, John Drescher wrote:

>> I've been struggling to find a way to prevent CMake from using
>> CMAKE_INSTALL_PREFIX in any of its FIND_* routines.  Generally
>> speaking, stripping it out of CMAKE_SYSTEM_PREFIX_PATH seems to work,
>> but we're still getting situations on Windows where it is finding old
>> libraries from previous program installs.  I've tried ensuring all of
>> the CMAKE_SYSTEM_*_PATH variables are stripped, but that doesn't seem
>> to make a difference.
>> Is there a mechanism I can use to specify to CMake to NEVER search in
>> a given path, excluding it from all FIND_* routine searches?  It is
>> very typical in our development process to have older builds installed
>> and be building newer versions at the same time, so we really need a
>> good solid way to make sure previously built libraries aren't picked
>> up by FIND routines.
> Not that I have a solution however I too am looking to solve this
> problem. For me its not so much about INSTALL paths since I almost
> never run the INSTALL targets (at least not on projects that do not
> have different names for release and debug) on windows but it's more
> that a 32 bit build for Visual Studio 2005 will find the 64 bit Qt I
> built for Visual Studio 2010. I am thinking of looking into batch
> files and environment variables however I am not sure how many
> packages will use environment variables like ( ITK_DIR, VTK_DIR ...)
> John

I had the same issue with windows while trying to keep separated 32 and 64 bit versions of everything. Basically what I did was make a copy of the Shortcuts to the "Visual Studio 2008 Command Prompt" onto the desktop. Next point the shortcut to a new .bat file that contains the contents of the original file it pointed but adds additional paths for all the installed libraries and executables for the "bitness" that the shortcut represents. So for example, I have all my dev stuff installed in C:\Developer\x64 or C:\Developer\i386. Once the command prompt is up and running I can then launch CMake-GUI.exe from there and the proper paths get picked up. There may be better ways to do all of this but this seems to work for me. Here is my "64 bit" .bat file that gets run when the Command Prompt Shortcut gets run:

@SET VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 9.0
@SET VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC
@SET FrameworkDir=C:\Windows\Microsoft.NET\Framework64
@SET FrameworkVersion=v2.0.50727
@SET Framework35Version=v3.5
@if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR
@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@echo Setting environment for using Microsoft Visual Studio 2008 x64 tools.

@call :GetWindowsSdkDir

@if not "%WindowsSdkDir%" == "" (
	set "PATH=%WindowsSdkDir%bin\x64;%WindowsSdkDir%bin\win64\x64;%WindowsSdkDir%bin;%PATH%"
	set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
	set "LIB=%WindowsSdkDir%lib\x64;%LIB%"

@set PATH=%VCINSTALLDIR%\BIN\amd64;%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%Framework35Version%\Microsoft .NET Framework 3.5 (Pre-Release Version);%FrameworkDir%\%FrameworkVersion%;%VCINSTALLDIR%\VCPackages;%VSINSTALLDIR%\Common7\IDE;%VSINSTALLDIR%\Common7\Tools;%VSINSTALLDIR%\Common7\Tools\bin;%PATH%

@set LIBPATH=%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%FrameworkVersion%;%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%FrameworkVersion%;%VCINSTALLDIR%\ATLMFC\LIB\amd64;%VCINSTALLDIR%\LIB\amd64;%LIBPATH%

@set ARCH_TYPE=x64
@set BOOST_ROOT=C:\Developer\%ARCH_TYPE%\MXABoost-1.44
@set EXPAT_INSTALL=C:\Developer\%ARCH_TYPE%\expat
@set HDF5_INSTALL=C:\Developer\%ARCH_TYPE%\hdf5-169
@set ITK_DIR=C:\Users\mjackson\Workspace\InsightToolkit-3.14.0\%ARCH_TYPE%
@set QTDIR=C:\Developer\%ARCH_TYPE%\Qt-4.7.1
@set TIFF_INSTALL=C:\Developer\%ARCH_TYPE%\tiff
@set BJAM_INSTALL=C:\Applications\bjam
@set SVN_INSTALL=C:\Applications\Subversion
@set CMAKE_INSTALL=C:\Applications\CMake-2.8.3
@set SEVENZIP_INSTALL=C:\Applications\7-Zip
@set JOM_INSTALL=C:\Applications\jom
@set QWT_INSTALL=C:\Developer\%ARCH_TYPE%\qwt-5.2.2
@set EMMPM_INSTALL=C:\Developer\%ARCH_TYPE%\emmpm
@set TBB_INSTALL=C:\Developer\%ARCH_TYPE%\tbb30_174oss


@rem Load up the Intel Threading Building Blocks variables which will set the TBB30_INSTALL_DIR whic
@rem the FindTBB.cmake module will use to find the libraries
call %TBB_INSTALL%\bin\intel64\vc9\tbbvars.bat


@goto end

@call :GetWindowsSdkDirHelper HKLM > nul 2>&1
@if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1
@if errorlevel 1 echo WindowsSdkDir not found
@exit /B 0

@SET WindowsSdkDir=
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
	if "%%i"=="CurrentInstallFolder" (
		SET "WindowsSdkDir=%%k"
@if "%WindowsSdkDir%"=="" exit /B 1
@exit /B 0

@echo ERROR: VSINSTALLDIR variable is not set. 
@goto end

@echo ERROR: VCINSTALLDIR variable is not set. 
@goto end


Hope that helps or gives inspiration.
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net 
BlueQuartz Software               Dayton, Ohio

More information about the CMake mailing list