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 improvements #69

Closed
wants to merge 6 commits into from
Closed

CMake improvements #69

wants to merge 6 commits into from

Conversation

Flamefire
Copy link
Contributor

@Flamefire Flamefire commented Jul 23, 2019

I looked over the CMake files and implemented a couple of enhancements and fixes.

  • Modularize into folders (test, examples, include, src) and add correct defaults (closes Make CMake tests and install directives optional #46)
  • Make config.h smaller and divide into 3 configs (examples, test, lib)
    • Allows to see what is actually required or define own config options
  • Move public include into include folder

This should now allow to use this project as a submodule from CMake with add_subdirectory allowing broader use without pulling in unnecessary dependencies or checks (FFTW, sndfile...)

Copy link
Member

@erikd erikd left a comment

Choose a reason for hiding this comment

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

This is a whole bunch of unrelated changes. You should probably PR some of these separately. You should also understand why things are the way they are before you decide to change them.

tests/throughput_test.c Outdated Show resolved Hide resolved
tests/util.h Outdated Show resolved Hide resolved
tests/multichan_throughput_test.c Outdated Show resolved Hide resolved
src/float_cast.h Outdated Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
@@ -19,7 +19,7 @@ test:
########

lib_LTLIBRARIES = src/libsamplerate.la
include_HEADERS = src/samplerate.h
include_HEADERS = include/samplerate.h
Copy link
Member

Choose a reason for hiding this comment

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

What???? Its fine (desirable even) to keep the header file in src/ and during installation put it in /usr/include.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree here. Could you tell me your reasoning why it would be "even desirable" to keep the public header in src/?

What proved advantageous was to separate out public and private headers already in the source tree. Public headers (ones installed) go into include private ones into src. This has 2 advantages:

  • Tests and examples can be build against the source tree. See https://github.com/erikd/libsamplerate/pull/69/files#diff-af3b638bc2a3e6c650974192a53c7291R70 The binaries linked against libsamplerate don't get to include the private headers. This avoids accidentally using a private there which would break on "real installs" and hence is an additional safe guard.
  • Consumers can add this git repo as a submodule and simply use it with add_subdirectory (motivation for this PR) They get the same includes (only public ones) as if using the installed library. This avoids having to install this in a separate step (and with a possibly mismatching compiler setting) which is a big bonus especially for Windows where dependencies are just a nightmare.

Makefile.am Outdated Show resolved Hide resolved
@Flamefire
Copy link
Contributor Author

This is a whole bunch of unrelated changes. You should probably PR some of these separately.

Sure. Which ones would you have separately? Most of the things is very related so I just put them in separate commits. What I can think of is the math/clip fixes and the src-evaluate fix although the cmake part depends on this one and I don't really like dependent MRs. So just tell me what you'd like in a separate MR.

You should also understand why things are the way they are before you decide to change them.

I do. I'm proficient in C++ & CMake but might miss some parts on C and autotools. So I got good reasons to change things but the solution might not be optimal. Let's talk about the individual changes to make this great project even better.

@Flamefire Flamefire mentioned this pull request Jul 26, 2019
1 task
@Flamefire
Copy link
Contributor Author

Flamefire commented Jul 26, 2019

I created smaller PRs which should be merged first to make this one small: #73, #74, #75, #76

@Flamefire Flamefire force-pushed the cmake branch 3 times, most recently from a5fdc05 to 3d5f63e Compare July 28, 2019 17:13
@Flamefire
Copy link
Contributor Author

I updated this PR to remove changes that were moved into other PRs and addressed comments. Anything else that should be factored into its own PR? Would be great to get this in, so projects using this are not impacted by dependencies for tests (e.g. searching for FFTW, libsndfile...)

Flamefire and others added 6 commits July 3, 2020 12:32
Move checks to the folders where they are required
Remove unused checks
Move samplerate.h to include folder (check for self-containedness)
unistd.h is only required in tests/examples, so add it there
The def file is only required for shared builds, so add it there
Follows CMake best practices to use target_ functions
They are included as `#include "src_config.h"` so they should be in the same folder
As an alternative: Add the `src` folder to include_directories but that violates the "clean includes" principle and fails to test that the public libsamplerate headers are self-contained
@evpobr
Copy link
Member

evpobr commented Oct 20, 2020

@Flamefire

Move public include into include folder

I like it.

Make config.h smaller and divide into 3 configs

Not sure. It is common practice to have one config.h. This is a support file, don't spend too much time on it. But that src/src_config.h should die. Usually it is simply used to include a config.h wrapped in a #ifdef HAVE_CONFIG_H.

Modularize into folders (test, examples, include, src)

Not sure. It seems to me that these are not such large projects to divide them into subdirectories. We have moved away from recursive makefiles and CMake files in libsndfile, to avoid a bunch of files here and there, it would be strange to have a project with subdirectories here.

@Flamefire
Copy link
Contributor Author

Not sure. It is common practice to have one config.h. This is a support file, don't spend too much time on it. But that src/src_config.h should die. Usually it is simply used to include a config.h wrapped in a #ifdef HAVE_CONFIG_H.

Sure but that config.h usually contains only macros required to make sure only features actually contained in the binary so consumers don't use stuff that isn't there. In this case (IIRC) there is more. Especially mixing in stuff that is only required for the tests is IMO reason enough to split it. Or to remove the test-only stuff and use plain preprocessor definitions on command line
The src_config.h was added by someone else who doesn't want a configure step IIRC. Fine by me.

Not sure. It seems to me that these are not such large projects to divide them into subdirectories.

It isn't that much about size but about organization. E.g. some dependencies are only required for tests or examples. With the 1-folder approach the boundaries are hard to define, with subdirs it is easy. (Example: With CMake I see it searching for FFTW and that might confuse new people into thinking FFTW is required for this library to work or provide some benefit)
And for users having an "examples" folder is also nice, so they can get a quick look how to use it. The tests are often not suitable for it. But tests and examples could be combined into 1 folder if wanted and files are properly named.

@evpobr
Copy link
Member

evpobr commented Oct 20, 2020

Ok, let's start from include PR. Add then create CMake subdirectories PR. Perhaps it is more convenient than I think now.

Flamefire added a commit to Flamefire/libsamplerate that referenced this pull request Nov 3, 2020
@evpobr
Copy link
Member

evpobr commented Nov 14, 2020

Sure but that config.h usually contains only macros required to make sure only features actually contained in the binary so consumers don't use stuff that isn't there. In this case (IIRC) there is more. Especially mixing in stuff that is only required for the tests is IMO reason enough to split it. Or to remove the test-only stuff and use plain preprocessor definitions on command line

I suggest another option - why not move the checks required for the library and tests to their subprojects, and call confgure_file() after all add_subdirectory()?

@Flamefire
Copy link
Contributor Author

Given that config.h is not installed this is certainly an option. The downside I see is that this way it can't be tested whether the main header is "clean", i.e. doesn't rely on anything from config.h. Additionally it can't be tested that the main binary doesn't rely on anything from the tests, i.e. something (a dependency search) was wrongly added in the test/example folder but should have been in the main instead.

But given that there is only a single header this can be verified manually and your approach is quite easy to do.

@evpobr
Copy link
Member

evpobr commented Nov 16, 2020

The downside I see is that this way it can't be tested whether the main header is "clean", i.e. doesn't rely on anything from config.h.

This is too much even for a paranoid person like me 😄

@evpobr evpobr closed this in 5120f95 Nov 30, 2020
@Flamefire Flamefire deleted the cmake branch June 1, 2024 09:46
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.

Make CMake tests and install directives optional
3 participants