advanpix / mpreal

GNU General Public License v3.0
82 stars 19 forks source link

Add cmake. #4

Open emsr opened 4 years ago

emsr commented 4 years ago

This adds cmake support. This is useful to use mpreal as a submodule in another git project that uses cmake. The only targets are the interface (header-only) library mpreal and mpreal_example - the test/example utility. I left the makefile in the example directory as it doesn't impact cmake.

We could set the C++ version back to 11 if you want to. Ed Smith-Rowland

advanpix commented 2 years ago

Yes, it is better to remove requirement for C++ standard as mpreal can work with anything down to C++ 2003 and even older.

advanpix commented 2 years ago

Please consider removing the restriction on C++ standard. It is really has no sense for MPFR C++. I would prefer keeping GMP/MPFR CMake files out of the MPFR C++ repository. It is responsibility of the main program/target user to find & link to proper GMP/MPFR.

Besides, GMP cannot be used in MSVC (MPIR is used instead). So that including GMP scripts has no sense for a lot of target users.

emsr commented 2 years ago

I'm removing the standard requirement. That's a good idea. I just pushed to my repo.

emsr commented 2 years ago

I took out the GMP and MPFR scripts also. So now it's just a header-only library with no enforced dependencies. W00t!

emsr commented 2 years ago

The CMakeLists does still have mpfr as a target link library for the example but it doesn't seem to need a script if mpfr is on your system.

emsr commented 2 years ago

Ok, now I've pushed the changes to my branch. No sure what happened. I also merged the latest.

advanpix commented 2 years ago

Could you please elaborate a bit why do you think CMake is needed for mpreal at all? The mpreal is one-header library, without restrictions on C++ compiler features, on GMP/MPIR/MPFR versions, etc. etc. Basically it is supposed to be used as a simple header file.

I use CMake in most of my projects, but I have difficulties in understanding how it can be useful for mpreal. Would appreciate to see some real example why this can be useful.

emsr commented 2 years ago

This came up when I added mpreal as a submodule in a larger cmake project. This allows another part of the library to have

add_executable(thing ...) target_link_libraries(thing mpreal ...)

So everywhere I use mpreal it's just adding one word in target_link_libraries.

I agree that there's no reason intrinsic to mpreal to have CMakeLists (it does build the example) - it's just easier to integrate into a larger cmake project. Not that it's that hard anyway.

emsr commented 2 years ago

I don't think having CMake would break other ways of using mpreal.