ccmakecompilationcmakelists-optionscunit

CMake and CUnit under windows cygwin


I cross compile software for embedded using cmake under cygwin. Now I would like to compile all CUnit test plans and using CTest on widows.

Doing so I'm calling find_package(CUnit REQUIRED) in my CMakeList.txt and it crash.

Library can't be found.

On my system cygwin I did install cmake package and cunit package (I'm able to compile using normal makefile)

I used cygwin installer and installed:

I do use cygwin because for some reason I couldn't make the cmake windows version work.

First I had to solve the cygwin path problem. so I did create a symlink so windows path now work on cygwin and cygwin path work on cmd.exe: following ARM GCC with Cygwin on Windows 8.1 : fatal error: no input file

This allowed me to cross compile using the arm-gcc toolchain :) and full path.

Second I try to make Cunit work and library is not found.
--> cunit lib can manually be found as /lib/libcunit.dll.a or in /usr/lib/libcunit.dll.a dunno why it's 2 time present.

--> cunit include folder are inside /usr/include/CUnit/CUnit.h

Third, I asked Mistral around he told me to create a FindCunit.cmake to locate the CUnit library. So I executed his orders ;) and the start of my file is:

message("including a custom cmake created for cygwin .... ")

set(CMAKE_FIND_DEBUG_MODE 1)

# Explicitly set the search path and disable default paths
find_path(CUnit_INCLUDE_DIRS
  NAMES CUnit.h
  PATHS /usr/include/CUnit
  NO_DEFAULT_PATH
)

if (CUnit_INCLUDE_DIRS)
  message("Found CUnit include directory: ${CUnit_INCLUDE_DIRS}")
else()
  message(FATAL_ERROR "Could not find CUnit include directory")
endif()

# Set the path explicitly and disable default paths
find_library(CUnit_LIBRARIES
  NAMES libcunit.dll.a
  PATHS /lib
  NO_DEFAULT_PATH
)

if (CUnit_LIBRARIES)
  message("Found CUnit library: ${CUnit_LIBRARIES}")
else()
  message(FATAL_ERROR "Could not find CUnit library")
endif()

It crash he can't find either the library neither the include file. running with set(CMAKE_FIND_DEBUG_MODE 1) show me the actual problem:

 find_path considered the following locations:

    /cygdrive/c/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/13.3 rel1/bin/../usr/include/CUnit/CUnit.h

the path he use is bad but I thought I specified the NO_DEFAULT_PATH and imposed a /lib path! But for some reason he appends before my path the pat to the arm-gcc toolchain.

I tried:

# Explicitly set the search path and disable default paths
find_path(CUnit_INCLUDE_DIRS
  NAMES CUnit.h
  PATHS ../../../../../usr/include/CUnit
  NO_DEFAULT_PATH
)

but this also gave me

/cygdrive/c/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/13.3 rel1/bin/../cygdrive/c/Users/guill/usr/include/CUnit/CUnit.h

I'm a little confuse right now.

Is there a way to configure the cygwin cmake to fetch cygwin CUnit without having to create a FindCunit.cmake? if no how can I solve my path issue?


Solution

  • Is there a way to configure the cygwin cmake to fetch cygwin CUnit without having to create a FindCunit.cmake?

    Unless CUnit comes with its own find module which CMake can find (quick web search suggests it does not) then you have to tell CMake how to find that library. You don't need to create a file as such - you could just put the contents in the calling CMakeLists.txt but some might consider it tidier to have the extra file.

    if no how can I solve my path issue?

    The CMake find_ functions have an additional flag you can pass in. It is one of the following: CMAKE_FIND_ROOT_PATH_BOTH, NO_CMAKE_FIND_ROOT_PATH ONLY_CMAKE_FIND_ROOT_PATH.

    The docs describe these in more detail, but to simplify it:

    By default, CMake will search in the re-rooted dirs first, and then in the non-rooted ones, however even if you don't specify that argument, there are various CMake variables which affect this behaviour. Search for CMAKE_FIND_ROOT_PATH_MODE_ here. I assume you're using a CMake toolchain file to set you up for cross-compilation - this might be setting one of these without you knowing.

    To add to this, you're on Windows and the args you're passing as PATHS will not work when not re-rooting the search directories as they're Linux ones. (/usr/include/ is not a valid Windows path)