@@ -242,12 +242,6 @@ private static void handleCleanOutput(ByteCodeTranslator b, File[] sources, File
242242 }
243243 File xmlvm = new File (srcRoot , "xmlvm.h" );
244244 copy (ByteCodeTranslator .class .getResourceAsStream ("/xmlvm.h" ), new FileOutputStream (xmlvm ));
245- File cn1GlobalsC = new File (srcRoot , "cn1_globals.c" );
246- copy (ByteCodeTranslator .class .getResourceAsStream ("/cn1_globals.m" ), new FileOutputStream (cn1GlobalsC ));
247- File nativeMethods = new File (srcRoot , "nativeMethods.c" );
248- copy (ByteCodeTranslator .class .getResourceAsStream ("/nativeMethods.m" ), new FileOutputStream (nativeMethods ));
249- File javaIoFileC = new File (srcRoot , "java_io_File.c" );
250- copy (ByteCodeTranslator .class .getResourceAsStream ("/java_io_File.m" ), new FileOutputStream (javaIoFileC ));
251245
252246 Parser .writeOutput (srcRoot );
253247
@@ -563,20 +557,40 @@ public boolean accept(File pathname, String string) {
563557
564558 private static void writeCmakeProject (File projectRoot , File srcRoot , String appName ) throws IOException {
565559 File cmakeLists = new File (projectRoot , "CMakeLists.txt" );
560+ File translatorSourcesRoot = resolveTranslatorSourcesRoot ();
566561 FileWriter writer = new FileWriter (cmakeLists );
567562 try {
568563 writer .append ("cmake_minimum_required(VERSION 3.10)\n " );
569564 writer .append ("project(" ).append (appName ).append (" LANGUAGES C OBJC)\n " );
570565 writer .append ("enable_language(OBJC OPTIONAL)\n " );
571566 writer .append ("set(CMAKE_C_STANDARD 99)\n " );
572- writer .append ("file(GLOB TRANSLATOR_SOURCES \" " ).append (srcRoot .getName ()).append ("/*.c\" \" " ).append (srcRoot .getName ()).append ("/*.m\" )\n " );
573- writer .append ("file(GLOB TRANSLATOR_HEADERS \" " ).append (srcRoot .getName ()).append ("/*.h\" )\n " );
567+ writer .append ("set(CN1_TRANSLATOR_SOURCE_ROOT \" " )
568+ .append (escapeCmakePath (translatorSourcesRoot .getAbsolutePath ()))
569+ .append ("\" )\n " );
570+ writer .append ("file(GLOB TRANSLATOR_SOURCES \" " ).append (srcRoot .getName ()).append ("/*.c\" \" " )
571+ .append (srcRoot .getName ()).append ("/*.m\" \" ${CN1_TRANSLATOR_SOURCE_ROOT}/*.c\" \" " )
572+ .append ("${CN1_TRANSLATOR_SOURCE_ROOT}/*.m\" )\n " );
573+ writer .append ("file(GLOB TRANSLATOR_HEADERS \" " ).append (srcRoot .getName ()).append ("/*.h\" \" " )
574+ .append ("${CN1_TRANSLATOR_SOURCE_ROOT}/*.h\" )\n " );
574575 writer .append ("add_library(${PROJECT_NAME} ${TRANSLATOR_SOURCES} ${TRANSLATOR_HEADERS})\n " );
575- writer .append ("target_include_directories(${PROJECT_NAME} PUBLIC " ).append (srcRoot .getName ()).append (")\n " );
576+ writer .append ("target_include_directories(${PROJECT_NAME} PUBLIC " ).append (srcRoot .getName ())
577+ .append (" ${CN1_TRANSLATOR_SOURCE_ROOT})\n " );
576578 } finally {
577579 writer .close ();
578580 }
579581 }
582+
583+ private static File resolveTranslatorSourcesRoot () {
584+ try {
585+ return new File (ByteCodeTranslator .class .getResource ("/cn1_globals.h" ).toURI ()).getParentFile ();
586+ } catch (Exception e ) {
587+ throw new RuntimeException ("Failed to resolve ByteCodeTranslator source root" , e );
588+ }
589+ }
590+
591+ private static String escapeCmakePath (String path ) {
592+ return path .replace ("\\ " , "\\ \\ " );
593+ }
580594
581595 private static String getFileType (String s ) {
582596 if (s .endsWith (".framework" )) {
0 commit comments