installing a hpp file for reuse in a ubuntu laptop

I wanna know how to install a header files on the computer the header file called ihead5.hpp is like this `#include
#include

using namespace std; //

void i5 (int a1,string s1) { /// a simple test fuction

cout << 20 <<s1;

}

`

and the cmakelists.txt is like this : cmake_minimum_required(VERSION 3.28.3) # this is a practice CmakeLists to learn to install headers file in the computer

project(itest5 CXX ) # project name and version

set(CMAKE_EXPORT_COMPILE_COMMANDS)

set(BUILD_BUNDLE_DIR “${PROJECT_BINARY_DIR}/lib”)

set(CMAKE_INSTALL_PREFIX “${BUILD_BUNDLE_DIR}” CACHE PATH “…” FORCE)

add_library(ihead5 ihead5.hpp )

set_target_properties(ihead5 PROPERTIES LINKER_LANGUAGE CXX) # set targets property

include(GNUInstallDirs) #include gnuinstalldir

install(TARGETS ihead5

EXPORT ihead5

ARCHIVE DESTINATION lib) # ihead goes to lib file

install(FILES

EXPORT ihead5.hpp

DESTINATION include) # ihead.hpp goes to include folder but i get thew error when using install command on vscode : [main] Building folder: /home/d22/cmake_oef1/lib1/installtest1/build install [build] Starting build [proc] Executing command: /usr/bin/cmake --build /home/d22/cmake_oef1/lib1/installtest1/build --config Debug --target install -- [build] [1/1 0% :: 0.000] Install the project... [build] -- Install configuration: "Debug" [build] -- Up-to-date: /home/d22/cmake_oef1/lib1/installtest1/build/lib/lib/libihead5.a [build] CMake Error at cmake_install.cmake:50 (file): [build] file INSTALL cannot find "/home/d22/cmake_oef1/lib1/installtest1/EXPORT": [build] No such file or directory. [build] [build] [build] FAILED: CMakeFiles/install.util [build] cd /home/d22/cmake_oef1/lib1/installtest1/build && /usr/bin/cmake -P cmake_install.cmake [build] ninja: build stopped: subcommand failed. [proc] The command: /usr/bin/cmake --build /home/d22/cmake_oef1/lib1/installtest1/build --config Debug --target install -- exited with code: 1 [driver] Build completed: 00:00:00.023 [build] Build finished with exit code 1 Can someone help?

Blockquote

I can barely see where the code starts/ends and where your own text ends/starts, so your post would certainly benefit from having a proper formatting.

As for installing single files, that can be done with install(FILES ... DESTINATION ...), although in case of installing public headers it is better to be handled with install(TARGETS ... PUBLIC_HEADER DESTINATION ...), but for that to work you would need to set the PUBLIC_HEADER target property.

ihead goes to lib file

You seem to be creating a header-only library, so I doubt that this would work the way you expect it to.

For me the error comes from your call to install(TARGETS ihead5 EXPORT ihead5 ARCHIVE DESTINATION lib) because you’re mixing two different signatures.

See: https://cmake.org/cmake/help/latest/command/install.html

You will find a fully working modern example at:
CMake-Best-Practices—2nd-Edition/…/CMakeLists.txt

i sort kinda fix it by typing in the cmake this :


cmake_minimum_required(VERSION 3.22)
project(itest5 CXX ) # project name and version

set(CMAKE_EXPORT_COMPILE_COMMANDS)

add_library(ihead5 INTERFACE ihead5.hpp )

target_sources(ihead5 PUBLIC
ihead5.hpp ) # set targets property
set_target_properties(ihead5 PROPERTIES LINKER_LANGUAGE CXX)
include(GNUInstallDirs) #include gnuinstalldir

install(FILES ihead5.hpp DESTINATION lib) # goes to the lib files

install(FILES ihead5.hpp DESTINATION /usr/include) # goes to the /usr/include folder

install(FILES ihead5.hpp DESTINATION /usr/bin) # goes to the /usr/include folder

and now it finds the header in the cpp file i use for testing called ihead5test.cpp : 

#include <ihead5.hpp>

int main() {

i5(“hello h6”); // is the function of the ihead5.hpp file

}

but if try to add the hpp in a other CMakeList.txt :

cmake_minimum_required(VERSION 3.22.1)
project(libtest1) # a project to test header files in other folders

include_directories(include)

find_library(ihead5 required) # but if i do add

#this find_library function it cannot find it

add_executable(ihead5test ihead5test.cpp) # it can be executed but

without mentiononing the ihead5.hpp file int CMakeLists.txt



target_link_libraries(ihead5test ihead5)

i get this errors :

[{
	"resource": "/home/jonathan/Documents/cpp.test/Cmake_practice/biebtest/CMakeLists.txt",
	"owner": "cmake-configure-diags",
	"severity": 8,
	"message": "CMake Error at CMakeLists.txt:7 (add_library):Cannot find source file:\n\n  ihead5.hpp",
	"source": "CMake (add_library)",
	"startLineNumber": 7,
	"startColumn": 1,
	"endLineNumber": 7,
	"endColumn": 10000
}]

and : [{ "resource": "/home/jonathan/Documents/cpp.test/Cmake_practice/biebtest/CMakeLists.txt", "owner": "cmake-configure-diags", "severity": 8, "message": "CMake Error at CMakeLists.txt:7 (add_library):No SOURCES given to target: ihead5", "source": "CMake (add_library)", "startLineNumber": 7, "startColumn": 1, "endLineNumber": 7, "endColumn": 10000 }]
do you know what i might do wrong?