Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake doesn't override glfw_FOUND when set manually + README update #84

Merged
merged 19 commits into from
Feb 15, 2023

Conversation

Lacusch
Copy link
Contributor

@Lacusch Lacusch commented Feb 13, 2023

Possible fix for #83 .
Added 2 lines in CMake list + 1 line in README to let people known about the new option.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

It's my first public pull request so I hope I didn't screw up anywhere.

@Lacusch Lacusch marked this pull request as ready for review February 13, 2023 11:08
@W2Wizard W2Wizard added the Improvement Adds an implementation or improves on something label Feb 13, 2023
@W2Wizard
Copy link
Collaborator

Thanks for your PR! Please refer to #83 on what I suggested :D

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

Thanks for the suggestion, I'm still not too familiar with Cmake, but I'll try to create the change that way.
Should I create a new pull request for that change or can I update this pull request somehow?

@W2Wizard
Copy link
Collaborator

W2Wizard commented Feb 13, 2023

Thanks for the suggestion, I'm still not to familiar with Cmake, but I'll try to create the change that way.

That's alright, if you have any questions just go crazy!

Should I create a new pull request for that change or can I update this pull request somehow?

That won't be necessary. You can just put all your changes into this one PR 👌

GLFW_FETCH is off by default and controlls whenevere we alwasys install
the glfw or not
@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

Okay I've set up a Variable GLFW_FETCH like you suggested. (I turned it off by default). It this looks good we need to update docs and it should be good to go.

@W2Wizard
Copy link
Collaborator

W2Wizard commented Feb 13, 2023

With 0fe9f2e I added Findglfw3.cmake which is basically a script that tries to find it glfw on the system first before it clones.

If you could combine this PR with the setting you proposed that would be great! That way you could first try and search for the library instead of instantly git cloning it the moment it fails.

For example for us at Codam, glfw3 is already installed on the Macs yet for some reason it fails to find it even tho it links correctly. With this module it manages to suppress the warning.

If not I can also deal with it if you'd like.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

Okay If you want to handle it from now on that's fine by me.

But it you can explain how you want me to set it up I'm happy to do it.

@W2Wizard
Copy link
Collaborator

W2Wizard commented Feb 13, 2023

The Find module basically does all the searching for us. The main idea is to fetch as the last possible solution. Because if GLFW is already installed we can use it.

So basically:

  1. Use find_package to locate GLFW.
  2. If it fails the module kicks in and tries to find it in the commonly located paths.
  3. Finally if that failed as well, you run the LinkGLFW macro which git clones and links glfw like before. You can check if the glfw_FOUND variable is true / yes in order to do so.

In order to make the module work that I added all you need to do is add:

# Add this at the top or somewhere appropriate
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

I was thinking of then using the GLFW_FETCH as an option wether to fetch it at the last step or not. For your sakes then you don't need it to always fetch every-time, just use whats already installed.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

I added the line you wrote + removed a comment that I accidentally left in.

@W2Wizard
Copy link
Collaborator

W2Wizard commented Feb 13, 2023

That's alright, add as many commits as you need. I'll squash merge it in the end ✨

As you can see in the CI, the module works:
image
Now it just unnecessarily fetches glfw.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

Okay I see. On my system It can't find it as it's installed with brew, so I didn't see the problem.
Should I change to condition at the end of CMake list to fix the problem?

Add the paths used by 42Homebrew to detect the GLFW dependency
Now we first fetch, then try to find and finally clone if we really are unable to find the glfw dependency
@W2Wizard
Copy link
Collaborator

W2Wizard commented Feb 13, 2023

I made the necessary changes, could you try and see if this works for you ? I made some tests myself but I just want to double check.

Should now also recognize homebrew as a possible installation both normal and the 42 version used from: https://github.com/kube/42homebrew

CI Output
Screen Shot 2023-02-13 at 5 57 27 PM

42 Homebrew
image

Proper system install
Screen Shot 2023-02-13 at 5 58 59 PM

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

It seems to work really well, except that the option -DGLFW_FETCH=ON doesn't seem to work for me.

The difference between running

cmake -DGLFW_FETCH=ON ../ -B ..//build && make -C ..//build cc unit.o tests.o ../build/libmlx42.a -ldl -lglfw -pthread -lm -o test
and
cmake ../ -B ..//build && make -C ..//build cc unit.o tests.o ../build/libmlx42.a -ldl -lglfw -pthread -lm -o test
In the test folder is only :

1c1
< cmake -DGLFW_FETCH=ON ../ -B ..//build && make -C ..//build
---
> cmake ../ -B ..//build && make -C ..//build

So it's not building GLFW even with the option specified.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

If I understand it correctly this option is supposed to make sure that it builds glfw regardless of it's installation.

@W2Wizard
Copy link
Collaborator

Ah I see Ill fix it.

Exactly 👍

@W2Wizard
Copy link
Collaborator

W2Wizard commented Feb 13, 2023

I fixed a little mistake that it set the incorrect variable in the Find module. It should work now I hope.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 13, 2023

I won't go to school tomorrow but I'll check it on Wednesday morning it that works for you.

And if you want I would be happy to update the docs as well it you tell me where to put the new option.

@W2Wizard
Copy link
Collaborator

Regarding the docs about this, I think stating under General compilation. in the README and how to pass them onto cmake is probably good enough. Just to make sure you can also add it to the docs/index.md file, further specifying what they mean and stuff.

So like:

Installation 🏗️

Available Options

You can pass build options to cmake ... cmake -DDEBUG=1 -DGLFW_FETCH=0 ...

The following options for MLX42 are:

  • DEBUG: Enables assertion macros and compiles with -g in order for debugging with lldb.
  • GLFW_FETCH: Fetches GLFW if it can't be found on the system at all, allows you to then install it with sudo make install under the build/_deps folder.

@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 14, 2023

Thanks I'll update the docs today

docs/installation.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@W2Wizard W2Wizard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to be merged 👌

Thank you so much for this PR! It actually fixes all the linkage problems that I've seen and found so far! I really appreciate your contribution :D

@W2Wizard W2Wizard merged commit 83769ce into codam-coding-college:master Feb 15, 2023
@Lacusch
Copy link
Contributor Author

Lacusch commented Feb 15, 2023

You're welcome happy to contribute

@Lacusch Lacusch mentioned this pull request Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Adds an implementation or improves on something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants