diff --git a/CMakeLists.txt b/CMakeLists.txt index 530d431..223409f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,17 +10,14 @@ project(utempl set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_MODULE_STD 1) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(BOOST_INCLUDE_LIBRARIES "pfr") option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON) option(UTEMPL_MODULE OFF) -if(UTEMPL_MODULE) - add_compile_definitions(UTEMPL_EXPORT=export) -elseif() - add_compile_definitions(UTEMPL_EXPORT="") +if(UTEMPL_MODULE OR ENABLE_EXAMPLES OR ENABLE_TESTS) + set(CMAKE_CXX_MODULE_STD 1) endif() file(GLOB_RECURSE SOURCES "src/*.cpp") @@ -87,10 +84,20 @@ if(UTEMPL_MODULE) set(EXISTING_HEADERS) foreach(HPP_FILE ${HEADER_SOURCES}) - get_filename_component(FILE_NAME ${HPP_FILE} NAME_WE) + get_filename_component(REL_PATH ${HPP_FILE} DIRECTORY) + string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/src" "" REL_PATH ${REL_PATH}) + get_filename_component(FILE_NAME ${HPP_FILE} NAME_WE) + set(FILE_NAME "${REL_PATH}/${FILE_NAME}") set(HEADER_FILE "_headers/utempl/${FILE_NAME}.hpp") file(READ ${HPP_FILE} FILE_CONTENT) - file(WRITE ${HEADER_FILE} "${FILE_CONTENT}") + if(EXISTS ${HEADER_FILE}) + file(READ ${HEADER_FILE} HEADER_CONTENT) + if(NOT FILE_CONTENT STREQUAL HEADER_CONTENT) + file(WRITE ${HEADER_FILE} "${FILE_CONTENT}") + endif() + else() + file(WRITE ${HEADER_FILE} "${FILE_CONTENT}") + endif() list(APPEND EXISTING_HEADERS "${HEADER_FILE}") endforeach() file(GLOB HEADER_FILES "_headers/*.hpp") @@ -107,15 +114,29 @@ if(UTEMPL_MODULE) target_link_libraries(utempl PUBLIC fmt::fmt ${Boost_LIBRARIES}) endif() + target_include_directories(utempl PUBLIC + $ + $) + else() add_library(utempl INTERFACE) file(GLOB_RECURSE HEADER_SOURCES "src/*.hpp") set(EXISTING_HEADERS) foreach(CPP_FILE ${SOURCES} ${HEADER_SOURCES}) - get_filename_component(FILE_NAME ${CPP_FILE} NAME_WE) + get_filename_component(REL_PATH ${CPP_FILE} DIRECTORY) + string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/src" "" REL_PATH ${REL_PATH}) + get_filename_component(FILE_NAME ${CPP_FILE} NAME_WE) + set(FILE_NAME "${REL_PATH}/${FILE_NAME}") set(HEADER_FILE "_headers/utempl/${FILE_NAME}.hpp") file(READ ${CPP_FILE} FILE_CONTENT) - file(WRITE ${HEADER_FILE} "${FILE_CONTENT}") + if(EXISTS ${HEADER_FILE}) + file(READ ${HEADER_FILE} HEADER_CONTENT) + if(NOT FILE_CONTENT STREQUAL HEADER_CONTENT) + file(WRITE ${HEADER_FILE} "${FILE_CONTENT}") + endif() + else() + file(WRITE ${HEADER_FILE} "${FILE_CONTENT}") + endif() list(APPEND EXISTING_HEADERS "${HEADER_FILE}") endforeach() @@ -133,14 +154,14 @@ else() target_link_libraries(utempl INTERFACE fmt::fmt ${Boost_LIBRARIES}) endif() + target_include_directories(utempl INTERFACE + $ + $) endif() - add_library(utempl::utempl ALIAS utempl) target_compile_features(utempl INTERFACE cxx_std_23) -target_include_directories(utempl INTERFACE - $ - $) + @@ -177,12 +198,15 @@ install(FILES "${PROJECT_BINARY_DIR}/utemplConfig.cmake" "${PROJECT_BINARY_DIR}/utemplConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/utempl/cmake) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/headers/utempl DESTINATION include) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/_headers/utempl DESTINATION include) if(ENABLE_TESTS) - find_package(GTest REQUIRED) + CPMAddPackage( + NAME GTest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + ) enable_testing() file(GLOB SOURCES tests/* tests/*/* tests/*/*/*) add_executable(utempl_tests) diff --git a/src/loopholes/counter.cpp b/src/loopholes/counter.cpp index d40e017..0f2e325 100644 --- a/src/loopholes/counter.cpp +++ b/src/loopholes/counter.cpp @@ -8,11 +8,10 @@ export module utempl.loopholes.counter; export import utempl.loopholes.core; import std; - #else +#include #include -#include #endif @@ -34,13 +33,13 @@ consteval auto CounterHelper() -> std::size_t { }; // For incerement counter need a unique Ts... -export template ()> +UTEMPL_EXPORT template ()> consteval auto Counter(auto...) -> std::size_t { return R; }; // Without increment -export template ()> +UTEMPL_EXPORT template ()> consteval auto CountValue(auto...) -> std::size_t { return R; }; diff --git a/src/meta_info.cpp b/src/meta_info.cpp index 1fe243e..6ecc676 100644 --- a/src/meta_info.cpp +++ b/src/meta_info.cpp @@ -1,4 +1,5 @@ #pragma once +#include #ifdef UTEMPL_MODULE export module utempl.meta_info; import utempl.loopholes; @@ -6,7 +7,6 @@ import utempl.type_list; import std; #else #include -#include #include #endif diff --git a/src/module.hpp b/src/module.hpp new file mode 100644 index 0000000..4b340a6 --- /dev/null +++ b/src/module.hpp @@ -0,0 +1,20 @@ +#pragma once + +#ifdef UTEMPL_MODULE + +#define UTEMPL_EXPORT export + +#define UTEMPL_EXPORT_BEGIN export { +#define UTEMPL_EXPORT_END } +#define UTEMPL_GLOBAL_MODULE module; +#define UTEMPL_IMPORT(modules, headers) modules + +#else + +#define UTEMPL_EXPORT +#define UTEMPL_EXPORT_BEGIN +#define UTEMPL_EXPORT_END +#define UTEMPL_GLOBAL_MODULE +#define UTEMPL_IMPORT(modules, headers) headers + +#endif diff --git a/src/utempl.cpp b/src/utempl.cpp deleted file mode 100644 index ee0a829..0000000 --- a/src/utempl.cpp +++ /dev/null @@ -1,11 +0,0 @@ -export module utempl; -export import utempl.type_list; -export import utempl.tuple; -export import utempl.string; -export import utempl.loopholes; -export import utempl.attributes; -export import utempl.meta_info; -export import utempl.overloaded; -export import utempl.utils; -export import utempl.go_interface; -export import utempl.optional; diff --git a/src/utempl.hpp b/src/utempl.hpp index 9b75961..982b9a0 100644 --- a/src/utempl.hpp +++ b/src/utempl.hpp @@ -1,4 +1,5 @@ #pragma once + #ifdef UTEMPL_MODULE import utempl; #else