-
Notifications
You must be signed in to change notification settings - Fork 680
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
added CMakeLists.txt to support building via cmake #223
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
cmake_minimum_required(VERSION 3.4) | ||
project(linenoise C) | ||
|
||
include(GNUInstallDirs) | ||
|
||
option(LINENOISE_BUILD_EXAMPLE OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second argument is for a documentation string. |
||
|
||
# ----------------- | ||
# LIBRARY | ||
# ----------------- | ||
add_library(${PROJECT_NAME} linenoise.c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not abuse |
||
target_include_directories(${PROJECT_NAME} | ||
INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/linenoise> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
) | ||
target_compile_options(${PROJECT_NAME} | ||
PRIVATE -Wall -W | ||
) | ||
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hardcode toolchain flags. These can be provided from the command line or (more conveniently for developers) a preset. |
||
|
||
# ----------------- | ||
# EXAMPLE | ||
# ----------------- | ||
if(LINENOISE_BUILD_EXAMPLE) | ||
add_executable(${PROJECT_NAME}-example example.c) | ||
target_link_libraries(${PROJECT_NAME}-example | ||
PRIVATE ${PROJECT_NAME} | ||
) | ||
target_compile_options(${PROJECT_NAME} | ||
PRIVATE -Wall -W | ||
) | ||
endif() | ||
|
||
# ----------------- | ||
# INSTALLATION | ||
# ----------------- | ||
if(TARGET ${PROJECT_NAME}-example) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When and why does an example need to be installed? |
||
install (TARGETS ${PROJECT_NAME}-example | ||
DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) | ||
endif() | ||
|
||
install (TARGETS ${PROJECT_NAME} | ||
EXPORT ${PROJECT_NAME}Config | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You set the minimum to be 3.4, but this command invocation relies on defaults provided only by 3.14. |
||
|
||
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/linenoise.h | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/linenoise/ | ||
) | ||
|
||
install(EXPORT ${PROJECT_NAME}Config | ||
NAMESPACE ${PROJECT_NAME}:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add an |
||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefer to put things closer to where they are used.