Skip to content

Commit ea2d975

Browse files
committed
Try to make it works with module
1 parent a42cbd5 commit ea2d975

9 files changed

Lines changed: 78 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/.cache
44
/compile_commands.json
5-
/build
5+
build/
66

77
# ignore emacs temp files
88
*~

CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
cmake_minimum_required(VERSION 3.28...4.2)
3+
cmake_minimum_required(VERSION 3.28...4.3)
44

55
# TODO: Set BEMAN_USE_MODULES if one of a particular set of compiler versions is being used
66

7-
if (BEMAN_USE_MODULES)
8-
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
9-
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")
7+
if(BEMAN_USE_MODULES)
8+
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
9+
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
10+
"d0edc3af-4c50-42ea-a356-e2862fe7a444"
11+
)
1012
endif()
1113

1214
project(
@@ -37,27 +39,38 @@ include(infra/cmake/beman-install-library.cmake)
3739
add_library(beman.transform_view INTERFACE)
3840
add_library(beman::transform_view ALIAS beman.transform_view)
3941

40-
target_sources(
41-
beman.transform_view
42-
PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
43-
)
42+
target_sources(beman.transform_view PUBLIC FILE_SET HEADERS BASE_DIRS include)
4443

4544
set_target_properties(
4645
beman.transform_view
4746
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON
4847
)
4948

5049
add_subdirectory(include/beman/transform_view)
51-
if (BEMAN_USE_MODULES)
50+
51+
if(BEMAN_USE_MODULES)
52+
add_library(beman.transform_view_module STATIC)
53+
add_library(beman::transform_view_module ALIAS beman.transform_view_module)
54+
55+
if(BEMAN_USE_STD_MODULES)
56+
target_compile_features(beman.transform_view_module PUBLIC cxx_std_23)
57+
# XXX set_target_properties(beman.transform_view_module PROPERTIES CXX_MODULE_STD ON)
58+
endif()
59+
60+
target_sources(
61+
beman.transform_view_module
62+
PUBLIC FILE_SET HEADERS BASE_DIRS include
63+
)
64+
5265
add_subdirectory(src/beman/transform_view)
5366
endif()
5467

55-
include(CTest)
68+
# NOT needed! include(CTest)
69+
enable_testing()
5670

57-
beman_install_library(beman.transform_view TARGETS beman.transform_view)
71+
beman_install_library(beman.transform_view TARGETS beman.transform_view beman.transform_view_module)
5872

5973
if(BEMAN_TRANSFORM_VIEW_BUILD_TESTS)
60-
enable_testing()
6174
add_subdirectory(tests/beman/transform_view)
6275
endif()
6376

examples/CMakeLists.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
cmake_minimum_required(VERSION 3.28...4.3)
3+
4+
# TODO: Set BEMAN_USE_MODULES if one of a particular set of compiler versions is being used
5+
6+
if(BEMAN_USE_MODULES)
7+
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
8+
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
9+
"d0edc3af-4c50-42ea-a356-e2862fe7a444"
10+
)
11+
endif()
12+
13+
project(beman.transform_view.example LANGUAGES CXX)
14+
15+
if(PROJECT_IS_TOP_LEVEL)
16+
find_package(beman.transform_view 0.1.0 EXACT REQUIRED)
17+
endif()
218

319
set(ALL_EXAMPLES transform_view_direct_usage)
420

@@ -10,8 +26,19 @@ foreach(example ${ALL_EXAMPLES})
1026
beman.transform_view.examples.${example}
1127
PRIVATE ${example}.cpp
1228
)
29+
if(BEMAN_USE_MODULES)
30+
target_compile_features(
31+
beman.transform_view.examples.${example}
32+
PUBLIC cxx_std_23
33+
)
34+
# XXX set_target_properties(beman.transform_view.examples.${example} PROPERTIES CXX_MODULE_STD ON)
35+
endif()
1336
target_link_libraries(
1437
beman.transform_view.examples.${example}
15-
PRIVATE beman::transform_view
38+
PRIVATE beman::transform_view_module
39+
)
40+
add_test(
41+
NAME beman.transform_view.examples.${example}
42+
COMMAND beman.transform_view.examples.${example}
1643
)
1744
endforeach()

examples/transform_view_direct_usage.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
#include <beman/transform_view/transform_view.hpp>
4-
53
#include <iostream>
4+
#include <ranges>
5+
#include <string>
6+
7+
#ifdef BEMAN_HAS_MODULES
8+
import beman.transform_view;
9+
#else
10+
#include <beman/transform_view/transform_view.hpp>
11+
#endif
612

713
namespace tv26 = beman::transform_view;
814

include/beman/transform_view/transform_view.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef BEMAN_TRANSFORM_VIEW_HPP
44
#define BEMAN_TRANSFORM_VIEW_HPP
55

6-
#ifndef BEMAN_HAS_MODULES
6+
#ifndef BEMAN_HAS_STD_MODULES
77
#include <functional>
88
#include <iterator>
99
#include <optional>
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
add_library(beman.transform_view.module STATIC)
4-
add_library(beman::transform_view.module ALIAS beman.transform_view.module)
5-
63
target_sources(
7-
beman.transform_view.module
4+
beman.transform_view_module
85
PUBLIC FILE_SET CXX_MODULES FILES transform_view.cppm
96
)
107

11-
target_include_directories(
12-
beman.transform_view.module
13-
PUBLIC
14-
${PROJECT_SOURCE_DIR}/include
15-
)
16-
17-
target_compile_definitions(
18-
beman.transform_view.module
19-
PUBLIC BEMAN_HAS_MODULES)
20-
21-
set_target_properties(
22-
beman.transform_view.module
23-
PROPERTIES CXX_MODULE_STD ON
24-
)
8+
target_compile_definitions(beman.transform_view_module PUBLIC BEMAN_HAS_MODULES)
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
module;
22

3-
export module beman.transform_view;
4-
3+
#ifndef BEMAN_HAS_STD_MODULES
4+
#include <functional>
5+
#include <iterator>
6+
#include <optional>
7+
#include <ranges>
8+
#else
59
import std;
10+
#endif
11+
12+
export module beman.transform_view;
613

714
extern "C++" {
815
export {
9-
#include <beman/transform_view/transform_view.hpp>
16+
#include <beman/transform_view/transform_view.hpp>
1017
}
1118
}

tests/beman/transform_view/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
find_package(GTest REQUIRED)
3+
find_package(GTest CONFIG REQUIRED)
44

55
add_executable(beman.transform_view.tests.transform_view)
66
target_sources(
@@ -19,7 +19,7 @@ target_sources(
1919
)
2020
target_link_libraries(
2121
beman.transform_view.tests.module_smoke_test
22-
PRIVATE beman::transform_view.module
22+
PRIVATE beman::transform_view_module
2323
)
2424

2525
include(GoogleTest)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import beman.transform_view;
22

3-
int main() {
4-
}
3+
int main() {}

0 commit comments

Comments
 (0)