@@ -491,37 +491,21 @@ def generate_cmakelists(cppstd, root_path, INCLUDE_DIRS, DEFINITIONS, EXTRA_SOUR
491
491
for d in DEFINITIONS :
492
492
# TODO: check definition type! type1: JUST_DEF type2: DEF="value"
493
493
cmakelists .append ("add_definitions(-D" + d + ")" )
494
- # add sources!
495
- cmakelists .append ("set(SOURCES" )
496
- # add extra sources!
497
- for esrc in EXTRA_SOURCES :
498
- cmakelists .append (esrc )
499
- # get all sources not in main() list (no duplicates exist)
500
- clean_list = []
501
- clean_list_main = []
502
- for f in src_list :
503
- clean_list .append (f .replace ("\\ " , "/" ))
504
- #clean_list = list(set(clean_list)) # do not do this!
505
- for filepath , app_name in src_main .items ():
506
- clean_list_main .append (filepath .replace ("\\ " , "/" ))
507
- #clean_list_main = list(set(clean_list_main)) # do not do this!
508
- clean_list = [x for x in clean_list if x not in clean_list_main ]
509
- for f in clean_list :
510
- cmakelists .append ("\t " + f )
511
- cmakelists .append (")" )
494
+ #
495
+ cmakelists .append ("# add all executables" )
512
496
COUNT_APP_ID = 1
513
497
all_apps = []
514
498
# add_executable for binaries
515
499
for filepath , app_name in src_main .items ():
516
- cmakelists .append ("add_executable(" + app_name [1 ]+ " " + filepath .replace ("\\ " , "/" )+ " ${SOURCES} )" )
500
+ cmakelists .append ("add_executable(" + app_name [1 ]+ " " + filepath .replace ("\\ " , "/" )+ " )" )
517
501
# add_executable for test binaries
518
502
print ("finding test executables!" )
519
503
# if no main is found, then each test is assumed to be independent!
520
504
if len (src_test_main .items ()) == 0 :
521
505
print ("WARNING: no main() is found for tests... using main-less strategy!" )
522
506
src_test_main = src_test_nomain
523
507
for filepath , app_name in src_test_main .items ():
524
- cmakelists .append ("add_executable(" + app_name [1 ]+ " " + filepath .replace ("\\ " , "/" )+ " ${SOURCES} )" )
508
+ cmakelists .append ("add_executable(" + app_name [1 ]+ " " + filepath .replace ("\\ " , "/" )+ " )" )
525
509
526
510
527
511
# INCLUDE_DIRS will act as header-only libraries
@@ -540,6 +524,30 @@ def generate_cmakelists(cppstd, root_path, INCLUDE_DIRS, DEFINITIONS, EXTRA_SOUR
540
524
# cxxdeps.txt
541
525
cmakelists = get_cmakelists_from_cxxdeps (root_path , cmakelists , INCLUDE_DIRS , src_main , src_test_main )
542
526
527
+ # ======== begin add sources ========
528
+ cmakelists .append ("# finally, add all sources" )
529
+ cmakelists .append ("set(SOURCES" )
530
+ # add extra sources!
531
+ for esrc in EXTRA_SOURCES :
532
+ cmakelists .append ("\t " + esrc )
533
+ # get all sources not in main() list (no duplicates exist)
534
+ clean_list = []
535
+ clean_list_main = []
536
+ for f in src_list :
537
+ clean_list .append (f .replace ("\\ " , "/" ))
538
+ #clean_list = list(set(clean_list)) # do not do this!
539
+ for filepath , app_name in src_main .items ():
540
+ clean_list_main .append (filepath .replace ("\\ " , "/" ))
541
+ #clean_list_main = list(set(clean_list_main)) # do not do this!
542
+ clean_list = [x for x in clean_list if x not in clean_list_main ]
543
+ for f in clean_list :
544
+ cmakelists .append ("\t " + f )
545
+ cmakelists .append (")" )
546
+ # ======== end add sources ========
547
+ for filepath , app_name in src_main .items ():
548
+ cmakelists .append ("target_sources(" + app_name [1 ]+ " PRIVATE ${SOURCES})" )
549
+ for filepath , app_name in src_test_main .items ():
550
+ cmakelists .append ("target_sources(" + app_name [1 ]+ " PRIVATE ${SOURCES})" )
543
551
544
552
545
553
# Generate CMakeLists.txt (or look for other option, such as 'bazel')
0 commit comments