CMakeLists.txt suggestion
lewismj opened this issue · 6 comments
Hi,
If a minimal CMakeLists.txt file is added to the project, e.g.
project(mpc C)
set(CMAKE_C_STANDARD 99)
add_library(mpc mpc.c mpc.h)
Then this would allow convenient import of mpc into other projects that used CMake, for example:
cmake_minimum_required(VERSION 3.19)
project(scratchpad3)
set(CMAKE_CXX_STANDARD 17)
include(FetchContent)
FetchContent_Declare(
mpc
GIT_REPOSITORY https://github.com/lewismj/mpc.git
GIT_TAG master
)
FetchContent_GetProperties(mpc)
if(NOT mpc_POPULATED)
FetchContent_Populate(mpc)
add_subdirectory(${mpc_SOURCE_DIR} ${mpc_BINARY_DIR})
endif()
include_directories(${CMAKE_BINARY_DIR}/_deps/mpc-src)
add_executable(scratchpad3 main.cpp)
target_link_libraries(${PROJECT_NAME} mpc)
I cloned and tested this, it allows downstream users of cmake to just use 'FetchContent' which is quite nice, if you want to allow someone to build from scratch without having dependencies installed?
Sorry, I errantly closed that. Pardon the noise.
So, I have two questions (not being hugely familiar with CMake):
- I don't think this compiles
mpc
with all the options that theMakefile
specifies right now; is it much more complex to offer this? - I think if
mpc
supported multiple build systems, it's essentially guaranteed that they'll get out-of-sync. Is it possible to generate theCMakeLists.txt
from theMakefile
(e.g., via a shell script or amake
target) so they can remain in-sync?
(worth noting that I'm not the maintainer of this project, but I have worked on projects that support multiple build-systems.)
CMake is a generic cross platform build tool. It isn't a replacement for make; CMake would generate the build files, e.g. make files. It is a more convenient way to define the build.
So, cmake; make; make install is usual build process.
e.g. https://cmake.org/cmake/help/latest/guide/tutorial/index.html
Example, MSFT, cpp rest sdk: https://github.com/microsoft/cpprestsdk
Apple, Foundation DB, https://github.com/apple/foundationdb
It is pretty much a standard in the C/C++ world.
Generally I'm not a big fan of cmake, and given the CMakeLists.txt
you propose is only three lines I'm sure the people who do want to use it can add it themselves. The recommended way to use this project is just to copy the source files directly. Having the Makefile
in the repo is useful for various things e.g. running tests and while it is there we may as well configure it so it can build and install the lib statically or dynamically too.
@lewismj, I'm familiar enough with cmake to know what it is and how it normally works. I thought you were suggesting adding that CMakeLists.txt
in addition to the Makefile
that's already integrated rather than replacing it with cmake. I personally don't love cmake; I find it a huge additional dependency without a ton of benefit (until it gets to huge projects).
Ok, CMake is usually used for defining the stuff like running tests and installation etc... But I think I'll just add it locally thanks. I would recommend learning about its capabilities though.