The folder structure:
Project/
├── main.cpp
└── deps/
└── FreeImage/
├── FreeImage.lib
├── FreeImage.dll
├── FreeImage.h
├── FreeImagePlus.lib
├── FreeImagePlus.dll
└── FreeImagePlus.h
The code:
#include <FreeImagePlus.h>
int main(void)
{
fipImage i;
return 0;
}
And now the question:
How to write a CMakeLists.txt file to be able to compile the above in windows?
My attempt as an answer below
One solution of a CMakeLists.txt with extra tips
Extra tips:
Setting the output directories and then copying the precompiled libraries to that same location is a easy way to have your code run without any added extra configurations in MSVS
And this for cycle does that for you for all the desired configurations
However, I do not like having to specify the '.lib' in
target_link_libraries(...FreeImage.lib...)Anyone else has a solution to be able to say
target_link_libraries(${NAME}_exe PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImage" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImagePlus")while avoiding the linking errorLNK1104: cannot open file '..\deps\FreeImage\FreeImage.obj'?