title: How to use cmake to let command "pkg_check_modules" be passed in Windows with git-bash
body: <p>I want to build <a href="https://github.com/kdudka/nss-pem" rel="nofollow noreferrer">nss-pem</a> on Windows by cmake with git-bash(or msys or cygwin). cmake found <code>pkg-config</code> in my cygwin's bin directory. I also added the directory path into PKG_CONFIG_PATH, and added <code>.pc</code> file and built-nss-lib into the directory I added. But I still got error when cmake exe the line <code>pkg_check_modules(NSS REQUIRED "nss")</code></p>
  
  <p><strong>$PKG_CONFIG_PATH</strong>:</p>
  
  <pre><code>User@host MINGW64 ~/Desktop/nss-pem/build
  $ echo $PKG_CONFIG_PATH
  /mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
  </code></pre>
  
  <p><strong>CMake Error:</strong></p>
  
  <pre><code>User@host MINGW64 ~/Desktop/nss-pem/build
  $ cmake ../src
  -- Checking for module 'nss'
  --   No package 'nss' found
  CMake Error at C:/Program Files/CMake/share/cmake-3.9/Modules/FindPkgConfig.cmake:412 (message):
    A required package was not found
  Call Stack (most recent call first):
    C:/Program Files/CMake/share/cmake-3.9/Modules/FindPkgConfig.cmake:588 (_pkg_check_modules_internal)
    CMakeLists.txt:7 (pkg_check_modules)
  </code></pre>
  
  <p><strong>nss.pc:</strong></p>
  
  <pre><code># nss pkg-config
  prefix=D:/Projects/library/nss
  exec_prefix=${prefix}
  includedir=${prefix}
  libdir=${exec_prefix}/WIN954.0_x86_64_64_OPT.OBJ/lib/
  
  Name: nss
  Description: The nss library
  Version: 3.32
  Cflags: -I${includedir}/WIN954.0_x86_64_64_OPT.OBJ/include -I${includedir}/public/nss
  Libs: -L${libdir} -lnss3 -lnspr4
  </code></pre>
  
  <p>What is the correct way to build this project? And what is the best way to setup the unix-like environment to build projects on Windows? </p>
  
  <h2>　</h2>
  
  <h1>Update</h1>
  
  <p>I try to use <code>git-bash</code> and add <code>cygwin/bin</code> into my env variables. The command I used to call cmake is <code>cmake -G "MSYS Makefiles" ../src</code>. It seems that it occur some errors of path.</p>
  
  <pre><code>$ cmake -G "MSYS Makefiles" ../src
  -- The C compiler identification is GNU 5.4.0
  -- Check for working C compiler: C:/cygwin/bin/gcc.exe
  -- Check for working C compiler: C:/cygwin/bin/gcc.exe -- broken
  CMake Error at C:/Program Files/CMake/share/cmake-3.9/Modules/CMakeTestCCompiler                                                                                                             .cmake:51 (message):
    The C compiler "C:/cygwin/bin/gcc.exe" is not able to compile a simple test
    program.
  
    It fails with the following output:
  
     Change Dir: C:/Users/User/Desktop/nss-pem/build/CMakeFiles/CMakeTmp
  
  
  
    Run Build Command:"C:/cygwin/bin/make.exe" "cmTC_bdb42/fast"
  
    /usr/bin/make -f CMakeFiles/cmTC_bdb42.dir/build.make
    CMakeFiles/cmTC_bdb42.dir/build
  
    make[1]: Entering directory
    '/cygdrive/c/Users/User/Desktop/nss-pem/build/CMakeFiles/CMakeTmp'
  
    /bin/sh: /C/Program Files/CMake/bin/cmake.exe: No such file or directory
  
    make[1]: *** [CMakeFiles/cmTC_bdb42.dir/build.make:65:
    CMakeFiles/cmTC_bdb42.dir/testCCompiler.c.obj] Error 127
  
    make[1]: Leaving directory
    '/cygdrive/c/Users/User/Desktop/nss-pem/build/CMakeFiles/CMakeTmp'
  
    make: *** [Makefile:126: cmTC_bdb42/fast] Error 2
  
  
  
  
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:1 (project)
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/User/Desktop/nss-pem/build/CMakeFiles/CMakeOutput.log".
  See also "C:/Users/User/Desktop/nss-pem/build/CMakeFiles/CMakeError.log".
  </code></pre>
  
  <p><code>/bin/sh: /C/Program Files/CMake/bin/cmake.exe: No such file or directory</code>: bash could not find <code>cmake.exe</code>, even if I modified the <code>CMakeCache.txt</code>. And the C compiler checking always fail. (I can manually compile the test file.)</p>
  
  <p>So I gave up to work with git-bash, and turn to use Windows' <code>cmd.exe</code> with <code>MinGW</code>. Below is the steps what I done.</p>
  
  <ol>
  <li>Clean up <code>PATH</code> env variables (remove cygwin's dirs).</li>
  <li>Copy <code>pkg-config.exe</code> and the required dynamic libraries into <code>MinGW/bin</code>.</li>
  <li>Create <code>MinGW/lib/pkgconfig/nss.pc</code>.</li>
  </ol>
  
  <p>Below is the message returned:</p>
  
  <pre><code>C:\Users\IvenCJ7\Desktop\nss-pem\build&gt;cmake -G "MinGW Makefiles" ../src
  -- The C compiler identification is GNU 6.3.0
  -- Check for working C compiler: C:/MinGW/bin/gcc.exe
  -- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Found PkgConfig: C:/MinGW/bin/pkg-config.exe (found version "0.29.1")
  -- Checking for module 'nss'
  --   Found nss, version 3.32
  -- Looking for lowkeyti.h
  -- Looking for lowkeyti.h - found
  -- Looking for NSSCKFWSlot_GetSlotID
  -- Looking for NSSCKFWSlot_GetSlotID - not found
  -- Configuring done
  -- Generating done
  -- Build files have been written to: C:/Users/User/Desktop/nss-pem/build
  </code></pre>
  
  <p><code>cmake</code> still cannot find the function, <code>NSSCKFWSlot_GetSlotID</code> in NSS. I made sure the function is in the NSS's include headers.</p>
  
  <p>Below is the information that pkg-config return to me.</p>
  
  <pre><code>$ pkg-config --cflags --libs nss
  -ID:/Projects/library/nss/WIN954.0_x86_64_64_OPT.OBJ/include 
  -ID:/Projects/library/nss/public/nss 
  -LD:/Projects/library/nss/WIN954.0_x86_64_64_OPT.OBJ/lib/ -lnss3 -lnspr4
  </code></pre>