The 2nd version of your CMakeLists.txt file works fine with FLTK 1.4.1: I tested it successfully with CMake 3.29 after reducing cmake_minimum_required(VERSION 3.29)
to 3.29.
How exactly did you install FLTK in C:/fltk
? The correct way to do it with VS (I'm using VS 2019) is to right-click on the "INSTALL" target in the project explorer and select "build". Yes, this looks weird, but this is what CMake + VS need. After that I found all the libs in C:/fltk/lib
as you wrote.
There should also be 5 files (*.cmake) in C:/fltk/CMake/
. Do these files also exist? If not you didn't install FLTK correctly. Go back and do it as I described. If you did, continue...
Now the next step is to build your project with CMake. I assume that you have your main.cpp
file and CMakeLists.txt
in the same folder. Open CMake and select the source folder (where these files live) and the binary folder (e.g. the folder build
inside the source folder). Then click on "Configure". If you did this you should have seen an error message. Note for the future: please post error messages if you ask questions (use copy/paste). What I see is an error message and some instructions:
Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19045.
CMake Error at CMakeLists.txt:7 (find_package):
Could not find a package configuration file provided by "FLTK"
(requested version 1.4) with any of the following names:
FLTKConfig.cmake
fltk-config.cmake
Add the installation prefix of "FLTK" to CMAKE_PREFIX_PATH or set
"FLTK_DIR" to a directory containing one of the above files. If "FLTK"
provides a separate development package or SDK, be sure it has been
installed.
Configuring incomplete, errors occurred!
The first file FLTKConfig.cmake
is one of the 5 files in C:/fltk/CMake/
. As the instructions say: you have two choices. You need to define one of two CMake variables by clicking on the '+' button ("Add Entry"):
FLTK_DIR
with value C:/fltk/CMake/
orCMAKE_PREFIX_PATH
with value C:/fltk
.I did the latter and VS found FLTK and built the project successfully. Finally I modified your main.cpp
so it shows the window and waits until the window is closed:
#include <FL/Fl.H> // note: typo fixed
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
int main() {
Fl_Window win(100, 100, "ciao");
win.show();
return Fl::run();
}
That's it. Let us know if this works, or post what you did and related error messages.
PS: there are other ways to specify the required variables but that would be OT here.