Skip to content
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

Demonstrate how to configure a cpp-library with multiple source sets #974

Open
jamie-walker opened this issue Jan 15, 2019 · 14 comments
Open
Labels

Comments

@jamie-walker
Copy link

The use-case we have for this is a (JNI) shared library where different source files use different compiler options.

This is supported in the old software model by declaring multiple source sets. I'm not sure how to do this using the new cpp-library plugin.

@lacasseio
Copy link
Contributor

Thanks for this demonstration issue. Its certainly possible, but requires quite a bit of configuration. We will start with samples and see what we can improve to make it simpler for the users.

@big-guy
Copy link
Member

big-guy commented Jan 17, 2019

@jamie-walker do you have an example handy for what you're trying to do? Why do some of the files need different compiler arguments?

@jamie-walker
Copy link
Author

@big-guy: we target different cpu instruction sets for some of the source files: e.g. SSE or AVX. I could probably make different libraries with the different optimisation levels as a workaround. However, there is quite a bit of shared code so this would involve splitting what is currently quite a tiny library into three: a header only lib for the shared bits, an SSE lib and an AVX lib. I could see this also being useful if we had some code that required e.g. fast-math but other parts of the same library where we didn't want any optimisations that changed the result of the calculations.

@zosrothko
Copy link

May be it is not related to this issue, but I have a requirment to compile C sources & C++ source located in the same directory as

	library {
		baseName = "PocoFoundation"
		source {
			def cppTree = project.fileTree('src')
			cppTree.include '**/*.c' 
			cppTree.include '**/*.cc' 
			cppTree.include '**/*.cpp' 
...

The output.txt is showing that only *.cc and *.cpp sources are compiled, but no one *.c sources:
output.txt

Thus I am wondering how to configure the source set to include C sources?

@lacasseio
Copy link
Contributor

@zosrothko The sample you are providing is only configuring a new FileTree without linking it in any way with the source property. You could add from(cppTree) to add the FileTree to the source FileCollection. However, this will have the C++ compiler compile the C source file. It may not be what you are expecting. The demonstration for this issue is to show how to compile C source file with the C compiler.

@zosrothko
Copy link

@lacasseio My comment was just exposing the beginning of the sourcedefinition. Here the full snippet

library {
	baseName = "PocoFoundation"
	source {
		def cppTree = project.fileTree('src')
		cppTree.include '**/*.c' 
		cppTree.include '**/*.cc' 
		cppTree.include '**/*.cpp' 
		cppTree.exclude 'File_*.cpp'	
		cppTree.exclude 'ByteOrder.cpp'
		cppTree.exclude 'String.cpp'
		cppTree.exclude 'SignalHandler.cpp'
		cppTree.exclude 'Environment_*.cpp'
		cppTree.exclude 'FPEnvironment_*.cpp'
		cppTree.exclude 'Timezone_*.cpp'
		cppTree.exclude 'DirectoryIterator_*.cpp'
		cppTree.exclude 'File_*.cpp'
		cppTree.exclude 'FileStream_*.cpp'
		cppTree.exclude 'Path_*.cpp'
		cppTree.exclude 'LogFile_*.cpp'
		cppTree.exclude 'NamedEvent_*.cpp'
		cppTree.exclude 'NamedMutex_*.cpp'
		cppTree.exclude 'PipeImpl_*.cpp'
		cppTree.exclude 'Process_*.cpp'
		cppTree.exclude 'SharedMemory_*.cpp'
		cppTree.exclude 'SharedLibrary_*.cpp'
		cppTree.exclude 'Event_*.cpp'
		cppTree.exclude 'Mutex_*.cpp'
		cppTree.exclude 'RWLock_*.cpp'
		cppTree.exclude 'Semaphore_*.cpp'
		cppTree.exclude 'Thread_*.cpp'
		cppTree.exclude 'EventLogChannel.cpp'
		cppTree.exclude 'UnWindows.cpp'
		cppTree.exclude 'WindowsConsoleChannel.cpp'
		cppTree.exclude 'AndroidLogChannel.cpp'
		cppTree.exclude 'SyslogChannel.cpp'
							cppTree.include 'EventLogChannel.cpp'
							cppTree.include 'UnWindows.cpp'
							cppTree.include 'WindowsConsoleChannel.cpp'
		from cppTree
	}
	publicHeaders {
		from	file('include')
	}
	binaries.configureEach {
		def compileTask = compileTask.get()
		def linkTask = linkTask.get()
	    if (toolChain instanceof VisualCpp) {
			compileTask.compilerArgs.add('/DFoundation_EXPORTS')
			
			linkTask.linkerArgs.add("ws2_32.lib")
			linkTask.linkerArgs.add("iphlpapi.lib")
		}
	}
}

And please, take a look to the output.txt above. It is showing the proper compilation of *.cc and *.cpp files but none of *.c

Below the list of the src directory

 Répertoire de Z:\git\poco-1.9.1-gragle-new-plugins\Foundation\src

19/01/2019  18:21    <DIR>          .
19/01/2019  18:21    <DIR>          ..
30/09/2018  18:42               637 AbstractObserver.cpp
30/09/2018  18:42             1 937 ActiveDispatcher.cpp
30/09/2018  18:42             5 414 adler32.c
30/09/2018  18:42             3 468 ArchiveStrategy.cpp
30/09/2018  18:42             6 778 Ascii.cpp
30/09/2018  18:42             3 277 ASCIIEncoding.cpp
30/09/2018  18:42             3 026 AsyncChannel.cpp
30/09/2018  18:42             3 677 AtomicCounter.cpp
30/09/2018  18:42               475 AtomicFlag.cpp
30/09/2018  18:42             3 951 Base32Decoder.cpp
30/09/2018  18:42             5 287 Base32Encoder.cpp
30/09/2018  18:42             3 994 Base64Decoder.cpp
30/09/2018  18:42             4 068 Base64Encoder.cpp
30/09/2018  18:42            27 953 bignum-dtoa.cc
30/09/2018  18:42             4 384 bignum-dtoa.h
30/09/2018  18:42            23 841 bignum.cc
30/09/2018  18:42             5 658 bignum.h
30/09/2018  18:42             5 498 BinaryReader.cpp
30/09/2018  18:42             6 809 BinaryWriter.cpp
30/09/2018  18:42             2 307 Bugcheck.cpp
30/09/2018  18:42               271 ByteOrder.cpp
30/09/2018  18:42             8 665 cached-powers.cc
30/09/2018  18:42             3 091 cached-powers.h
30/09/2018  18:42               694 Channel.cpp
30/09/2018  18:42               930 Checksum.cpp
30/09/2018  18:42             4 844 Clock.cpp
30/09/2018  18:42             2 785 compress.c
30/09/2018  18:42             1 102 Condition.cpp
30/09/2018  18:42               411 Configurable.cpp
30/09/2018  18:42             6 195 ConsoleChannel.cpp
30/09/2018  18:42             2 703 CountingStream.cpp
30/09/2018  18:42            14 513 crc32.c
30/09/2018  18:42            31 003 crc32.h
30/09/2018  18:42            11 692 DateTime.cpp
30/09/2018  18:42             1 394 DateTimeFormat.cpp
30/09/2018  18:42             5 271 DateTimeFormatter.cpp
30/09/2018  18:42             9 736 DateTimeParser.cpp
30/09/2018  18:42             3 029 Debugger.cpp
30/09/2018  18:42            81 052 deflate.c
30/09/2018  18:42            13 499 deflate.h
30/09/2018  18:42             8 788 DeflatingStream.cpp
30/09/2018  18:42             2 106 DigestEngine.cpp
30/09/2018  18:42             2 416 DigestStream.cpp
30/09/2018  18:42             2 964 DirectoryIterator.cpp
30/09/2018  18:42             3 522 DirectoryIteratorStrategy.cpp
30/09/2018  18:42             1 158 DirectoryIterator_UNIX.cpp
30/09/2018  18:42             1 251 DirectoryIterator_WIN32.cpp
30/09/2018  18:42             1 501 DirectoryIterator_WIN32U.cpp
30/09/2018  18:42            13 569 DirectoryWatcher.cpp
30/09/2018  18:42             2 531 diy-fp.cc
30/09/2018  18:42             4 082 diy-fp.h
30/09/2018  18:42            31 224 double-conversion.cc
30/09/2018  18:42            26 733 double-conversion.h
30/09/2018  18:42             2 518 Environment.cpp
30/09/2018  18:42             6 735 Environment_UNIX.cpp
30/09/2018  18:42             2 933 Environment_VX.cpp
30/09/2018  18:42             5 492 Environment_WIN32.cpp
30/09/2018  18:42             5 995 Environment_WIN32U.cpp
30/09/2018  18:42             5 981 Environment_WINCE.cpp
30/09/2018  18:42             2 167 Error.cpp
30/09/2018  18:42             1 810 ErrorHandler.cpp
30/09/2018  18:42               566 Event.cpp
30/09/2018  18:42               420 EventArgs.cpp
30/09/2018  18:42               488 EventChannel.cpp
30/09/2018  18:42             7 993 EventLogChannel.cpp
30/09/2018  18:42             4 445 Event_POSIX.cpp
30/09/2018  18:42             1 228 Event_VX.cpp
30/09/2018  18:42             1 013 Event_WIN32.cpp
30/09/2018  18:42             6 060 Exception.cpp
30/09/2018  18:42            31 789 fast-dtoa.cc
30/09/2018  18:42             4 152 fast-dtoa.h
30/09/2018  18:42             3 603 FIFOBufferStream.cpp
30/09/2018  18:42             5 975 File.cpp
30/09/2018  18:42            10 216 FileChannel.cpp
30/09/2018  18:42             1 814 FileStream.cpp
30/09/2018  18:42             1 228 FileStreamFactory.cpp
30/09/2018  18:42             3 065 FileStream_POSIX.cpp
30/09/2018  18:42             4 640 FileStream_WIN32.cpp
30/09/2018  18:42            10 541 File_UNIX.cpp
30/09/2018  18:42             7 627 File_VX.cpp
30/09/2018  18:42            10 370 File_WIN32.cpp
30/09/2018  18:42            11 250 File_WIN32U.cpp
30/09/2018  18:42             9 532 File_WINCE.cpp
30/09/2018  18:42            15 506 fixed-dtoa.cc
30/09/2018  18:42             2 826 fixed-dtoa.h
30/09/2018  18:42            13 216 Format.cpp
30/09/2018  18:42               668 Formatter.cpp
30/09/2018  18:42             2 345 FormattingChannel.cpp
30/09/2018  18:42             1 422 FPEnvironment.cpp
30/09/2018  18:42             1 362 FPEnvironment_C99.cpp
30/09/2018  18:42             3 686 FPEnvironment_DEC.cpp
30/09/2018  18:42             1 280 FPEnvironment_DUMMY.cpp
30/09/2018  18:42             1 362 FPEnvironment_QNX.cpp
30/09/2018  18:42             2 428 FPEnvironment_SUN.cpp
30/09/2018  18:42             1 215 FPEnvironment_WIN32.cpp
30/09/2018  18:42             6 378 Glob.cpp
30/09/2018  18:42             7 057 gzguts.h
30/09/2018  18:42               538 Hash.cpp
30/09/2018  18:42             1 418 HashStatistic.cpp
30/09/2018  18:42             1 659 HexBinaryDecoder.cpp
30/09/2018  18:42             1 872 HexBinaryEncoder.cpp
30/09/2018  18:42            13 928 ieee.h
30/09/2018  18:42            23 355 infback.c
30/09/2018  18:42            13 301 inffast.c
30/09/2018  18:42               438 inffast.h
30/09/2018  18:42             6 426 inffixed.h
30/09/2018  18:42            56 361 inflate.c
30/09/2018  18:42             6 743 inflate.h
30/09/2018  18:42             7 274 InflatingStream.cpp
30/09/2018  18:42            13 303 inftrees.c
30/09/2018  18:42             2 990 inftrees.h
30/09/2018  18:42             2 344 JSONString.cpp
30/09/2018  18:42             3 414 Latin1Encoding.cpp
30/09/2018  18:42             7 779 Latin2Encoding.cpp
30/09/2018  18:42             4 542 Latin9Encoding.cpp
30/09/2018  18:42             3 425 LineEndingConverter.cpp
30/09/2018  18:42             7 286 LocalDateTime.cpp
30/09/2018  18:42               630 LogFile.cpp
30/09/2018  18:42             1 085 LogFile_STD.cpp
30/09/2018  18:42             2 591 LogFile_WIN32.cpp
30/09/2018  18:42             2 695 LogFile_WIN32U.cpp
30/09/2018  18:42             9 649 Logger.cpp
30/09/2018  18:42             3 381 LoggingFactory.cpp
30/09/2018  18:42             2 366 LoggingRegistry.cpp
30/09/2018  18:42             3 419 LogStream.cpp
30/09/2018  18:42               408 Manifest.cpp
30/09/2018  18:42             7 693 MD4Engine.cpp
30/09/2018  18:42             9 410 MD5Engine.cpp
30/09/2018  18:42             1 689 MemoryPool.cpp
30/09/2018  18:42               919 MemoryStream.cpp
30/09/2018  18:42             4 212 Message.cpp
02/01/2019  13:33               232 MSG00001.bin
30/09/2018  18:42               819 Mutex.cpp
30/09/2018  18:42             4 270 Mutex_POSIX.cpp
30/09/2018  18:42             1 059 Mutex_VX.cpp
30/09/2018  18:42             1 087 Mutex_WIN32.cpp
30/09/2018  18:42             1 256 Mutex_WINCE.cpp
30/09/2018  18:42               766 NamedEvent.cpp
30/09/2018  18:42               722 NamedEvent_Android.cpp
30/09/2018  18:42             3 842 NamedEvent_UNIX.cpp
30/09/2018  18:42             1 156 NamedEvent_WIN32.cpp
30/09/2018  18:42             1 239 NamedEvent_WIN32U.cpp
30/09/2018  18:42               766 NamedMutex.cpp
30/09/2018  18:42               866 NamedMutex_Android.cpp
30/09/2018  18:42             4 288 NamedMutex_UNIX.cpp
30/09/2018  18:42             1 352 NamedMutex_WIN32.cpp
30/09/2018  18:42             1 434 NamedMutex_WIN32U.cpp
30/09/2018  18:42             2 286 NestedDiagnosticContext.cpp
30/09/2018  18:42               519 Notification.cpp
30/09/2018  18:42             2 104 NotificationCenter.cpp
30/09/2018  18:42             3 803 NotificationQueue.cpp
30/09/2018  18:42               534 NullChannel.cpp
30/09/2018  18:42               862 NullStream.cpp
30/09/2018  18:42            12 362 NumberFormatter.cpp
30/09/2018  18:42             5 078 NumberParser.cpp
30/09/2018  18:42            10 015 NumericString.cpp
30/09/2018  18:42            19 095 Path.cpp
30/09/2018  18:42             4 705 Path_UNIX.cpp
30/09/2018  18:42             4 181 Path_WIN32.cpp
30/09/2018  18:42             5 007 Path_WIN32U.cpp
30/09/2018  18:42             2 546 Path_WINCE.cpp
30/09/2018  18:42             6 840 PatternFormatter.cpp
30/09/2018  18:42            32 390 pcre.h
30/09/2018  18:42             9 521 pcre_byte_order.c
30/09/2018  18:42             8 019 pcre_chartables.c
30/09/2018  18:42           332 365 pcre_compile.c
30/09/2018  18:42             5 146 pcre_config.c
30/09/2018  18:42            14 909 pcre_config.h
30/09/2018  18:42           130 627 pcre_dfa_exec.c
30/09/2018  18:42           225 577 pcre_exec.c
30/09/2018  18:42             8 037 pcre_fullinfo.c
30/09/2018  18:42            23 548 pcre_get.c
30/09/2018  18:42             3 895 pcre_globals.c
30/09/2018  18:42           116 981 pcre_internal.h
30/09/2018  18:42           376 274 pcre_jit_compile.c
30/09/2018  18:42             6 093 pcre_maketables.c
30/09/2018  18:42             6 347 pcre_newline.c
30/09/2018  18:42             3 430 pcre_ord2utf8.c
30/09/2018  18:42             3 946 pcre_refcount.c
30/09/2018  18:42             5 568 pcre_string_utils.c
30/09/2018  18:42            50 346 pcre_study.c
30/09/2018  18:42            29 472 pcre_tables.c
30/09/2018  18:42           212 183 pcre_ucd.c
30/09/2018  18:42            10 481 pcre_valid_utf8.c
30/09/2018  18:42             4 271 pcre_version.c
30/09/2018  18:42             8 470 pcre_xclass.c
30/09/2018  18:42               904 Pipe.cpp
30/09/2018  18:42               529 PipeImpl.cpp
30/09/2018  18:42               766 PipeImpl_DUMMY.cpp
30/09/2018  18:42             1 588 PipeImpl_POSIX.cpp
30/09/2018  18:42             1 809 PipeImpl_WIN32.cpp
30/09/2018  18:42             1 606 PipeStream.cpp
02/01/2019  13:33             3 702 pocomsg.h
30/09/2018  18:42             2 330 pocomsg.mc
02/01/2019  13:33                39 pocomsg.rc
30/09/2018  18:42             3 707 PriorityNotificationQueue.cpp
30/09/2018  18:42             4 426 Process.cpp
30/09/2018  18:42             6 398 Process_UNIX.cpp
30/09/2018  18:42             1 762 Process_VX.cpp
30/09/2018  18:42             8 573 Process_WIN32.cpp
30/09/2018  18:42             9 245 Process_WIN32U.cpp
30/09/2018  18:42             4 694 Process_WINCE.cpp
30/09/2018  18:42             2 136 PurgeStrategy.cpp
30/09/2018  18:42            12 489 Random.cpp
30/09/2018  18:42             2 386 RandomStream.cpp
30/09/2018  18:42               449 RefCountedObject.cpp
30/09/2018  18:42             7 613 RegularExpression.cpp
30/09/2018  18:42             2 150 RotateStrategy.cpp
30/09/2018  18:42               409 Runnable.cpp
30/09/2018  18:42               675 RWLock.cpp
30/09/2018  18:42               668 RWLock_Android.cpp
30/09/2018  18:42               534 RWLock_POSIX.cpp
30/09/2018  18:42               970 RWLock_VX.cpp
30/09/2018  18:42             4 157 RWLock_WIN32.cpp
30/09/2018  18:42             2 873 RWLock_WINCE.cpp
30/09/2018  18:42               667 Semaphore.cpp
30/09/2018  18:42             4 504 Semaphore_POSIX.cpp
30/09/2018  18:42               916 Semaphore_VX.cpp
30/09/2018  18:42             1 092 Semaphore_WIN32.cpp
30/09/2018  18:42             8 350 SHA1Engine.cpp
30/09/2018  18:42             1 780 SharedLibrary.cpp
30/09/2018  18:42             1 593 SharedLibrary_HPUX.cpp
30/09/2018  18:42             2 364 SharedLibrary_UNIX.cpp
30/09/2018  18:42             2 538 SharedLibrary_VX.cpp
30/09/2018  18:42             1 701 SharedLibrary_WIN32.cpp
30/09/2018  18:42             2 013 SharedLibrary_WIN32U.cpp
30/09/2018  18:42             1 576 SharedMemory.cpp
30/09/2018  18:42               618 SharedMemory_DUMMY.cpp
30/09/2018  18:42             2 714 SharedMemory_POSIX.cpp
30/09/2018  18:42             4 424 SharedMemory_WIN32.cpp
30/09/2018  18:42             2 038 SignalHandler.cpp
30/09/2018  18:42             4 313 SimpleFileChannel.cpp
30/09/2018  18:42             2 138 SortedDirectoryIterator.cpp
30/09/2018  18:42             2 056 SplitterChannel.cpp
30/09/2018  18:42               756 Stopwatch.cpp
30/09/2018  18:42               607 StreamChannel.cpp
30/09/2018  18:42             3 959 StreamConverter.cpp
30/09/2018  18:42             2 954 StreamCopier.cpp
30/09/2018  18:42             1 818 StreamTokenizer.cpp
30/09/2018  18:42             6 201 String.cpp
30/09/2018  18:42             3 118 StringTokenizer.cpp
30/09/2018  18:42            21 615 strtod.cc
30/09/2018  18:42             2 254 strtod.h
30/09/2018  18:42               456 SynchronizedObject.cpp
30/09/2018  18:42             5 859 SyslogChannel.cpp
30/09/2018  18:42             1 953 Task.cpp
30/09/2018  18:42             2 932 TaskManager.cpp
30/09/2018  18:42             1 465 TaskNotification.cpp
30/09/2018  18:42             1 756 TeeStream.cpp
30/09/2018  18:42             2 446 TemporaryFile.cpp
30/09/2018  18:42             3 048 TextBufferIterator.cpp
30/09/2018  18:42             2 621 TextConverter.cpp
30/09/2018  18:42             3 957 TextEncoding.cpp
30/09/2018  18:42             2 867 TextIterator.cpp
30/09/2018  18:42             2 832 Thread.cpp
30/09/2018  18:42             1 328 ThreadLocal.cpp
30/09/2018  18:42             9 864 ThreadPool.cpp
30/09/2018  18:42               639 ThreadTarget.cpp
30/09/2018  18:42             9 500 Thread_POSIX.cpp
30/09/2018  18:42             5 875 Thread_VX.cpp
30/09/2018  18:42             4 469 Thread_WIN32.cpp
30/09/2018  18:42             2 969 Thread_WINCE.cpp
30/09/2018  18:42             3 970 TimedNotificationQueue.cpp
30/09/2018  18:42             4 337 Timer.cpp
30/09/2018  18:42             2 804 Timespan.cpp
30/09/2018  18:42             6 340 Timestamp.cpp
30/09/2018  18:42               643 Timezone.cpp
30/09/2018  18:42             1 926 Timezone_UNIX.cpp
30/09/2018  18:42             1 536 Timezone_VX.cpp
30/09/2018  18:42             2 359 Timezone_WIN32.cpp
30/09/2018  18:42             1 972 Timezone_WINCE.cpp
30/09/2018  18:42             2 073 Token.cpp
30/09/2018  18:42            44 964 trees.c
30/09/2018  18:42             8 600 trees.h
30/09/2018  18:42             5 439 ucp.h
30/09/2018  18:42             1 032 Unicode.cpp
30/09/2018  18:42             3 814 UnicodeConverter.cpp
30/09/2018  18:42            19 323 URI.cpp
30/09/2018  18:42               860 URIStreamFactory.cpp
30/09/2018  18:42             4 633 URIStreamOpener.cpp
30/09/2018  18:42             5 640 UTF16Encoding.cpp
30/09/2018  18:42             4 042 UTF32Encoding.cpp
30/09/2018  18:42             5 846 UTF8Encoding.cpp
30/09/2018  18:42             8 707 UTF8String.cpp
30/09/2018  18:42            11 614 utils.h
30/09/2018  18:42             7 864 UUID.cpp
30/09/2018  18:42             3 072 UUIDGenerator.cpp
30/09/2018  18:42            13 318 Var.cpp
30/09/2018  18:42             1 480 VarHolder.cpp
30/09/2018  18:42             2 987 VarIterator.cpp
30/09/2018  18:42               446 Void.cpp
30/09/2018  18:42             8 937 Windows1250Encoding.cpp
30/09/2018  18:42            11 578 Windows1251Encoding.cpp
30/09/2018  18:42             5 910 Windows1252Encoding.cpp
30/09/2018  18:42             7 392 WindowsConsoleChannel.cpp
30/09/2018  18:42            16 896 zconf.h
30/09/2018  18:42            98 151 zlib.h
30/09/2018  18:42             7 808 zutil.c
30/09/2018  18:42             7 084 zutil.h
             299 fichier(s)        3 213 588 octets
               2 Rép(s)  88 534 315 008 octets libres

@lacasseio
Copy link
Contributor

You are right @zosrothko. This seems to be a limitation with how the source view is calculated. We are probably being a bit too restrictive in the sense that the default location should include the pattern filter for the specific source. However, if you specify your own pattern, you should be allowed to specify any files ending/filter pattern. One of the main driving force for the new plugin is the configuration should scale in complexity with how complex it your project. Simple projects have nothing to specify. For example, custom file location will need to specify it's own source extension filtering like you are doing.

To move forward with this, I would create a PR for the following:

  • Add coverage for changing the source location to another location with the same extension (.cpp or .swift)
  • Add coverage for compiling C++ files with another source extension from the default location
  • Add coverage for compiling C++ files with another source extension from a different location
  • Move the matching of the pattern when getFrom().isEmpty() condition only for C++.
  • Swift should still behave the same way.

There is still one open question: Does just changing the only the location should still include only the default source extension? I think that if you are opinionated about where the files are, you should also be opinionated about what source extension you want from that location.

@zosrothko Do you want to provide a PR for this?

@lacasseio
Copy link
Contributor

@zosrothko
Copy link

zosrothko commented Feb 13, 2019 via email

@lacasseio
Copy link
Contributor

I agree that we should be able to query the source FileCollection to know if any filter has been applied. In the even no filter was applied, we can apply our default filter. The issue is answering the question. FileCollection can include other FileCollection and event FileTree that may have filters on their own. It's a matter of knowing where the default filter should be applied and what was the user's intention when adding sources.

For example, a user could add one FileCollection without filters with the intention the default filter would apply and later add another one with a filter different than the default one. In this case, we could have a strange failure where more files are included from the first FileCollection. My thinking was more along the lines that if you specify a custom FileCollection for your source, this means you know which file you want and you should be expressing them fully. It's pretty much what you are doing in your example. What we could do as a middle ground solution is to expose a public helper method for setting the default filter in your custom FileCollection.

@zosrothko
Copy link

I think something is missing in the source block when a directory contains sources from different languages. Here a use case

Let say one have a single directory with sources like

  1. Assembly sources suffixed by '.asm'.
  2. C sources suffixed by '.c'.
  3. C++ sources suffixed by '.cpp' or '.cc' or '.cxx'.
  4. Cobol source suffixed by '.cob'. (if one day a CobolCompiler plugin be offered)

Unless misunderstanding from my side, there is currently no way to associate each kind of source with its proper compiler and the proper language options.

For example on Windows, it would be usefull to link

  1. the '.asm' suffix with the VisualStudio cl compiler and the proper options
  2. the '.c' suffix with the VisualStudio cl compiler plus the option '/Tc' ofr'/TC'
  3. the '.cpp' suffix with the VisualStudio cl compiler plus the option '/Tp' pt '/TP'
  4. the '.cob' suffix with the Cobol compiler and whatever option
  5. the '.cpy' suffix with the Cobol compiler and whatever option

@lacasseio
Copy link
Contributor

This is working as expected. Multi-sources components have been ignored at the moment so all source will be compiled as C++ source. To compile C source with a C compiler, see the sample demonstrating this. It will change in the future, but at the moment it's something we haven't looked into. We are unsure if the software model approach was the correct one.

@lacasseio
Copy link
Contributor

This issue should only demonstrate how to have same language sources that are compiled differently (or completely excluded from a specific variant of the component). Multiple language source for component should be demonstrated as another sample.

@NikBomb
Copy link

NikBomb commented Apr 13, 2022

Hello, I just wanted to ask if the original question from @jamie-walker has been addressed and we have an example?

ashimagarg67 pushed a commit to ashimagarg67/gradle that referenced this issue Apr 29, 2024
See gradle/gradle-native#974

Signed-off-by: Francis ANDRE <francis.andre.kampbell@orange.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants