Skip to content

module support for cpp2 files #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
adam-ce opened this issue Jul 18, 2024 · 3 comments
Open

module support for cpp2 files #162

adam-ce opened this issue Jul 18, 2024 · 3 comments

Comments

@adam-ce
Copy link

adam-ce commented Jul 18, 2024

if i understand correctly, this is still something for the future, but to my understanding it's not possible to make libraries with cpp2 files.

e.g., i followed a module example:
cmake file:

cmake_minimum_required(VERSION 3.30)

project(cpp2test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

FetchContent_Declare(
    cppfront
    GIT_REPOSITORY https://github.com/modern-cmake/cppfront.git
    GIT_TAG main  # or an actual git SHA if you don't like to live dangerously
)

FetchContent_MakeAvailable(cppfront)


add_library(foo)
# Add the module file to the library
target_sources(foo
  PUBLIC
    FILE_SET CXX_MODULES FILES
      Shape.cpp
)
set_target_properties(foo PROPERTIES LINKER_LANGUAGE CXX)
# Create an executable
add_executable(cpp2test main.cpp2)
# Link to the library foo
target_link_libraries(cpp2test PUBLIC foo)

with Shape.cpp

export module Shape;

export int add(int a, int b) {
    return a + b + 42;
}

and main.cpp2

import Shape;

main : () = {
           std::cout << "Hello, world! " << add(1, 2) << "\n";
}

this compiles and runs. but i get errors as soon as i rename Shape.cpp to Shape.cpp2:

[cmake] CMake Error in CMakeLists.txt:
[cmake]   Target "foo" has source file
[cmake] 
[cmake]     /home/madam/Documents/cpp2test/Shape.cpp2
[cmake] 
[cmake]   in a "FILE_SET TYPE CXX_MODULES" but it is not scheduled for compilation.

i already added set_target_properties(foo PROPERTIES LINKER_LANGUAGE CXX), but it appears that that's not enough.

@adam-ce
Copy link
Author

adam-ce commented Jul 18, 2024

i just saw, that #145 appears to fix it, but is not merged and the corresponding bug is closed.

@alexreinking
Copy link
Contributor

@adam-ce -- I meant to merge that, but I got distracted by the various CI issues and then my day job got busier. Do you have any bandwidth to help out with CI?

@adam-ce
Copy link
Author

adam-ce commented Jul 22, 2024

you're thinking the issue with macos?

i'm not a CI expert at all and i'm not really familiar with mac. in my own setup i ended up deleting the CI tests on Macos because they were failing too often (timeouts as well, but i was starting an android simulator).

besides that, no. i don't have available bandwidth, not even for my own pet project :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants