1# PURPOSE:
2# The code in this file loops through all of the compile groups, extracts all the required
3# and optional dependencies, and collects all of the source files needed for  the compile
4# targets (e.g., libmuqModeling, etc...)
5#
6
7
8
9# Initially, we have no targets to build
10set(MUQ_TARGETS "" CACHE INTERNAL "List of MUQ libraries to build.")
11set(MUQ_GROUPS "" CACHE INTERNAL "List of MUQ compile groups.")
12
13# Go compile everything
14add_subdirectory(modules)
15
16function(ForciblyEnable group)
17  message(STATUS "Forcibly enabling ${group}")
18
19  set(MUQ_ENABLEGROUP_${group} ON CACHE INTERNAL "MUQ_ENABLEGROUP_${group}")
20
21
22  foreach(depend ${${group}_REQUIRES_GROUPS})
23    if(NOT MUQ_ENABLEGROUP_${depend})
24        message(STATUS "    The ${group} group depends on the ${depend} group, but the ${depend} group was not enabled.")
25        message(STATUS "    Turning the ${depend} group on.")
26        set(MUQ_ENABLEGROUP_${depend} ON CACHE INTERNAL "MUQ_ENABLEGROUP_${depend}")
27        ForciblyEnable(${depend})
28    endif()
29  endforeach()
30endfunction(ForciblyEnable)
31
32## Figure out what dependencies we actually need
33set(MUQ_REQUIRES )
34set(MUQ_DESIRES )
35foreach(group ${MUQ_GROUPS})
36
37      # Make sure all upstream dependency groups are enabled
38      message(STATUS "Configuring compile group ${group}")
39      foreach(depend ${${group}_REQUIRES_GROUPS})
40          if(MUQ_ENABLEGROUP_${group} AND NOT MUQ_ENABLEGROUP_${depend})
41              message(STATUS "    The ${group} group depends on the ${depend} group, but the ${depend} group was not enabled.")
42              message(STATUS "    Turning the ${depend} group on.")
43              ForciblyEnable(${depend})
44          endif()
45      endforeach()
46
47endforeach()
48
49foreach(group ${MUQ_GROUPS})
50
51  if(MUQ_ENABLEGROUP_${group})
52      # Add to the list of required external libraries
53      foreach(depend ${${group}_REQUIRES})
54          list(APPEND MUQ_REQUIRES ${depend})
55      endforeach()
56
57      # Add to the list of desired (i.e., optional) external libraries
58      foreach(depend ${${group}_DESIRES})
59          list(APPEND MUQ_DESIRES ${depend})
60      endforeach()
61
62  endif()
63endforeach()
64
65# Remove duplicate requirements
66list(REMOVE_DUPLICATES MUQ_REQUIRES)
67if(MUQ_DESIRES)
68    list(REMOVE_DUPLICATES MUQ_DESIRES)
69endif()
70
71# Create a list of all MUQ libraries to build
72set(MUQ_TARGETS )
73foreach(group ${MUQ_GROUPS})
74    if(MUQ_ENABLEGROUP_${group})
75        message(STATUS "Adding target ${${group}_LIBRARY} for compile group ${group}")
76        list(APPEND MUQ_TARGETS ${${group}_LIBRARY})
77    endif()
78endforeach()
79list(REMOVE_DUPLICATES MUQ_TARGETS)
80
81# Set up the source for each target library
82foreach(target ${MUQ_TARGETS})
83    set(${target}_SOURCES )
84
85    foreach(group ${MUQ_GROUPS})
86        if(MUQ_ENABLEGROUP_${group})
87	          if(${${group}_LIBRARY} MATCHES ${target})
88
89                # Check to see if a group has any source (e.g., *.cpp) files.  Flag it as something that will be built if it does.
90	              list(LENGTH ${group}_SOURCES sources_length)
91		            if(sources_length GREATER 0)
92	                  set(${group}_IS_COMPILED ON CACHE INTERNAL "Whether or not the group ${group} is used in any library.")
93		            endif()
94
95	              list(APPEND ${target}_SOURCES ${${group}_SOURCES})
96	          endif()
97	      endif()
98    endforeach()
99
100    if(${target}_SOURCES)
101        list(REMOVE_DUPLICATES ${target}_SOURCES)
102    endif()
103
104endforeach()
105