Skip to content

Commit 4c2ad4d

Browse files
authored
Improvements to IceConfig.cmake (#278)
1 parent 1f38f74 commit 4c2ad4d

File tree

3 files changed

+197
-71
lines changed

3 files changed

+197
-71
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ jobs:
6161
- name: Setup Ice Build Dependencies
6262
uses: ./ice/.github/actions/setup-dependencies
6363

64-
- name: Build Ice on ${{ matrix.os }}
64+
- name: Build Ice
6565
uses: ./ice/.github/actions/build
6666
timeout-minutes: 60
6767
with:
6868
working_directory: ice
6969
build_flags: ${{ runner.os == 'Windows' && '/t:BuildDist' || 'srcs' }}
7070

71-
- name: Publish C# NuGet Packages on ${{ matrix.os }}
71+
- name: Publish C# NuGet Packages
7272
timeout-minutes: 5
7373
working-directory: ice/csharp/msbuild
7474
run: dotnet msbuild ice.proj /t:Publish
@@ -78,17 +78,30 @@ jobs:
7878
with:
7979
path: ice-demos
8080

81-
- name: Generate C++ Build Systems on ${{ matrix.os }}
82-
timeout-minutes: 5
81+
- name: Build C++ Demos
82+
timeout-minutes: 20
8383
working-directory: ice-demos/cpp
84-
run: find . -name CMakeLists.txt -execdir cmake -B build -S . ";"
84+
run: |
85+
set -o pipefail
86+
find . -name CMakeLists.txt -type f | while IFS= read -r file; do
87+
dir=$(dirname "$file");
88+
cmake -B "$dir/build" -S "$dir" -DIce_DEBUG=ON
89+
cmake --build "$dir/build" --config Release
90+
done
91+
if: runner.os != 'Windows'
8592

86-
- name: Build C++ Demos on ${{ matrix.os }}
93+
- name: Build C++ Demos
8794
timeout-minutes: 20
8895
working-directory: ice-demos/cpp
89-
run: find . -name CMakeLists.txt -type d -execdir cmake --build build ";"
96+
run: |
97+
Get-ChildItem -Recurse -Filter CMakeLists.txt | ForEach-Object {
98+
$dir = $_.DirectoryName
99+
cmake -B "$dir/build" -S "$dir" -DIce_DEBUG=ON
100+
cmake --build "$dir/build" --config Release
101+
}
102+
if: runner.os == 'Windows'
90103

91-
- name: Build C# Demos on ${{ matrix.os }}
104+
- name: Build C# Demos
92105
timeout-minutes: 20
93106
working-directory: ice-demos/csharp
94107
run: dotnet build
@@ -97,7 +110,7 @@ jobs:
97110
run: dotnet format --verify-no-changes "./ice-demos/csharp/C# NET demos.sln"
98111
if: runner.os == 'Linux'
99112

100-
- name: Build Java Demos on ${{ matrix.os }}
113+
- name: Build Java Demos
101114
timeout-minutes: 20
102115
working-directory: ice-demos/java
103116
env:
@@ -106,7 +119,7 @@ jobs:
106119
CPP_CONFIGURATION: Release
107120
run: ./gradlew build
108121

109-
- name: Build JavaScript Demos on ${{ matrix.os }}
122+
- name: Build JavaScript Demos
110123
timeout-minutes: 20
111124
working-directory: ice-demos/js
112125
env:
@@ -117,8 +130,12 @@ jobs:
117130
npm install
118131
npx gulp build
119132
120-
- name: Build Swift Demos on ${{ matrix.os }}
133+
- name: Build Swift Demos
121134
timeout-minutes: 20
122135
working-directory: ice-demos/swift
123-
run: find . -name Package.swift -execdir swift build \;
136+
run: |
137+
set -o pipefail
138+
find . -name Package.swift -type f | while IFS= read -r file; do
139+
swift build --package-path "$(dirname "$file")"
140+
done
124141
if: runner.os == 'macOS'

.github/workflows/cpp.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
2828
- name: Run Clang Format
2929
run: |
30+
set -o pipefail
3031
find . -name "*.h" -o -name "*.cpp" | xargs clang-format-19 --style=file --fallback-style=none --Werror --dry-run
3132
3233
clang-tidy:
@@ -72,10 +73,18 @@ jobs:
7273
timeout-minutes: 30
7374
working-directory: ice-demos/cpp
7475
run: |
75-
find . -name CMakeLists.txt -execdir cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DIce_DEBUG=ON \;
76-
find . -name CMakeLists.txt -execdir cmake --build build --config Release \;
76+
set -o pipefail
77+
find . -name CMakeLists.txt -type f | while IFS= read -r file; do
78+
dir=$(dirname "$file");
79+
cmake -B "$dir/build" -S "$dir" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DIce_DEBUG=ON
80+
cmake --build "$dir/build" --config Release
81+
done
7782
7883
- name: Run Clang Tidy
7984
working-directory: ice-demos/cpp
8085
run: |
81-
find . -name compile_commands.json -execdir run-clang-tidy-19 -j$(nproc) -quiet \;
86+
set -o pipefail
87+
find . -name compile_commands.json -type f | while IFS= read -r file; do
88+
dir=$(dirname "$file");
89+
run-clang-tidy-19 -p "$dir" -j$(nproc) -quiet
90+
done

cpp/cmake/IceConfig.cmake

Lines changed: 156 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
if (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}")
1112
endif()
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)
1721
endif()
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()
2745
endif()
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")
3150
endif()
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()
4073
endif()
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()
74173
endif()
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()
115224
endfunction()
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

Comments
 (0)