1+ 
12if  (NOT  Ice_HOME)
23  if  (DEFINED  ENV{ICE_HOME})
34    set (Ice_HOME $ENV{ICE_HOME}  CACHE  PATH  "Path to the Ice installation directory" )
@@ -10,69 +11,173 @@ if (NOT EXISTS ${Ice_HOME})
1011  message (FATAL_ERROR "The specified Ice_HOME directory does not exist: ${Ice_HOME} " )
1112endif ()
1213
13- find_program (Ice_SLICE2CPP_EXECUTABLE slice2cpp HINTS  ${Ice_HOME} /cpp/bin PATH_SUFFIXES  x64/Release x64/Debug)
14+ # List of all available Ice components 
15+ set (Ice_AVAILABLE_COMPONENTS DataStorm Glacier2 Ice IceBox IceGrid IceStorm)
1416
15- if (NOT  DEFINED  Ice_SLICE_DIR AND  EXISTS  ${Ice_HOME} /slice)
16-   set (Ice_SLICE_DIR ${Ice_HOME} /slice CACHE  PATH  "Path to the Ice Slice files directory" )
17+ # IceBT is only available on Linux 
18+ # TODO: Check for required dependency 
19+ if (UNIX  AND  NOT  APPLE )
20+   list (APPEND  Ice_AVAILABLE_COMPONENTS IceBT)
1721endif ()
1822
19- # This is the only version we support for the demos right now 
20- set (Ice_VERSION "3.8.0-alpha.0"  CACHE  STRING  "Ice version" )
21- set (Ice_DLL_VERSION "38a0"  CACHE  STRING  "Ice DLL version" )
22- 
23- find_path (Ice_INCLUDE_DIR NAMES  Ice/Ice.h HINTS  ${Ice_HOME} /cpp/include )
23+ # Ensure Ice is always in the components list 
24+ if (NOT  "Ice"  IN_LIST  Ice_FIND_COMPONENTS)
25+     list (APPEND  Ice_FIND_COMPONENTS Ice)
26+ endif ()
2427
25- if  (CMAKE_LIBRARY_ARCHITECTURE )
26-   list (APPEND  lib_path_suffixes ${CMAKE_LIBRARY_ARCHITECTURE} )
28+ # Ensure requested components are valid 
29+ foreach (component  ${Ice_FIND_COMPONENTS} )
30+     if (NOT  component  IN_LIST  Ice_AVAILABLE_COMPONENTS)
31+         message (FATAL_ERROR "Ice component '${component} ' not found. Available: ${Ice_AVAILABLE_COMPONENTS} " )
32+     endif ()
33+ endforeach ()
34+ 
35+ if (NOT  DEFINED  Ice_ARCHITECTURE)
36+   if  (CMAKE_LIBRARY_ARCHITECTURE )
37+     set (Ice_ARCHITECTURE ${CMAKE_LIBRARY_ARCHITECTURE}  CACHE  STRING  "Library architecture" )
38+   elseif (WIN32 )
39+     if (CMAKE_SIZEOF_VOID_P  EQUAL  8)
40+       set (Ice_ARCHITECTURE "x64"  CACHE  STRING  "Windows x64" )
41+     else ()
42+       set (Ice_ARCHITECTURE "Win32"  CACHE  STRING  "Windows x86" )
43+     endif ()
44+   endif ()
2745endif ()
2846
29- if (WIN32 )
30-   list (APPEND  lib_path_suffixes x64/Release)
47+ # Ice include directory 
48+ if (NOT  DEFINED  Ice_INCLUDE_DIR)
49+   find_path (Ice_INCLUDE_DIR NAMES  Ice/Ice.h HINTS  ${Ice_HOME} /cpp/include  CACHE  PATH  "Path to the Ice include directory" )
3150endif ()
3251
33- find_library (Ice_LIBRARY NAMES  Ice Ice${Ice_DLL_VERSION}  HINTS  ${Ice_HOME} /cpp/lib/ PATH_SUFFIXES  ${lib_path_suffixes} )
52+ # Ice include directories include the generated directory(s) 
53+ if (NOT  DEFINED  Ice_INCLUDE_DIRS)
54+   set (Ice_INCLUDE_DIRS ${Ice_INCLUDE_DIR} )
55+ 
56+   #  Only the Windows build has separate Debug and Release directories for the generated files 
57+   if (WIN32 )
58+     set (Ice_GENERATED_INCLUDE_DIR_RELEASE ${Ice_INCLUDE_DIR} /generated /${Ice_ARCHITECTURE} /Release)
59+     if  (EXISTS  ${Ice_GENERATED_INCLUDE_DIR_RELEASE} )
60+       list (APPEND  Ice_INCLUDE_DIRS $<$<CONFIG:Release>:${Ice_GENERATED_INCLUDE_DIR_RELEASE} >)
61+     endif ()
62+ 
63+     set (Ice_GENERATED_INCLUDE_DIR_DEBUG ${Ice_INCLUDE_DIR} /generated /${Ice_ARCHITECTURE} /Debug)
64+     if  (EXISTS  ${Ice_GENERATED_INCLUDE_DIR_DEBUG} )
65+       list (APPEND  Ice_INCLUDE_DIRS $<$<CONFIG:Debug>:${Ice_GENERATED_INCLUDE_DIR_DEBUG} >)
66+     endif ()
67+   elseif (EXISTS  ${Ice_INCLUDE_DIR} /generated )
68+       list (APPEND  Ice_INCLUDE_DIRS ${Ice_INCLUDE_DIR} /generated )
69+   endif ()
70+ 
71+   set (Ice_INCLUDE_DIRS ${Ice_INCLUDE_DIRS}  CACHE  STRING  "Ice include directories" )
3472
35- if  (Ice_FIND_COMPONENTS)
36-   foreach (component  IN LISTS Ice_FIND_COMPONENTS)
37-     string (TOUPPER "${component} "  component_upcase)
38-     find_library (Ice_${component_upcase} _LIBRARY NAMES  ${component}  ${component}${Ice_DLL_VERSION}  HINTS  ${Ice_HOME} /cpp/lib/ PATH_SUFFIXES  ${lib_path_suffixes} )
39-   endforeach ()
4073endif ()
4174
42- find_package_handle_standard_args(Ice
43-                   REQUIRED_VARS Ice_SLICE2CPP_EXECUTABLE
44-                         Ice_INCLUDE_DIR
45-                         Ice_LIBRARY
46-                         Ice_SLICE_DIR
47-                   VERSION_VAR Ice_VERSION)
48- 
49- if (Ice_FOUND)
50-   # set(Ice_LIBRARIES ${Ice_LIBRARY}) 
51-   if (WIN32 )
52-     set (Ice_INCLUDE_DIRS ${Ice_INCLUDE_DIR}  ${Ice_HOME} /cpp/include /generated  ${Ice_HOME} /cpp/include /generated /x64/Release)
53-   else ()
54-     set (Ice_INCLUDE_DIRS ${Ice_INCLUDE_DIR}  ${Ice_HOME} /cpp/include /generated )
75+ # Read Ice version variables from Ice/Config.h 
76+ if  (NOT  DEFINED  Ice_VERSION)
77+ 
78+   file (STRINGS  "${Ice_INCLUDE_DIR} /Ice/Config.h"  _ice_config_h_content REGEX  "#define ICE_([A-Z]+)_VERSION " )
79+ 
80+   if ("${_ice_config_h_content} "  MATCHES  "#define ICE_STRING_VERSION \" ([^\" ]+)\" " )
81+     set (Ice_VERSION "${CMAKE_MATCH_1} "  CACHE  STRING  "Ice version" )
82+   endif ()
83+ 
84+   if ("${_ice_config_h_content} "  MATCHES  "#define ICE_SO_VERSION \" ([^\" ]+)\" " )
85+     set (Ice_SO_VERSION "${CMAKE_MATCH_1} "  CACHE  STRING  "Ice so version" )
5586  endif ()
5687
57-   add_library (Ice::Ice UNKNOWN IMPORTED )
58-   # set_target_properties(Ice::Ice PROPERTIES IMPORTED_IMPLIB ${Ice_LIBRARY}) 
59-   set_target_properties (Ice::Ice PROPERTIES
60-     IMPORTED_LOCATION  ${Ice_LIBRARY} 
61-     INTERFACE_INCLUDE_DIRECTORIES  "${Ice_INCLUDE_DIRS} " 
62-   )
63- 
64-   if  (Ice_FIND_COMPONENTS)
65-     foreach (component  IN LISTS Ice_FIND_COMPONENTS)
66-       string (TOUPPER "${component} "  component_upcase)
67-       add_library (Ice::${component}  UNKNOWN IMPORTED )
88+   if ("${_ice_config_h_content} "  MATCHES  "#define ICE_INT_VERSION ([0-9]+)" )
89+     set (Ice_INT_VERSION "${CMAKE_MATCH_1} "  CACHE  STRING  "Ice int version" )
90+   endif ()
91+ 
92+   unset (_ice_config_h_content)
93+ 
94+ endif ()
95+ 
96+ if (NOT  DEFINED  Ice_SLICE2CPP_EXECUTABLE)
97+   find_program (Ice_SLICE2CPP_EXECUTABLE slice2cpp
98+     HINTS  ${Ice_HOME} /cpp/bin
99+     PATH_SUFFIXES  ${Ice_ARCHITECTURE} /Release ${Ice_ARCHITECTURE} /Debug
100+     CACHE  PATH  "Path to the slice2cpp executable" )
101+ endif ()
102+ 
103+ if (NOT  DEFINED  Ice_SLICE_DIR AND  EXISTS  ${Ice_HOME} /slice)
104+   set (Ice_SLICE_DIR ${Ice_HOME} /slice CACHE  PATH  "Path to the Ice Slice files directory" )
105+ endif ()
106+ 
107+ foreach (component  ${Ice_FIND_COMPONENTS} )
108+   if (NOT  TARGET  Ice::${component} )
109+     # Create an imported target for the component 
110+     add_library (Ice::${component}  UNKNOWN IMPORTED )
111+ 
112+     find_library (Ice_${component} _LIBRARY_RELEASE
113+       NAMES  ${component}  ${component}${Ice_SO_VERSION} 
114+       HINTS  ${Ice_HOME} /cpp/lib/
115+       PATH_SUFFIXES  ${Ice_ARCHITECTURE}  ${Ice_ARCHITECTURE} /Release
116+     )
117+ 
118+     find_library (Ice_${component} _LIBRARY_DEBUG
119+       NAMES  ${component} d ${component}${Ice_SO_VERSION} d
120+       HINTS  ${Ice_HOME} /cpp/lib/
121+       PATH_SUFFIXES  ${Ice_ARCHITECTURE}  ${Ice_ARCHITECTURE} /Debug
122+     )
123+ 
124+     if (Ice_${component} _LIBRARY_RELEASE)
125+       set_property (TARGET  Ice::${component}  APPEND  PROPERTY
126+         IMPORTED_CONFIGURATIONS  RELEASE
127+       )
128+       set_target_properties (Ice::${component}  PROPERTIES
129+         IMPORTED_LOCATION_RELEASE  "${Ice_${component} _LIBRARY_RELEASE}" 
130+       )
131+     endif ()
132+ 
133+     if (Ice_${component} _LIBRARY_DEBUG)
134+       set_property (TARGET  Ice::${component}  APPEND  PROPERTY
135+         IMPORTED_CONFIGURATIONS  DEBUG
136+       )
68137      set_target_properties (Ice::${component}  PROPERTIES
69-         IMPORTED_LOCATION  ${Ice_${component_upcase} _LIBRARY}
70-         INTERFACE_INCLUDE_DIRECTORIES  "${Ice_INCLUDE_DIRS} " 
138+         IMPORTED_LOCATION_DEBUG  "${Ice_${component} _LIBRARY_DEBUG}" 
71139      )
72-     endforeach ()
140+     endif ()
141+ 
142+     set_target_properties (Ice::${component}  PROPERTIES
143+       INTERFACE_INCLUDE_DIRECTORIES  "${Ice_INCLUDE_DIRS} " 
144+     )
145+ 
146+     # Select the appropriate library configuration based on platform and build type 
147+     include (SelectLibraryConfigurations)
148+     select_library_configurations(Ice_${component} )
149+ 
73150  endif ()
151+ 
152+ endforeach ()
153+ 
154+ if (Ice_DEBUG)
155+   message (STATUS  "Ice_VERSION: ${Ice_VERSION} " )
156+   message (STATUS  "Ice_SO_VERSION: ${Ice_SO_VERSION} " )
157+   message (STATUS  "Ice_INT_VERSION: ${Ice_INT_VERSION} " )
158+   message (STATUS  "Ice_HOME: ${Ice_HOME} " )
159+   message (STATUS  "Ice_SLICE2CPP_EXECUTABLE: ${Ice_SLICE2CPP_EXECUTABLE} " )
160+   message (STATUS  "Ice_SLICE_DIR directory: ${Ice_SLICE_DIR} " )
161+   message (STATUS  "Ice_INCLUDE_DIR: ${Ice_INCLUDE_DIR} " )
162+   message (STATUS  "Ice_INCLUDE_DIRS: ${Ice_INCLUDE_DIRS} " )
163+ 
164+   foreach (component  ${Ice_FIND_COMPONENTS} )
165+     message (STATUS  "Ice_${component} _LIBRARY: ${Ice_${component} _LIBRARY}" )
166+     if (Ice_${component} _LIBRARY_RELEASE)
167+       message (STATUS  "Ice_${component} _LIBRARY_RELEASE: ${Ice_${component} _LIBRARY_RELEASE}" )
168+     endif ()
169+     if (Ice_${component} _LIBRARY_DEBUG)
170+       message (STATUS  "Ice_${component} _LIBRARY_DEBUG: ${Ice_${component} _LIBRARY_DEBUG}" )
171+     endif ()
172+   endforeach ()
74173endif ()
75174
175+ # Use `find_package_handle_standard_args` for better error handling 
176+ find_package_handle_standard_args(Ice
177+   REQUIRED_VARS Ice_HOME Ice_INCLUDE_DIRS Ice_SLICE2CPP_EXECUTABLE
178+   HANDLE_COMPONENTS
179+ )
180+ 
76181# Function to generate C++ source files from Slice (.ice) files for a target using slice2cpp 
77182# The target must have the Slice files in its sources 
78183# The generated files are added to the target sources 
@@ -84,8 +189,11 @@ function(slice2cpp_generate target)
84189  # Get the list of source files for the target 
85190  get_target_property (sources  ${target}  SOURCES )
86191
87-   # Create a  directory to store  the generated files 
192+   # Get the output  directory for  the generated files 
88193  set (output_dir ${CMAKE_CURRENT_BINARY_DIR} /generated /${target} )
194+   file (RELATIVE_PATH output_dir_relative ${CMAKE_CURRENT_LIST_DIR}  ${output_dir} )
195+ 
196+   # Create a directory to store the generated files 
89197  make_directory (${output_dir} )
90198
91199  # Add the generated headers files to the target include directories 
@@ -99,26 +207,18 @@ function(slice2cpp_generate target)
99207
100208      get_filename_component (slice_file_name ${file}  NAME_WE )
101209      get_filename_component (slice_file_path ${file}  ABSOLUTE )
210+ 
102211      set (output_files ${output_dir} /${slice_file_name} .h ${output_dir} /${slice_file_name} .cpp)
103212
104213      add_custom_command (
105214        OUTPUT  ${output_files} 
106215        COMMAND  ${Ice_SLICE2CPP_EXECUTABLE}  -I${Ice_SLICE_DIR}  ${slice_file_path}  --output -dir ${output_dir} 
107216        DEPENDS  ${slice_file_path} 
108-         COMMENT  "${Ice_SLICE2CPP_EXECUTABLE}   ${file}  -> ${slice_file_name} .h  ${slice_file_name} .cpp " 
217+         COMMENT  "Compiling Slice  ${file}  -> ${output_dir_relative}  / ${ slice_file_name}cpp  ${output_dir_relative}  / ${ slice_file_name}h " 
109218      )
110219
111220      target_sources (${target}  PRIVATE  ${output_files} )
112221
113222    endif ()
114223  endforeach ()
115224endfunction ()
116- 
117- if (Ice_DEBUG)
118-   message (STATUS  "Ice_VERSION: ${Ice_VERSION} " )
119-   message (STATUS  "Ice_HOME: ${Ice_HOME} " )
120-   message (STATUS  "Ice_INCLUDE_DIR: ${Ice_INCLUDE_DIR} " )
121-   message (STATUS  "Ice_INCLUDE_DIRS: ${Ice_INCLUDE_DIRS} " )
122-   message (STATUS  "Ice_SLICE_DIR directory: ${Ice_SLICE_DIR} " )
123-   message (STATUS  "Ice_LIBRARY: ${Ice_LIBRARY} " )
124- endif ()
0 commit comments