Skip to content
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

cmake: export targets in config files #2800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
117 changes: 81 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ file(GLOB COMPATSRC CONFIGURE_DEPENDS src/compat/*.c)
# libnotcurses-core (core shared library, core static library)
file(GLOB NCCORESRCS CONFIGURE_DEPENDS src/lib/*.c)
add_library(notcurses-core SHARED ${NCCORESRCS} ${COMPATSRC})
add_library(Notcurses::NotcursesCore ALIAS notcurses-core)
if(${USE_STATIC})
add_library(notcurses-core-static STATIC ${NCCORESRCS} ${COMPATSRC})
else()
Expand All @@ -250,13 +251,16 @@ endif()
set_target_properties(notcurses-core PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
EXPORT_NAME NotcursesCore
)
set_target_properties(notcurses-core-static PROPERTIES
VERSION ${PROJECT_VERSION}
OUTPUT_NAME notcurses-core
)
target_include_directories(notcurses-core
BEFORE
PUBLIC
$<INSTALL_INTERFACE:include>
PRIVATE
include
src
Expand Down Expand Up @@ -321,6 +325,7 @@ endif()
# libnotcurses (multimedia shared library+static library)
file(GLOB NCSRCS CONFIGURE_DEPENDS src/media/*.c src/media/*.cpp)
add_library(notcurses SHARED ${NCSRCS} ${COMPATSRC})
add_library(Notcurses::Notcurses ALIAS notcurses)
if(${USE_STATIC})
# can't build binaries against static notcurses until ffmpeg linking issues
# are resolved (USE_STATIC_BINARIES) FIXME
Expand All @@ -331,13 +336,16 @@ endif()
set_target_properties(notcurses PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
EXPORT_NAME Notcurses
)
set_target_properties(notcurses-static PROPERTIES
VERSION ${PROJECT_VERSION}
OUTPUT_NAME notcurses
)
target_include_directories(notcurses
BEFORE
PUBLIC
$<INSTALL_INTERFACE:include>
PRIVATE
include
src
Expand Down Expand Up @@ -501,6 +509,7 @@ set(NCPP_SOURCES
)

add_library(notcurses++ SHARED ${NCPP_SOURCES})
add_library(Notcurses::Notcurses++ ALIAS notcurses++)
if(${USE_STATIC})
add_library(notcurses++-static STATIC ${NCPP_SOURCES})
else()
Expand All @@ -515,7 +524,9 @@ set_target_properties(
notcurses++ PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
OUTPUT_NAME "notcurses++")
OUTPUT_NAME "notcurses++"
EXPORT_NAME Notcurses++
)

set(NCPP_INCLUDE_DIRS
"include"
Expand All @@ -526,7 +537,10 @@ set(NCPP_INCLUDE_DIRS

target_include_directories(notcurses++
BEFORE
PRIVATE ${NCPP_INCLUDE_DIRS}
PUBLIC
$<INSTALL_INTERFACE:include>
PRIVATE
${NCPP_INCLUDE_DIRS}
)

target_include_directories(notcurses++-static
Expand Down Expand Up @@ -620,18 +634,18 @@ file(GLOB NCPP_INTERNAL_HEADERS
LIST_DIRECTORIES false
${PROJECT_SOURCE_DIR}/include/ncpp/internal/*.hh)

install(FILES ${NCPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncpp)
install(FILES ${NCPP_INTERNAL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncpp/internal)

export(PACKAGE notcurses)

file(GLOB NOTCURSES_HEADERS
CONFIGURE_DEPENDS
LIST_DIRECTORIES false
${PROJECT_SOURCE_DIR}/include/notcurses/*.h
${CMAKE_CURRENT_BINARY_DIR}/include/version.h)

install(FILES ${NCPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncpp)
install(FILES ${NCPP_INTERNAL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncpp/internal)
install(FILES ${NOTCURSES_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/notcurses)

export(PACKAGE notcurses)

# tiny proofs of concept, one binary per source file
if(USE_POC)
file(GLOB POCSRCS CONFIGURE_DEPENDS src/poc/*.c)
Expand Down Expand Up @@ -1063,36 +1077,23 @@ if(${USE_CXX})
@ONLY
)
endif()
include(CMakePackageConfigHelpers)

configure_file(tools/version.h.in include/version.h)
configure_file(tools/builddef.h.in include/builddef.h)

configure_package_config_file(tools/NotcursesConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses
)
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/NotcursesCoreConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(tools/NotcursesCoreConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/NotcursesCoreConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/NotcursesCore
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

if(${USE_CXX})
configure_package_config_file(tools/Notcurses++Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/Notcurses++Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/Notcurses++ConfigVersion.cmake
COMPATIBILITY SameMajorVersion
Expand All @@ -1101,20 +1102,20 @@ endif()

# Installation
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/NotcursesCoreConfig.cmake"
"tools/NotcursesCoreConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/NotcursesCoreConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/NotcursesCore"
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfig.cmake"
"tools/NotcursesConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses"
)

if(${USE_CXX})
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/Notcurses++Config.cmake"
"tools/Notcurses++Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Notcurses++ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++"
)
Expand Down Expand Up @@ -1176,25 +1177,69 @@ endif()
endif() # BUILD_EXECUTABLES

if(${BUILD_FFI_LIBRARY})
LIST(APPEND INSTLIBS notcurses-ffi)
install(TARGETS notcurses-ffi
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
)
endif()
LIST(APPEND INSTLIBS notcurses-core notcurses)

if(${USE_STATIC})
LIST(APPEND INSTLIBS notcurses-core-static notcurses-static)
endif()
install(TARGETS notcurses-core-static notcurses-static
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
)
if(${USE_CXX})
LIST(APPEND INSTLIBS notcurses++)
if(${USE_STATIC})
LIST(APPEND INSTLIBS notcurses++-static)
endif()
endif()

install(TARGETS ${INSTLIBS}
install(TARGETS notcurses++-static
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
)
endif()
endif()

install(TARGETS notcurses-core
EXPORT NotcursesCoreExport
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
)
install(EXPORT NotcursesCoreExport
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/NotcursesCore
NAMESPACE Notcurses::
FILE NotcursesCoreTargets.cmake
)

install(TARGETS notcurses
EXPORT NotcursesExport
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
)
install(EXPORT NotcursesExport
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses
NAMESPACE Notcurses::
FILE NotcursesTargets.cmake
)

install(TARGETS notcurses++
EXPORT Notcurses++Export
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
)
install(EXPORT Notcurses++Export
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++
NAMESPACE Notcurses::
FILE Notcurses++Targets.cmake
)

option(DUMMY_PYTHON "Build dummy python module used for compile check and Clangd" OFF)
if(${DUMMY_PYTHON})
Expand Down
8 changes: 8 additions & 0 deletions tools/Notcurses++Config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include(CMakeFindDependencyMacro)
find_dependency(Notcurses)

include("${CMAKE_CURRENT_LIST_DIR}/Notcurses++Targets.cmake")

set(Notcurses++_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include")
set(Notcurses++_LIBRARY_DIRS "")
set(Notcurses++_LIBRARIES Notcurses::Notcurses++)
9 changes: 0 additions & 9 deletions tools/Notcurses++Config.cmake.in

This file was deleted.

8 changes: 8 additions & 0 deletions tools/NotcursesConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include(CMakeFindDependencyMacro)
find_dependency(NotcursesCore)

include("${CMAKE_CURRENT_LIST_DIR}/NotcursesTargets.cmake")

set(Notcurses_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include")
set(Notcurses_LIBRARY_DIRS "")
set(Notcurses_LIBRARIES Notcurses::Notcurses)
9 changes: 0 additions & 9 deletions tools/NotcursesConfig.cmake.in

This file was deleted.

8 changes: 8 additions & 0 deletions tools/NotcursesCoreConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include(CMakeFindDependencyMacro)
find_dependency(Threads)

include("${CMAKE_CURRENT_LIST_DIR}/NotcursesCoreTargets.cmake")

set(NotcursesCore_INCLUDE_DIRS "")
set(NotcursesCore_LIBRARY_DIRS "")
set(NotcursesCore_LIBRARIES Notcurses::NotcursesCore)
9 changes: 0 additions & 9 deletions tools/NotcursesCoreConfig.cmake.in

This file was deleted.

Loading