Question

I'm trying to adjust 3rd person code to my needs. This code is provided with CMake config files used to build and install it. There is possibility to choose one of libraries. And in code is often used #ifdef USE_FTD2XX directive. I saw that this is defined in CMamkeFiles.txt file like here:

option(USE_FTD2XX "Use FTDI libFTD2XX instead of free libftdi" ON)

if(USE_FTD2XX)
  find_package(libFTD2XX)
endif(USE_FTD2XX)

if(LIBFTD2XX_FOUND)
  include_directories(${LIBFTD2XX_INCLUDE_DIR})
  add_definitions( -DUSE_FTD2XX )
else(LIBFTD2XX_FOUND)
  set(LIBFTD2XX_LIBRARIES "")
endif(LIBFTD2XX_FOUND)

But if I simply use *.c and *.cpp files and I analyse and run it simply from IDE (Codeblocks), how could I set using this library in C++ code instead of in CMake? I'm also sure that I want use always this one so it can be fixed.

Should I simply #define USE_FTD2XX in main file?

Was it helpful?

Solution

You cannot simply #define USE_FTD2XX because you also need specific linker options for this to work (i.e. the library to link with). If the option is OFF in cmake, the specific link options won't be present in the Makefile and most likely you'll have linker errors.

So CMake takes care of everything automatically for you, but you need to re-generate your makefiles each time you want to toggle options on/off.

If only headers were involved and no library to link with (like some parts of the Boost framework), then yeah, defining USE_FTD2XX in your should be enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top