Skip to content

Commit

Permalink
cmake: export targets in config files
Browse files Browse the repository at this point in the history
  • Loading branch information
RMZeroFour committed Nov 7, 2024
1 parent 9377370 commit f39b4e7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 62 deletions.
111 changes: 76 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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 @@ -243,13 +244,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 @@ -314,6 +318,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})
add_library(notcurses-static STATIC ${NCSRCS} ${COMPATSRC})
else()
Expand All @@ -322,13 +327,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 @@ -492,6 +500,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 @@ -506,7 +515,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 @@ -517,6 +528,8 @@ set(NCPP_INCLUDE_DIRS

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

Expand Down Expand Up @@ -601,8 +614,6 @@ file(GLOB NCPP_INTERNAL_HEADERS
LIST_DIRECTORIES false
${PROJECT_SOURCE_DIR}/include/ncpp/internal/*.hh)

export(PACKAGE notcurses)

install(FILES ${NOTCURSES_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/notcurses)
install(FILES ${NCPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncpp)
install(FILES ${NCPP_INTERNAL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncpp/internal)
Expand Down Expand Up @@ -1029,55 +1040,41 @@ configure_file(tools/notcurses++.pc.in
@ONLY
)

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
)

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
)

# 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"
)

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 @@ -1136,24 +1133,68 @@ endif()
endif() # BUILD_EXECUTABLES

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

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

install(TARGETS ${INSTLIBS}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_COMPONENT Development
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)
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.

0 comments on commit f39b4e7

Please sign in to comment.