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 #378

Closed
wants to merge 8 commits into from
Closed

CMake #378

wants to merge 8 commits into from

Conversation

jwinarske
Copy link

@jwinarske jwinarske commented Sep 3, 2018

I've done some preliminary work on CMake support.

It builds on Mac, Linux, and partially (6 undefined errors) for Windows.

If this is of any interest, I'm open to feature requests. I was thinking Test cases next.

#cmakedefine HAVE_UNISTD_H

/* Define to 1 if you have the `Used' function. */
#cmakedefine HAVE_USED
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, where did you copy to form this config.h.in from? It appears to have unnecessary macros defined such as "Used" and "We", which I think are a result of a bug that I have fixed in c42de06. Can you make this config.h.in more up to date then?

Copy link
Author

Choose a reason for hiding this comment

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

It's copied from the flex config.h.in. There are quite a bit of entries that are not used. I was being thorough for the sake of preservation. I can make this more current.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would help if you take my config_for_build.h in #373 for reference. That was my attempt to analyze what config.h macros are actually used in Flex, versus what are redundant.

CMakeLists.txt Outdated
@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake")

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Relase)
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo.

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Thank you

Description: Flex (the fast lexical analyzer) support library
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lfl

Copy link
Contributor

Choose a reason for hiding this comment

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

Excuse me, but why do we need another libfl.pc.in in the flex package? Was it impossible to adopt the src/libfl.pc.in directly?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. Removing it

cmake/flexdef.h Outdated
char *tmp = strstr(path, fname);
tmp[strlen(fname)] = 0;
return tmp;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The basename() dependency has been removed since my commit fb731ac. Even if it were used, having the function embedded in a header would be bad.

Copy link
Author

Choose a reason for hiding this comment

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

Cool. Again this is a temp file that is going away.

cmake/flexdef.h Outdated
#endif
#ifdef UINT16_MAX
#undef UINT16_MAX
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of undef'ing these (INT8_MIN, INT8_MAX, etc)? If that was to avoid the build errors as described in #307, then I have resolved it in master (through #309 and e1f6b4a).

You might need to also remove the #include <stdint.h> line below.

Copy link
Author

Choose a reason for hiding this comment

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

This header only applies to ongoing Windows build work, which doesn't work yet. I will remove this until all items are sorted, after which create separate PR.

cmake/flexdef.h Outdated

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Principally config.h should be included before other standard headers, as config.h would contain feature macros that would alter which function interface that standard headers would expose. Is there any reason you include the other way around?

Copy link
Author

Choose a reason for hiding this comment

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

Yes see above comment. I appreciate the time you are putting into reviewing this :)

@egorpugin
Copy link
Contributor

@jwinarske FYI -
I've also implemented cmake for flex, you could check it here:
https://github.com/egorpugin/flex
#77

Maybe something would be useful.

@Croydon
Copy link

Croydon commented Nov 4, 2019

What is the status of this?

@westes
Copy link
Owner

westes commented Nov 4, 2019 via email

@madebr
Copy link

madebr commented Apr 1, 2020

How does this cmake script intend to break the dependency circle?
The cmake script depends on flex itself.
It should build a stage1flex for the build system that can be used to build flex for the host system.

@jwinarske
Copy link
Author

jwinarske commented Apr 1, 2020 via email

@madebr
Copy link

madebr commented Apr 1, 2020

That would be great!
Don't forget the case where CMAKE_CROSSCOMPILING is ON.

@tay10r
Copy link

tay10r commented Jan 27, 2021

Is this still planning on getting merged? CMake generally makes it much easier to build on Windows when it comes to projects that use autotools

@nightlark
Copy link

nightlark commented Nov 1, 2021

Hey @jwinarske and @westes -- what would be needed to help move this along? I noticed there are a few things that seem in various states of being stalled:

  • Automating releases in Automate release #480 (seems like the main thing blocking a new release of flex)
  • Switching CI tests from Travis to GitHub Actions (would you want a PR that does this separate from the automated release PR? It looks like that one is focus on automating releases, though it has lingered long enough waiting for feedback that it looks like there are some things that are getting slightly outdated)
  • CMake support (from feedback it seems like the main change left for this PR is support for bootstrapping?)

I'm open to taking those PRs across the finish line or helping make requested changes depending on whether or not the original authors are still around and want to keep making changes.

If the main issue is the flex maintainer(s) lacking time at the moment, I'm not really sure what could be done -- maybe @westes could chime in here on what would help the most. I have seen a few other projects recently move under an org when the original maintainer was no longer able to keep working on them; I'm guessing that's not the desired approach, but if it is an issue could be opened to discuss further (it seems like there are at least 2 people who have made a number of contributions and have left reviews on PRs).

@westes
Copy link
Owner

westes commented Nov 1, 2021

There are two sets of issues: things to do with cmake itself and things blocking flex.

From what I understand, cmake lacks a number of features that the flex build system expects and has. (If I'm wrong on this, please point me in the right direction.) Autotools works and is standard; cmake may or may not work or whatever, but I've not seen a compelling reason to switch -- beyond that some people are excited about cmake. Maintaining two build systems is a mainightmare over time -- I spent a good deal of time removing all the special purpose stuff thrown in because some systems couldn't be bothered to run the autotools stuff.

Yes, a pr that -just- uses github actions, removing travis, would help. While that's maintaining the dependency on github, travis is showing its age and they're clearly moving away from the free support of open source projects.

Automating the flex release process is something I need to get back to; that makes releases changes easier. Although, I have to watch that I don't become dependent on github any more than we are.

I have considered migrating the flex codebase to an organization setup; the real dependency there is again, I don't want to entangle myself or flex into github than we already are.

@tay10r
Copy link

tay10r commented Nov 1, 2021

Hope you don't mind me chiming in.

cmake lacks a number of features that the flex build system expects and has. (If I'm wrong on this, please point me in the right direction.)

What features?

but I've not seen a compelling reason to switch

Since you are the maintainer, this makes sense. I have to assume you're usually running a Linux distribution and developing software from the command line (at least, I do the same). However, some people develop software on Windows. Or, some people deploy software on Windows. When this is the case, having an easy/platform-agnostic way to get Flex is extremely appreciated. With CMake (if Flex used CMake), this could be done on any platform:

include(FetchContent)
FetchContent_Declare(flex URL "https://github.com/westes/flex/archive/master.zip")
FetchContent_MakeAvailable(flex)
# Now Flex is available to use in other people's build system.

@westes
Copy link
Owner

westes commented Nov 2, 2021

fetching the tip of the default branch is going to result in a failed build for most people. That is, therefore, not something I want to make easier.

Flex needs to be bootstrapped, one way or another -- either you already have a flex that can build the tip of the default branch or you fetch one of the releases because the released archives include the intermediate files that appear during the bootstrapping process.

The most recent lacking feature that I recall was support for getext. My recollection, though, in general, was that while cmake has some interesting features, if you want anything beyond what it offers, you're out of luck. And flex does want some unusual build-time features. With autotools, I've got the shel and standard make to fal back on if I need to make something unusal hapen.

But to be clear, the burden of proof is on cmake. We have a working build system. It will run on Windows -- and has for years. Yes it's kind of intricate and hard to wrangle at times. So is bootstrapping flex.

@tay10r
Copy link

tay10r commented Nov 2, 2021

fetching the tip of the default branch is going to result in a failed build for most people. That is, therefore, not something I want to make easier.

Or latest release. Just a matter of changing the URL.

The most recent lacking feature that I recall was support for getext. My recollection, though, in general, was that while cmake has some interesting features, if you want anything beyond what it offers, you're out of luck. And flex does want some unusual build-time features. With autotools, I've got the shel and standard make to fal back on if I need to make something unusal hapen.

I haven't used gettext in a while, so I don't know what the requirements are. Maybe worth someone who has experience in autotools and CMake commenting on whether this is a suitable level of support. In any case, you can fallback to the shell and standard make in CMake as well (via add_custom_command or execute_process).

@westes
Copy link
Owner

westes commented Nov 2, 2021

I guess I'm not being clear:
Flex already has a build system. It works on Windows (even though Windows is an utter pile of crap). It works on all manner of Linux/*BSD/Unixlike systems.

What benefit -to flex- does cmake offer?

@tay10r
Copy link

tay10r commented Nov 2, 2021

I guess I'm not being clear:
Flex already has a build system. It works on Windows (even though Windows is an utter pile of crap). It works on all manner of Linux/*BSD/Unixlike systems.
What benefit -to flex- does cmake offer?

Sorry! Not trying to ruffle any feathers here. The benefit is that is makes it easier for people developing for Windows. It benefits users, in that regard. From a maintenance perspective, it may make things more difficult if you're not a regular CMake user. So the way I see it, there's a maintainability / usability trade-off involved with the decision.

While I would be happy to see Flex adopt CMake, I think it may be worth supporting CMake in a separate repository. That way, the owner of the repository is responsible for maintaining the build system.

@Explorer09
Copy link
Contributor

@tay10r Flex is not going to drop Autotools support since Flex has been part of many GNU/Linux toolchains. The main problem preventing Flex from supporting CMake is: (a) we didn't see much benefit for CMake comparing to maintenance costs, and (b) we don't have people who are experts at CMake so as to keep the Autotools scripts and CMake syntaxes consistent.

@tay10r
Copy link

tay10r commented Nov 2, 2021

I'm suggesting someone support CMake in a separate repository. That way, the owner of that repository is responsible for keeping the CMake script up to date. It eliminates the burden from primary Flex repository and achieves the same result.

@nightlark
Copy link

nightlark commented Nov 2, 2021

Yes, a pr that -just- uses github actions, removing travis, would help. While that's maintaining the dependency on github, travis is showing its age and they're clearly moving away from the free support of open source projects.

Alright, that sounds like something I could get a PR prepared for relatively soon.

Automating the flex release process is something I need to get back to; that makes releases changes easier. Although, I have to watch that I don't become dependent on github any more than we are.

I have considered migrating the flex codebase to an organization setup; the real dependency there is again, I don't want to entangle myself or flex into github than we already are.

Any hosting platform will have its own way of managing things that needs to be dealt, particularly if more than one person has write access; self-hosting would come with its own (fun?) management issues.

I'll put some thought into ways the core of the release automation could be kept easy to move away from GitHub, for discussion on an automation related issue, so the rest of this can be kept focused on CMake.


A few CMake things that come to mind:

  • Better cross-platform support for users that makes things easier for users/packagers who are building flex from source; part of this might be the platform/build system independent commands that likely replace running arbitrary shell commands. If flex were providing things like pre-built binaries, CPack provides an easy way to create installers for a large number of platforms
  • Easier integration with C++ package managers (vcpkg, conan, hunter)
  • Not tied to a build system; generators can create native projects build systems and IDEs like ninja, XCode, Eclipse, Visual Studio, etc based on developer preference
  • Generally the language used to write CMake files is considered easier to understand (if Autotools is what someone is used to, this may not be the case)

I'm still trying to grok exactly what the build system is doing for the tests, though at least with my current understanding I could see a CMake version of the tests being more readable.

That said -- it seems like the main obstacle is needing at least one person to take ownership of the CMake side of things to keep it up to date and in-sync with changes to the Autotools build system. Using a separate repository seems like a good way to ensure that it would have a maintainer taking on that responsibility.

@westes
Copy link
Owner

westes commented Nov 2, 2021

I'm suggesting someone support CMake in a separate repository. That way, the owner of that repository is responsible for keeping the CMake script up to date. It eliminates the burden from primary Flex repository and achieves the same result.

That seems like it would work out well; people who want this feature would have it and it would leave flex maintenance where it is now.

@westes
Copy link
Owner

westes commented Nov 2, 2021

I'm still trying to grok exactly what the build system is doing for the tests, though at least with my current understanding I could see a CMake version of the tests being more readable.

For the tests, we have the problem that we're testing flex itself. We're testing the flex that we just built, on top of that. We need to test command line options in some cases and we need to test specific things in the flex input in some cases.

Since those things break just about every (otherwise reasonable) assumption that automake has about flex, we end up convincing it by changing a lot of default settings that automake has. In some cases, we have to explain rather patiently to automake that the normal ways of building things need to be replaced by various variants.

@westes
Copy link
Owner

westes commented Feb 15, 2022

One of the biggest problems I have with this kind of request is that flex is part of the bootstrap tooling for many systems. We have to preserve that or else we alienate a lot of the flex userbase.

If there were an alternate build system that provided ease of build on other platforms that didn't compromise the other things we need out of flex's build system, I could be pursuaded.

While looking around for other things, I found a tool called muon.

I see that it has a dependency that states that msvc builds are not supported.

Would that make using muon counter to the whole point of using an additional/alternate build system? I have no idea how prevalent various nonstandard, noncompliant compilers are, other than anecdata.

(As a side note, my sweet spot on this is having something that autogenerates its own not-Makefiles from Makefile.am and the like. I'd be willing to configure that in the flex codebase and ship autobuilt non-Makefiles with the flex distribution in that case. I also want a tiger made of lightning and a pony with wings.)

Copy link

@Ctwhsoca Ctwhsoca left a comment

Choose a reason for hiding this comment

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

Duplicate of #

@westes
Copy link
Owner

westes commented Apr 6, 2024

After a lot of discussion and evaluation, cmake does not meet flex's needs. At best, this would be a parallel build system that requires constant work to keep up with flex has to do.

@westes westes closed this Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants