1

I have the jpeglib library, built with cmake and visual studio 2005. And I also have a separate program that uses this library. How can I compile that program so that I can debug both program and library code?

My first attempt was by just including the main program's project into the libjpeg solution, changing include paths and specifying the path to libjpeg .lib. This worked, but when I rerun cmake, I have to redo that. I described it here: https://board.flatassembler.net/topic.php?p=203834#203834

How can I compile those two programs using cmake itself? I tried adding this in the libjpeg CMakeList.txt :

add_executable(_main--ddraw main.cpp)
set_property(TARGET _main--ddraw PROPERTY RUNTIME_OUTPUT_DIRECTORY "c:/_src/_main--ddraw3")
target_link_libraries(_main--ddraw jpeg-static)

But it only resulted in this:

1>CMake Error at CMakeLists.txt:369 (add_executable):
1>  Cannot find source file:
1>    main.cpp
1>  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
1>  .hxx .in .txx
1>CMake Error: CMake can not determine linker language for target: _main--ddraw
Alefun999 Sss
  • 123
  • 1
  • 7
  • As CMake says, he can't find `main.cpp` file. You've to set right path to this file first. – Algorys May 02 '18 at 08:09
  • @Algorys intuitions says that I should set RUNTIME_OUTPUT_DIRECTORY before add_executable. Also I indeed set a wrong path at first, maybe it's cached somewhere. – Alefun999 Sss May 02 '18 at 08:23
  • If you set RUNTIME_OUTPUT_DIRECTORY for a specific target, target should be defined before. Otherwise, for CMake cache, remove "build" directory and re-run cmake again will normally solve this problem. See https://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output?answertab=active#tab-top – Algorys May 02 '18 at 08:45
  • @Algorys, purged "build" directory, still can't find the source. I know for sure there is file `c:/_src/_main--ddraw3/main.cpp` – Alefun999 Sss May 02 '18 at 10:59
  • CMake searches the source file in the *current source directory* and in the *current build directory*. Property `RUNTIME_OUTPUT_DIRECTORY` is unrelated - it affects on directory with *output file* (executable), not on the input one. – Tsyvarev May 02 '18 at 11:17
  • I guess I should have 2 CMakeLists.txt , like described here https://stackoverflow.com/a/8304235/9449737 ? – Alefun999 Sss May 02 '18 at 11:49

0 Answers0