lexborisov / Modest

Modest is a fast HTML renderer implemented as a pure C99 library with no outside dependencies.
GNU Lesser General Public License v2.1
732 stars 65 forks source link

Cmake support (patch to enable it) #64

Closed roromo closed 5 years ago

roromo commented 5 years ago

Hi Lex,

I have attached a patch which enables CMake support. I noticed that you started another project, but it might be useful to still support this one, at least until the other project reaches feature parity.

Maybe it could also prove useful as inspiration for that other project? :)

The patch adds modern CMake support, and is validated on both Linux and Windows. On Windows, it works with both mingw (gcc) and the Visual Studio compilers.

Features:

Notes:

A project that wants to use the installed libraries only has to add the modest libraries installation folder to its CMAKE_MODULE_PATH, and specify this in its CMakeLists.txt:

find_package(modest CONFIG REQUIRED) ................................................................................... target_link_libraries(my_app $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,modest::modest_shared,modest::modest_static> )

The above will let the linking to the dynamic or the static library be controlled by the CMake global flag BUILD_SHARED_LIBS.

When "my_app" is built in Debug configuration, the modest Debug binaries will be linked in automatically. When "my_app" is built in Release configuration, the modest Release binaries will be linked in instead, etc.

As you can see, this is the modern Cmake way, with no need for include_directories and such.

To manually enforce the linking to the shared library, one would replace the above with: target_link_libraries(my_app modest::modest_shared )

Or for enforcing the linking with the static library: target_link_libraries(my_app modest::modest_static )

What this Cmake support patch does not do, is build the examples and the tests though. cmake_support.zip

lexborisov commented 5 years ago

Hi @roromo

You make the great job! It is very useful. Can you send a pull request?

roromo commented 5 years ago

Hi @roromo

You make the great job! It is very useful. Can you send a pull request?

Ok, pull request sent.

roromo commented 5 years ago

If you would like to bring some changes to how things are organized and built, let me know and I will try to help if I know how to. :)