Skip to content
Open
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
64 changes: 64 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: windows

on:
pull_request:
push:
branches:
- master
- develop
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
# TODO: platform: [Win32, x64]
platform: [x64]
cxx_standard: [20, 23]
# NO! shared: ["", -DBUILD_SHARED_LIBS=ON]
build_type: [Release]

steps:
- uses: actions/checkout@v3

- name: Create Build Environment
run: |
pip install cmake ninja
ninja --version
cmake --version
cmake -E make_directory ${{runner.workspace}}/build

- name: Configure
# Use a bash shell for $GITHUB_WORKSPACE.
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
cmake -G Ninja -DCMAKE_SYSTEM_PROCESSOR=${{matrix.platform}} \
-DCMAKE_TOOLCHAIN_FILE=cmake/Windows.MSVC.toolchain.cmake \
-DCMAKE_CXX_STANDARD=${{matrix.cxx_standard}} \
${{matrix.shared}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
$GITHUB_WORKSPACE

- name: Build
working-directory: ${{runner.workspace}}/build
run: |
$threads = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors
cmake --build . --config ${{matrix.build_type}} --parallel $threads

- name: Test
working-directory: ${{runner.workspace}}/build
run: ctest -C ${{matrix.build_type}} --timeout 60
env:
CTEST_OUTPUT_ON_FAILURE: True

- name: Install
working-directory: ${{runner.workspace}}/build
run: |
cmake --install . --config ${{matrix.build_type}}
122 changes: 88 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,104 +1,148 @@
cmake_minimum_required(VERSION 3.15)
cmake_policy(VERSION 3.15)
cmake_minimum_required(VERSION 3.28)

#---------------------------------------------------------------------------------------
# Compiler config
#---------------------------------------------------------------------------------------
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(Modules
VERSION 0.0.0
VERSION 0.0.1
LANGUAGES CXX)

set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "" FORCE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_cmake")

include(GnuInstallDirs)
include(GNUInstallDirs)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
message(FATAL_ERROR "CMAKE_CXX_SCAN_FOR_MODULES not supported yet")
else()
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
endif()

add_compile_options(/experimental:module) # needed for STL modules
if(WIN32)
add_compile_options(/experimental:module) # needed for STL modules
endif()

if(PROJECT_IS_TOP_LEVEL)
option(TEST_INSTALLED_VERSION "Test exported cmake config set" NO)
enable_testing()
endif()

if(NOT TEST_INSTALLED_VERSION)

#
# Single file module
#
add_executable(SingleFileModule)
target_sources(SingleFileModule
PRIVATE
PRIVATE
SingleFileModule/main.cpp
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES FILES
SingleFileModule/mod.ixx
)

set_property(TARGET SingleFileModule PROPERTY CXX_STANDARD 20)
add_test(NAME SingleFileModule COMMAND SingleFileModule)

#
# Two files module
#
add_executable(TwoFileModule)
target_sources(TwoFileModule
PRIVATE
PRIVATE
TwoFileModule/main.cpp
TwoFileModule/mod.ixx
TwoFileModule/mod.cpp
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES FILES
TwoFileModule/mod.ixx
)

set_property(TARGET TwoFileModule PROPERTY CXX_STANDARD 20)
add_test(NAME TwoFileModule COMMAND TwoFileModule)

#
# Partition module
#

add_executable(PartitionModule)
target_sources(PartitionModule
PRIVATE
PRIVATE
PartitionModule/main.cpp
PartitionModule/mod.func.cpp
PartitionModule/mod.class.cpp
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES FILES
PartitionModule/mod.ixx
PartitionModule/mod.class.ixx PartitionModule/mod.class.cpp
PartitionModule/mod.func.ixx PartitionModule/mod.func.cpp
PartitionModule/mod.class.ixx
PartitionModule/mod.func.ixx
)

set_property(TARGET PartitionModule PROPERTY CXX_STANDARD 20)
add_test(NAME PartitionModule COMMAND PartitionModule)

#
# Conflicts - Two modules including same headers (iostream)
#

add_executable(Conflicts)
target_sources(Conflicts
PRIVATE
PRIVATE
Conflicts/main.cpp
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES FILES
Conflicts/mod.ixx
Conflicts/mod2.ixx
)

set_property(TARGET Conflicts PROPERTY CXX_STANDARD 20)
add_test(NAME Conflicts COMMAND Conflicts)

#
# SubModules
#

add_executable(SubModules)
target_sources(SubModules
PRIVATE
PRIVATE
SubModules/main.cpp

SubModules/mod/sub1/mod.sub1.class.cpp # Partitions od mod.sub1 module/submodule
SubModules/mod/sub1/mod.sub1.func.cpp #
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES FILES
SubModules/mod/mod.ixx # PMI for module mod
SubModules/mod/sub1/mod.sub1.ixx # PMI for submodule mod.sub1
SubModules/mod/sub1/mod.sub1.class.ixx SubModules/mod/sub1/mod.sub1.class.cpp # Partitions od mod.sub1 module/submodule
SubModules/mod/sub1/mod.sub1.func.ixx SubModules/mod/sub1/mod.sub1.func.cpp #
SubModules/mod/sub1/mod.sub1.class.ixx
SubModules/mod/sub1/mod.sub1.func.ixx
SubModules/mod/sub2/mod.sub2.ixx # PMI for submodule mod.sub2
)

set_property(TARGET SubModules PROPERTY CXX_STANDARD 20)
#set_property(TARGET SubModules PROPERTY FOLDER "Submodule")
add_test(NAME SubModules COMMAND SubModules)

#
# Module as dll
#

add_library(DllModule SHARED)
target_sources(DllModule
PRIVATE
PRIVATE
DllModule/mod.class.cpp
DllModule/mod.func.cpp
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES FILES
DllModule/mod.ixx
DllModule/mod.class.ixx
DllModule/mod.func.ixx
DllModule/mod.func.ixx
)

set_property(TARGET DllModule PROPERTY CXX_STANDARD 20)
Expand All @@ -112,7 +156,7 @@ set_property(TARGET DllModule PROPERTY FOLDER "Dll")

add_executable(DllModuleApp)
target_sources(DllModuleApp
PRIVATE
PRIVATE
DllModule/main.cpp
)

Expand All @@ -129,17 +173,15 @@ add_library(ExternalDllModule SHARED)
set(ixx_files
ExternalDllModule/mod.ixx
ExternalDllModule/mod.class.ixx
ExternalDllModule/mod.func.ixx
ExternalDllModule/mod.func.ixx
)
target_sources(ExternalDllModule
PRIVATE
PRIVATE
ExternalDllModule/mod.class.cpp
ExternalDllModule/mod.func.cpp
$<BUILD_INTERFACE:${ixx_files}>
INTERFACE
$<INSTALL_INTERFACE:include/mod.ixx>
$<INSTALL_INTERFACE:include/mod.class.ixx>
$<INSTALL_INTERFACE:include/mod.func.ixx>
PUBLIC
FILE_SET cxx_modules_dll TYPE CXX_MODULES FILES
${ixx_files}
)
set_property(TARGET ExternalDllModule PROPERTY CXX_STANDARD 20)
target_compile_definitions(ExternalDllModule
Expand All @@ -148,27 +190,39 @@ target_compile_definitions(ExternalDllModule
INTERFACE
"DLLMODULE_EXPORT=__declspec(dllimport)"
)
install(TARGETS ExternalDllModule EXPORT ExternalDllModule_export)
install(FILES ${ixx_files} TYPE INCLUDE) # there is no standard destination now so we pick include
install(EXPORT ExternalDllModule_export NAMESPACE ExternalDllModule:: DESTINATION lib/cmake/ExternalDllModule FILE ExternalDllModuleConfig.cmake)
set_property(TARGET ExternalDllModule PROPERTY FOLDER "Dll")

#
# install the ExternalDllModule
#

install(TARGETS ExternalDllModule EXPORT ExternalDllModule_export
FILE_SET cxx_modules_dll DESTINATION lib/cxx/miu
)
#XXX install(FILES ${ixx_files} TYPE INCLUDE) # there is no standard destination now so we pick include
install(EXPORT ExternalDllModule_export NAMESPACE ExternalDllModule::
DESTINATION lib/cmake/ExternalDllModule FILE ExternalDllModuleConfig.cmake
)

endif() # NOT TEST_INSTALLED_VERSION

#
# 3rd party dll module consumption
# You need to install the ExternalDllModule first
#

find_package(ExternalDllModule QUIET)
if(ExternalDllModule_FOUND)
if(NOT TARGET ExternalDllModule)
find_package(ExternalDllModule REQUIRED)

add_executable(ExternalDllModuleApp)
target_sources(ExternalDllModuleApp
PRIVATE
PRIVATE
DllModule/main.cpp
)

target_link_libraries(ExternalDllModuleApp PRIVATE ExternalDllModule::ExternalDllModule)
set_property(TARGET ExternalDllModuleApp PROPERTY CXX_STANDARD 20)
set_property(TARGET ExternalDllModuleApp PROPERTY FOLDER "Dll")
add_test(NAME ExternalDllModuleApp COMMAND ExternalDllModuleApp)
endif()

SET_PROPERTY(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT SingleFileModule)
SET_PROPERTY(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT SingleFileModule)
58 changes: 58 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": 7,
"cmakeMinimumRequired": {
"major": 3,
"minor": 27,
"patch": 0
},
"include": [
"CMakeReleasePresets.json"
],
"configurePresets": [
{
"name": "ninja-multi",
"inherits": "Release",
"displayName": "Ninja Multi-Config",
"description": "Build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config"
},
{
"name": "windows-only",
"inherits": "Release",
"displayName": "Windows-only configuration",
"description": "This build is only available on Windows",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
"workflowPresets": [
{
"name": "Release",
"steps": [
{
"type": "configure",
"name": "Release"
},
{
"type": "build",
"name": "Release"
},
{
"type": "test",
"name": "Release"
},
{
"type": "build",
"name": "install"
},
{
"type": "package",
"name": "Release"
}
]
}
]
}
Loading