init
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
|
||||
# define CXX interface library
|
||||
|
||||
# define target & alias (for other projects consuming the "source-tree")
|
||||
add_library(iue-other_honly INTERFACE)
|
||||
|
||||
# define sources of target
|
||||
target_sources(iue-other_honly
|
||||
INTERFACE FILE_SET public_headers TYPE HEADERS BASE_DIRS ${PROJECT_SOURCE_DIR} FILES func.hpp func.detail.hpp)
|
||||
|
||||
# define installation step
|
||||
install(TARGETS iue-other_honly EXPORT iue-other-export
|
||||
FILE_SET public_headers DESTINATION "./")
|
||||
|
||||
# define test
|
||||
|
||||
if(BUILD_TESTING AND PROJECT_IS_TOP_LEVEL)
|
||||
add_executable(iue-other_honly.test func.test.cpp)
|
||||
target_link_libraries(iue-other_honly.test iue-other_honly)
|
||||
add_test(NAME iue-other_honly.test COMMAND iue-other_honly.test)
|
||||
endif()
|
||||
|
||||
# define CXX normal library
|
||||
|
||||
# define target & alias (for other projects consuming the "source-tree")
|
||||
add_library(iue-other_lib)
|
||||
|
||||
# define sources of target
|
||||
target_sources(iue-other_lib
|
||||
PRIVATE library.cpp
|
||||
PUBLIC FILE_SET public_headers TYPE HEADERS BASE_DIRS ${PROJECT_SOURCE_DIR} FILES library.hpp)
|
||||
|
||||
# define installation step
|
||||
install(TARGETS iue-other_lib EXPORT iue-other-export
|
||||
FILE_SET public_headers DESTINATION "./"
|
||||
LIBRARY DESTINATION "./")
|
||||
|
||||
# define test
|
||||
|
||||
if(BUILD_TESTING AND PROJECT_IS_TOP_LEVEL)
|
||||
add_executable(iue-other_lib.test library.test.cpp)
|
||||
target_link_libraries(iue-other_lib.test iue-other_lib)
|
||||
add_test(NAME iue-other_lib.test COMMAND iue-other_lib.test)
|
||||
endif()
|
||||
|
||||
# export targets for consuming cmake projects
|
||||
|
||||
# generate and install a .cmake file to allow dependend projects consuming the "install-tree" to import all targets
|
||||
install(EXPORT iue-other-export DESTINATION "iue-other" )
|
||||
|
||||
# allow dependend projects consuming the "build-tree" to use all targets
|
||||
export(EXPORT iue-other-export)
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace iue::other::detail {
|
||||
|
||||
inline int calc(int a) { return a * 2; }
|
||||
|
||||
} // namespace iue::other::detail
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "func.detail.hpp"
|
||||
|
||||
namespace iue::other {
|
||||
|
||||
inline int header_only(int a) { return detail::calc(a); }
|
||||
|
||||
} // namespace iue::other
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
#include "iue-other/func.hpp"
|
||||
|
||||
#include <cassert> // assert
|
||||
|
||||
int main() {
|
||||
assert(iue::other::header_only(5) == 10);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "library.hpp"
|
||||
|
||||
namespace iue::other {
|
||||
|
||||
int Widget::calc() const { return 5; }
|
||||
|
||||
int calc(const Widget& w) { return w.calc(); }
|
||||
|
||||
} // namespace iue::other
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace iue::other {
|
||||
|
||||
struct Widget {
|
||||
int calc() const;
|
||||
};
|
||||
|
||||
int calc(const Widget& w);
|
||||
|
||||
} // namespace iue::other
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "iue-other/library.hpp"
|
||||
|
||||
#include <cassert> // assert
|
||||
|
||||
int main() {
|
||||
|
||||
auto w = iue::other::Widget();
|
||||
assert(w.calc() == 5);
|
||||
assert(iue::other::calc(w) == 5);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user