Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions CMakeLists.txt
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)

Copy link
Copy Markdown

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.


option(LINENOISE_BUILD_EXAMPLE OFF)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do not abuse PROJECT_NAME like this.

target_include_directories(${PROJECT_NAME}
INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/linenoise>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use install(TARGETS ... INCLUDES DESTINATION) instead for specifying includes for the install.

)
target_compile_options(${PROJECT_NAME}
PRIVATE -Wall -W
)
Comment on lines +15 to +17

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

@friendlyanon friendlyanon May 10, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.
Spell out the RUNTIME, LIBRARY and ARCHIVE destinations or raise the minimum requirement.


install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/linenoise.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/linenoise/
)

install(EXPORT ${PROJECT_NAME}Config
NAMESPACE ${PROJECT_NAME}::

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please also add an ALIAS target that matches this name.

DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)