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

Rewrite install procedure and fix #151 #196

Merged
merged 15 commits into from
Sep 26, 2022
Merged
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
11 changes: 9 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ on: [push, pull_request]
jobs:
Build:
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- name: Setup CMake
uses: jwlawson/actions-setup-cmake@v1.12
with:
cmake-version: '3.24.x'
github-api-token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v2

Expand All @@ -17,3 +21,6 @@ jobs:

- name: Test
run: bash ci/tests.sh

- name: Standalone
run: cmake -DCMAKE_INSTALL_PREFIX=./standalone-install -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install/ -S ./tests/test-standalone -B ./standalone-build; cmake --build ./standalone-build; cmake --install ./standalone-build
3 changes: 3 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ jobs:

- name: Test
run: bash ci/tests.sh

- name: Standalone
run: cmake -DCMAKE_INSTALL_PREFIX=./standalone-install -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install/ -S ./tests/test-standalone -B ./standalone-build; cmake --build ./standalone-build ; cmake --install ./standalone-build
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if(MSVC)
endif()
endif()

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")

project(cpp-terminal
VERSION 1.0.0
DESCRIPTION "Small header only C++ library for writing multiplatform terminal applications"
Expand Down Expand Up @@ -40,8 +42,8 @@ if (CPPTERMINAL_BUILD_EXAMPLES)
endif()

if (CPPTERMINAL_ENABLE_INSTALL)
include(cmake/install.cmake)
install_library(cpp-terminal)
include(install)
install_library()
endif()

if(MSVC)
Expand Down
9 changes: 1 addition & 8 deletions ci/compile_test.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#cmake -DCMAKE_INSTALL_PREFIX=.\inst .
cmake .
cmake -DCMAKE_INSTALL_PREFIX=./install .
cmake --build . --config Release
cmake --install . --config Release
ctest --output-on-failure

# Install on windows is complicated and not like on linux
MCWertGaming marked this conversation as resolved.
Show resolved Hide resolved
#cd tests\test-standalone
#cmake -DCMAKE_PREFIX_PATH=%cd%\..\inst .
#cmake --build . --config Release
#cd
10 changes: 3 additions & 7 deletions ci/compile_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

set -ex

cmake -DCMAKE_INSTALL_PREFIX=./inst .
cmake --build . --config Release
cmake --install . --config Release
cmake -DCMAKE_INSTALL_PREFIX=./install .
cmake --build .
cmake --install .
ctest --output-on-failure

cd tests/test-standalone
cmake -DCMAKE_PREFIX_PATH=../../inst .
cmake --build . --config Release
5 changes: 5 additions & 0 deletions cmake/cpp-terminalConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/cpp-terminalTargets.cmake")

check_required_components(cpp-terminal)
41 changes: 9 additions & 32 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
function(install_library TARGET_LIB_NAME)

install(TARGETS ${TARGET_LIB_NAME} EXPORT ${TARGET_LIB_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/${TARGET_LIB_NAME}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB_NAME}/${TARGET_LIB_NAME}ConfigVersion.cmake"
VERSION ${CPPTERMINAL_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${TARGET_LIB_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB_NAME}/${TARGET_LIB_NAME}Targets.cmake"
)
set(ConfigPackageLocation lib/cmake/${TARGET_LIB_NAME})
configure_file(${TARGET_LIB_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB_NAME}/${TARGET_LIB_NAME}Config.cmake"
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB_NAME}/${TARGET_LIB_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB_NAME}/${TARGET_LIB_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB_NAME}/${TARGET_LIB_NAME}Targets.cmake"
DESTINATION
${ConfigPackageLocation}
COMPONENT
Devel
)
endfunction(install_library TARGET_LIB_NAME)
function(install_library)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/cpp-terminalConfig.cmake.in" "${PROJECT_BINARY_DIR}/cmake/cpp-terminalConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cpp-terminal")
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cpp-terminalConfigVersion.cmake" COMPATIBILITY AnyNewerVersion)
install(TARGETS cpp-terminal EXPORT cpp-terminalTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cpp-terminal" PRIVATE_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cpp-terminal/private")
install(EXPORT cpp-terminalTargets FILE cpp-terminalTargets.cmake NAMESPACE cpp-terminal:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cpp-terminal")
install(FILES "${PROJECT_BINARY_DIR}/cmake/cpp-terminalConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cpp-terminalConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cpp-terminal")
endfunction()
9 changes: 4 additions & 5 deletions cpp-terminal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# configure version information
configure_file(version.h.in version.h)
configure_file(version.hpp.in version.hpp)

# create and configure library target
add_library(cpp-terminal base.cpp prompt.cpp window.cpp input.cpp private/platform.cpp)

target_include_directories(cpp-terminal PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/private>
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpp-terminal>)
target_include_directories(cpp-terminal PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> $<INSTALL_INTERFACE:include>)

set_target_properties(cpp-terminal PROPERTIES
PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/version.h;${CMAKE_CURRENT_SOURCE_DIR}/base.hpp;${CMAKE_CURRENT_SOURCE_DIR}/prompt.hpp;${CMAKE_CURRENT_SOURCE_DIR}/window.hpp;${CMAKE_CURRENT_SOURCE_DIR}/input.hpp"
)
PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/version.hpp;${CMAKE_CURRENT_SOURCE_DIR}/base.hpp;${CMAKE_CURRENT_SOURCE_DIR}/prompt.hpp;${CMAKE_CURRENT_SOURCE_DIR}/window.hpp"
PRIVATE_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/private/conversion.hpp;${CMAKE_CURRENT_SOURCE_DIR}/private/platform.hpp")

add_library(cpp-terminal::cpp-terminal ALIAS cpp-terminal)
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/colors.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cpp-terminal/version.h>
#include <cpp-terminal/base.hpp>
#include <iostream>
#include "cpp-terminal/base.hpp"
MCWertGaming marked this conversation as resolved.
Show resolved Hide resolved
#include "cpp-terminal/version.hpp"

int main() {
std::cout << "Running cpp-terminal version: "
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_immediate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cpp-terminal/version.h>
#include <cpp-terminal/prompt.hpp>
#include <cpp-terminal/version.hpp>
#include <iostream>

int main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_not_immediate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cpp-terminal/version.h>
#include <cpp-terminal/prompt.hpp>
#include <cpp-terminal/version.hpp>
#include <iostream>

int main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_simple.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cpp-terminal/version.h>
#include <cpp-terminal/prompt.hpp>
#include <cpp-terminal/version.hpp>
#include <iostream>

int main() {
Expand Down
11 changes: 0 additions & 11 deletions tests/build.bat

This file was deleted.

15 changes: 6 additions & 9 deletions tests/test-standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

project(test-standalone CXX)

if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17
CACHE STRING "C++ standard" FORCE)
endif ()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(cpp-terminal REQUIRED)

add_executable(colors colors.cpp)
target_link_libraries(colors cpp-terminal)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

get_filename_component(buildDirRelFilePath "${CMAKE_CURRENT_SOURCE_DIR}/../../examples/colors.cpp" REALPATH BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(colors "${buildDirRelFilePath}")
target_link_libraries(colors PRIVATE cpp-terminal::cpp-terminal)
Loading