diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1fc7ca7..6af691b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -134,7 +134,13 @@ jobs: archive="ptfkit-native-${version}.tar.gz" tar --sort=name --mtime="UTC 1970-01-01" --owner=0 --group=0 --numeric-owner \ --transform="s,^targets/ptfkit-native,ptfkit-native-${version}," \ - -czf "$archive" targets/ptfkit-native + -czf "$archive" \ + targets/ptfkit-native/CMakeLists.txt \ + targets/ptfkit-native/LICENSE \ + targets/ptfkit-native/README.md \ + targets/ptfkit-native/cmake \ + targets/ptfkit-native/cpp \ + targets/ptfkit-native/include sha256sum "$archive" > "$archive.sha256" echo "archive=$archive" >> "$GITHUB_ENV" - name: Attest native archive provenance diff --git a/codegen/src/output/mod.rs b/codegen/src/output/mod.rs index 546d2e2..9bd9735 100644 --- a/codegen/src/output/mod.rs +++ b/codegen/src/output/mod.rs @@ -108,13 +108,6 @@ layout!( C_HEADER, Formatter::Cpp ); -layout!( - NATIVE_CPP_CMAKE, - "targets/ptfkit-native/cmake", - "targets/ptfkit-native/cmake", - PYTHON_HEADER, - Formatter::None -); layout!( NATIVE_C_TEST, "targets/ptfkit-native/tests/c", @@ -130,7 +123,7 @@ layout!( Formatter::Cpp ); -pub(crate) const LAYOUTS: [&Layout; 13] = [ +pub(crate) const LAYOUTS: [&Layout; 12] = [ &CATALOG, &REFERENCE_C, &REFERENCE_CPP, @@ -141,7 +134,6 @@ pub(crate) const LAYOUTS: [&Layout; 13] = [ &PYTHON_TEST, &NATIVE_C, &NATIVE_CPP_MODULE, - &NATIVE_CPP_CMAKE, &NATIVE_C_TEST, &NATIVE_CPP_TEST, ]; diff --git a/codegen/src/targets/mod.rs b/codegen/src/targets/mod.rs index b0d1afc..ebdb804 100644 --- a/codegen/src/targets/mod.rs +++ b/codegen/src/targets/mod.rs @@ -52,7 +52,6 @@ pub(crate) fn run(root: &Path, entries: Vec) -> Result<()> { Output::new(&output::PYTHON_TEST, python.tests), Output::new(&output::NATIVE_C, native.c_headers), Output::new(&output::NATIVE_CPP_MODULE, native.cpp_modules), - Output::new(&output::NATIVE_CPP_CMAKE, native.cpp_cmake), Output::new(&output::NATIVE_C_TEST, native.c_tests), Output::new(&output::NATIVE_CPP_TEST, native.cpp_tests), ], diff --git a/codegen/src/targets/native.rs b/codegen/src/targets/native.rs index bb59a0c..d25856c 100644 --- a/codegen/src/targets/native.rs +++ b/codegen/src/targets/native.rs @@ -16,12 +16,10 @@ use crate::{ }; pub(super) const HEADER: &str = "/* @generated by ptfkit-codegen; DO NOT EDIT. */\n"; -pub(super) const CMAKE_HEADER: &str = "# @generated by ptfkit-codegen; DO NOT EDIT.\n"; pub(super) struct OutputFiles { pub(super) c_headers: Vec, pub(super) cpp_modules: Vec, - pub(super) cpp_cmake: Vec, pub(super) c_tests: Vec, pub(super) cpp_tests: Vec, } @@ -57,18 +55,9 @@ pub(super) fn render(functions: &[CompiledFunction]) -> Result { cpp_modules.push(file("ptfkit.cppm", root_module.into_string())); - let mut cmake = Writer::new(); - cmake.write(format_args!("{CMAKE_HEADER}\nset(PTFKIT_CPP_MODULES\n")); - cmake.indented(|writer| { - for path in &module_paths { - writer.line(format_args!("\"${{CMAKE_CURRENT_LIST_DIR}}/../{path}\"")); - } - }); - cmake.line(")"); Ok(OutputFiles { c_headers, cpp_modules, - cpp_cmake: vec![file("ptfkitModules.cmake", cmake.into_string())], c_tests, cpp_tests, }) diff --git a/targets/ptfkit-native/CMakeLists.txt b/targets/ptfkit-native/CMakeLists.txt index b1b6b5c..0b9950e 100644 --- a/targets/ptfkit-native/CMakeLists.txt +++ b/targets/ptfkit-native/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.21) include(cmake/ptfkitVersion.cmake) -project(ptfkit VERSION ${PTFKIT_VERSION} LANGUAGES C CXX) +project(ptfkit VERSION ${PTFKIT_VERSION} LANGUAGES C) include(CMakePackageConfigHelpers) include(CMakeDependentOption) @@ -11,7 +11,12 @@ add_library(ptfkit_c INTERFACE) add_library(ptfkit::c ALIAS ptfkit_c) set_target_properties(ptfkit_c PROPERTIES EXPORT_NAME c) target_compile_features(ptfkit_c INTERFACE c_std_11) -target_compile_definitions(ptfkit_c INTERFACE PTFKIT_VERSION=\"${PROJECT_VERSION}\") +target_compile_definitions(ptfkit_c INTERFACE + PTFKIT_VERSION=\"${PROJECT_VERSION}\" +) +if(UNIX) + target_link_libraries(ptfkit_c INTERFACE m) +endif() target_include_directories(ptfkit_c INTERFACE $ $ @@ -26,21 +31,9 @@ cmake_dependent_option( ) if(PTFKIT_BUILD_CPP_MODULES) - include(cmake/ptfkitModules.cmake) - add_library(ptfkit_cpp) - add_library(ptfkit::cpp ALIAS ptfkit_cpp) - set_target_properties(ptfkit_cpp PROPERTIES - EXPORT_NAME cpp CXX_SCAN_FOR_MODULES ON - ) - target_compile_features(ptfkit_cpp PUBLIC cxx_std_20) - target_compile_definitions(ptfkit_cpp PUBLIC PTFKIT_VERSION=\"${PROJECT_VERSION}\") - target_compile_options(ptfkit_cpp PUBLIC - $<$:-fmodules-ts> - ) - target_sources(ptfkit_cpp PUBLIC - FILE_SET CXX_MODULES - FILES ${PTFKIT_CPP_MODULES} - ) + enable_language(CXX) + add_subdirectory(cpp) + set(INSTALL_EXPORT_ARGS CXX_MODULES_DIRECTORY cxx-modules) endif() install(TARGETS ptfkit_c EXPORT ptfkitTargets) @@ -52,17 +45,11 @@ install( FILES README.md LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR} ) -if(PTFKIT_BUILD_CPP_MODULES) - install( - TARGETS ptfkit_cpp - EXPORT ptfkitTargets - FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_LIBDIR}/ptfkit/modules - ) -endif() install( EXPORT ptfkitTargets NAMESPACE ptfkit:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ptfkit + ${INSTALL_EXPORT_ARGS} ) configure_package_config_file( cmake/ptfkitConfig.cmake.in diff --git a/targets/ptfkit-native/cmake/ptfkitModules.cmake b/targets/ptfkit-native/cmake/ptfkitModules.cmake deleted file mode 100644 index dfd6613..0000000 --- a/targets/ptfkit-native/cmake/ptfkitModules.cmake +++ /dev/null @@ -1,26 +0,0 @@ -# @generated by ptfkit-codegen; DO NOT EDIT. - -set(PTFKIT_CPP_MODULES - "${CMAKE_CURRENT_LIST_DIR}/../cpp/ptfkit.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/ahuja1984.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/aimrun2009.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/beniaich2023.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/chakraborty2011.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/cosby1984.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/dharumarajan2019.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/ferrerjulia2004.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/hodnett2002.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/jabro1992.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/li2007.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/mayr1999.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/oosterveld1980.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/pidgeon1972.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/puckett1985.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/rawls1982.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/saxton2006.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/tiwary2014.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/varallyai1982.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/vereecken1989.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/wang2012.cppm" - "${CMAKE_CURRENT_LIST_DIR}/../cpp/weber2020.cppm" -) diff --git a/targets/ptfkit-native/cpp/CMakeLists.txt b/targets/ptfkit-native/cpp/CMakeLists.txt new file mode 100644 index 0000000..c91cbdd --- /dev/null +++ b/targets/ptfkit-native/cpp/CMakeLists.txt @@ -0,0 +1,22 @@ +add_library(ptfkit_cpp) +add_library(ptfkit::cpp ALIAS ptfkit_cpp) +set_target_properties(ptfkit_cpp PROPERTIES + EXPORT_NAME cpp CXX_SCAN_FOR_MODULES ON +) +target_compile_features(ptfkit_cpp PUBLIC cxx_std_20) +target_compile_definitions(ptfkit_cpp PUBLIC + PTFKIT_VERSION=\"${PROJECT_VERSION}\" +) +target_compile_options(ptfkit_cpp PUBLIC + $<$:-fmodules-ts> +) +file(GLOB_RECURSE PTFKIT_CPP_MODULES CONFIGURE_DEPENDS *.cppm) +target_sources(ptfkit_cpp PUBLIC + FILE_SET CXX_MODULES + FILES ${PTFKIT_CPP_MODULES} +) +install( + TARGETS ptfkit_cpp + EXPORT ptfkitTargets + FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_LIBDIR}/ptfkit/modules +) diff --git a/targets/ptfkit-native/tests/CMakeLists.txt b/targets/ptfkit-native/tests/CMakeLists.txt index 98d51bd..a40de52 100644 --- a/targets/ptfkit-native/tests/CMakeLists.txt +++ b/targets/ptfkit-native/tests/CMakeLists.txt @@ -24,7 +24,13 @@ endfunction() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(c) -add_subdirectory(cpp_fallback) + +include(CheckLanguage) +check_language(CXX) +if(CMAKE_CXX_COMPILER) + enable_language(CXX) + add_subdirectory(cpp_fallback) +endif() if(PTFKIT_BUILD_CPP_MODULES) add_subdirectory(cpp)