stamen

Stamen - static menu generator
git clone git://git.dimitrijedobrota.com/stamen.git
Log | Files | Refs | README | LICENSE

commit e665a6f2bca782f688527dcf8232eeff412652a8
parent 6f2789a11b79acf217c112117a6969a0ec5e4a57
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 14 Jun 2024 00:56:34 +0200

Improve CMake, prepare for isntallation

Diffstat:
MCMakeLists.txt | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdemo/CMakeLists.txt | 3++-
Msrc/CMakeLists.txt | 13+++----------
AstamenConfig.cmake.in | 7+++++++
4 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -16,5 +16,86 @@ set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) +endif() + +include(GNUInstallDirs) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + +set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries") +set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables") +set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for header files") +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKEDIR CMake) +else() + set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME}) +endif() +set(INSTALL_CMAKEDIR ${DEF_INSTALL_CMAKEDIR} CACHE PATH "Installation directory for CMake files") + +message(STATUS "Build type set to ${CMAKE_BUILD_TYPE}") +message(STATUS "Project will be installed to ${CMAKE_INSTALL_PREFIX}") +foreach(p LIB BIN INCLUDE CMAKE) + file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${INSTALL_${p}DIR} _path) + message(STATUS "installing ${p} components to ${_path}") + unset(_path) +endforeach() + add_subdirectory(src) add_subdirectory(demo) + +install( + TARGETS + stamen-generate + stamen + EXPORT + stamenTargets + ARCHIVE + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + RUNTIME + DESTINATION ${INSTALL_BINDIR} + COMPONENT bin + LIBRARY + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDEDIR}/stamen + COMPONENT dev +) + +install( + EXPORT + stamenTargets + NAMESPACE + "stamen::" + DESTINATION + ${INSTALL_CMAKEDIR} + COMPONENT + dev +) + +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/stamenConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + ${PROJECT_SOURCE_DIR}/stamenConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/stamenConfig.cmake + INSTALL_DESTINATION ${INSTALL_CMAKEDIR} +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/stamenConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/stamenConfigVersion.cmake + DESTINATION + ${INSTALL_CMAKEDIR} +) diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt @@ -11,7 +11,7 @@ add_custom_command( add_executable(demo main.cpp ${GENERATE_OUT}/demo_menu.cpp) # target_link_libraries(demo stamen) - no need to link -target_include_directories(demo PUBLIC ../include) +target_include_directories(demo PRIVATE ../include) set_target_properties(demo PROPERTIES LINKER_LANGUAGE CXX) target_include_directories(demo PRIVATE ${GENERATE_OUT} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -41,6 +41,7 @@ set_target_properties(cdemo PROPERTIES add_executable(dynamic dynamic.cpp) target_link_libraries(dynamic stamen) +target_include_directories(dynamic PRIVATE ../include) set_target_properties(dynamic PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(dynamic PROPERTIES diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt @@ -1,5 +1,5 @@ add_library(stamen STATIC stamen.cpp menu.cpp c_bindings.cpp) -target_include_directories(stamen PUBLIC ../include) +target_include_directories(stamen PRIVATE ../include) target_compile_definitions(stamen PRIVATE WITH_C_BINDINGS) set_target_properties(stamen PROPERTIES LINKER_LANGUAGE CXX) @@ -7,24 +7,17 @@ set_target_properties(stamen PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} DEBUG_POSTFIX "d" - PUBLIC_HEADER "../include/stamen.h;../include/stamen.hpp" + PUBLIC_HEADER "include/stamen.h;include/stamen.hpp" MACOSX_RPATH ON WINDOWS_EXPORT_ALL_SYMBOLS ON ) -install(TARGETS stamen - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include -) - add_executable(stamen-generate generate.cpp) target_link_libraries(stamen-generate PRIVATE stamen) -target_include_directories(stamen-generate PUBLIC ../include) +target_include_directories(stamen-generate PRIVATE ../include) set_target_properties(stamen-generate PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) - -install(TARGETS stamen-generate DESTINATION bin) diff --git a/stamenConfig.cmake.in b/stamenConfig.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/stamenTargets.cmake") + +check_required_components( + "stamen-generate" + "stamen" +)