Skip to content

Commit 2185198

Browse files
committed
Use conan for deps
1 parent e72945f commit 2185198

File tree

10 files changed

+170
-577
lines changed

10 files changed

+170
-577
lines changed

.github/workflows/cmake.yml

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ env:
66
BUILD_TYPE: Release
77
EM_VERSION: 3.1.35
88
EM_CACHE_FOLDER: 'emsdk-cache'
9+
CONAN_USER_HOME: "conan"
910

1011
jobs:
1112
build:
1213
strategy:
1314
fail-fast: false
1415
matrix:
1516
platform:
16-
- { name: Ubuntu GCC, os: ubuntu-latest, compiler: g++, arch: "64", cmakepp: "", suffix: "", flags: "-DCMAKE_CXX_COMPILER=g++"}
17-
- { name: Ubuntu Clang, os: ubuntu-latest, compiler: clang++, arch: "64", cmakepp: "", suffix: "", flags: "-DCMAKE_CXX_COMPILER=clang++"}
18-
- { name: Windows 32, os: windows-latest, compiler: vs2019, arch: "32", cmakepp: "", suffix: "", flags: "-DCMAKE_PREFIX_PATH=`pwd`/../dependencies -A Win32"}
19-
- { name: Windows 64, os: windows-latest, compiler: vs2019, arch: "64", cmakepp: "", suffix: "", flags: "-DCMAKE_PREFIX_PATH=`pwd`/../dependencies -A x64"}
20-
- { name: MacOS, os: macos-latest, compiler: clang++, arch: "64", cmakepp: "", suffix: "", flags: "-DCMAKE_PREFIX_PATH=/opt/homebrew/opt/sfml@2"}
21-
- { name: WebAssembly, os: ubuntu-latest, compiler: em++, arch: "32", cmakepp: "emcmake", suffix: "-emscripten", flags: "-DCMAKE_PREFIX_PATH=`pwd`/../dependencies -DCMAKE_FIND_ROOT_PATH=/ -DLXGUI_TEST_IMPLEMENTATION=OPENGL_SDL"}
17+
- { name: Ubuntu GCC, os: ubuntu-latest, compiler: g++, arch: "64", cmakepp: "", suffix: "", flags: ""}
18+
- { name: Ubuntu Clang, os: ubuntu-latest, compiler: clang++, arch: "64", cmakepp: "", suffix: "", flags: ""}
19+
- { name: Windows 32, os: windows-latest, compiler: vs2019, arch: "32", cmakepp: "", suffix: "", flags: "-A Win32"}
20+
- { name: Windows 64, os: windows-latest, compiler: vs2019, arch: "64", cmakepp: "", suffix: "", flags: "-A x64"}
21+
- { name: MacOS, os: macos-latest, compiler: clang++, arch: "64", cmakepp: "", suffix: "", flags: ""}
22+
- { name: WebAssembly, os: ubuntu-latest, compiler: em++, arch: "32", cmakepp: "emcmake", suffix: "-emscripten", flags: "-DCMAKE_FIND_ROOT_PATH=/ -DLXGUI_TEST_IMPLEMENTATION=OPENGL_SDL"}
2223

2324
name: ${{matrix.platform.name}}
2425
runs-on: ${{matrix.platform.os}}
@@ -31,15 +32,27 @@ jobs:
3132

3233
- name: Setup Clang
3334
if: matrix.platform.compiler == 'clang++' && matrix.platform.os == 'ubuntu-latest'
34-
run: sudo apt install clang
35+
run:
36+
sudo apt install clang
37+
echo "CC=clang" >> $GITHUB_ENV
38+
echo "CXX=clang++" >> $GITHUB_ENV
3539

36-
- name: Setup Emscripten cache
37-
if: matrix.platform.compiler == 'em++'
38-
id: cache-system-libraries
40+
- name: Setup Conan cache
41+
if: matrix.platform.compiler != 'em++'
42+
id: cache-conan-packages
3943
uses: actions/cache@v4
4044
with:
41-
path: ${{env.EM_CACHE_FOLDER}}
42-
key: ${{env.EM_VERSION}}-${{matrix.platform.name}}-${{matrix.build-type}}
45+
path: ${{env.CONAN_USER_HOME}}
46+
key: ${{matrix.platform.name}}-${{matrix.compiler}}
47+
48+
- name: Get Conan dependencies
49+
if: matrix.platform.compiler != 'em++'
50+
shell: bash
51+
run:
52+
pip install conan
53+
conan profile detect --force
54+
conan create conan/observable_unique_ptr
55+
sudo conan install . --build=missing -c tools.system.package_manager:mode=install -c tools.system.package_manager:sudo=true --output-folder dependencies
4356

4457
- name: Setup Emscripten
4558
if: matrix.platform.compiler == 'em++'
@@ -51,35 +64,16 @@ jobs:
5164
- name: Create Build Environment
5265
run: cmake -E make_directory ${{github.workspace}}/build
5366

54-
- name: Get Linux dependencies
55-
if: runner.os == 'Linux' && matrix.platform.compiler != 'em++'
56-
run: |
57-
sudo apt-get update
58-
sudo apt-get install libz-dev libpng-dev libfreetype6-dev libglew-dev libglu1-mesa-dev libsfml-dev liblua5.2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-dev
59-
6067
- name: Get Emscripten dependencies
6168
if: matrix.platform.compiler == 'em++'
6269
shell: bash
6370
working-directory: ${{github.workspace}}/dependencies
6471
run: unzip wasm.zip
6572

66-
- name: Get Windows dependencies
67-
if: runner.os == 'Windows'
68-
# Ideally (but too slow):
69-
#run: vcpkg install sfml lua zlib libpng freetype glew sdl2 sdl2-ttf sdl2-image
70-
# Pre-compiled dependencies:
71-
shell: bash
72-
working-directory: ${{github.workspace}}/dependencies
73-
run: unzip windows-dependencies-${{matrix.platform.compiler}}-${{matrix.platform.arch}}.zip
74-
75-
- name: Get MacOS dependencies
76-
if: runner.os == 'macOS'
77-
run: brew install sfml@2 lua libpng freetype glew sdl2 sdl2_ttf sdl2_image
78-
7973
- name: Configure CMake
8074
shell: bash
8175
working-directory: ${{github.workspace}}/build
82-
run: ${{matrix.platform.cmakepp}} cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLXGUI_BUILD_EXAMPLES=0 -DCMAKE_INSTALL_PREFIX=`pwd`/../dependencies ${{matrix.platform.flags}}
76+
run: ${{matrix.platform.cmakepp}} cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLXGUI_BUILD_EXAMPLES=0 -DCMAKE_PREFIX_PATH=`pwd`/../dependencies -DCMAKE_INSTALL_PREFIX=`pwd`/../dependencies ${{matrix.platform.flags}}
8377

8478
- name: Build
8579
shell: bash

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ doc/*.log
1212
compile_commands.json
1313
dependencies/lib
1414
dependencies/include
15+
dependencies/*.cmake
16+
dependencies/CMake*
17+
dependencies/*conan*
1518
include/lxgui/lxgui.hpp
19+
.cache

CMakeLists.txt

Lines changed: 34 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ lxgui_set_option(LXGUI_BUILD_RAPIDYAML TRUE BOOL "Build the rapidyaml dependency
3636
lxgui_set_option(LXGUI_ENABLE_XML_PARSER TRUE BOOL "Enable the XML layout parser (if false, XML layout files cannot be read)")
3737
lxgui_set_option(LXGUI_ENABLE_YAML_PARSER TRUE BOOL "Enable the YAML layout parser (if false, YAML layout files cannot be read)")
3838
lxgui_set_option(LXGUI_TEST_IMPLEMENTATION "SFML" STRING "Which implementation to test (SFML/SDL/OPENGL_SFML/OPENGL_SDL)")
39+
lxgui_set_option(LXGUI_DEV FALSE BOOL "Enable compiler options for development (warnings etc), not recommended for release")
3940

4041
# project name
4142
project(lxgui LANGUAGES CXX VERSION 2.0)
@@ -48,36 +49,10 @@ project(lxgui LANGUAGES CXX VERSION 2.0)
4849
if(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
4950
set(LXGUI_COMPILER_EMSCRIPTEN TRUE)
5051
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
51-
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpfullversion -dumpversion
52-
OUTPUT_VARIABLE GCC_VERSION)
53-
54-
string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
55-
list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
56-
list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
57-
set(GCC_VERSION ${GCC_MAJOR}.${GCC_MINOR})
58-
59-
if(GCC_VERSION VERSION_LESS 8.0)
60-
message(ERROR ": lxgui requires advanced features from the C++17 norm that are only available with gcc 8 or higher (your version: ${GCC_VERSION}). Please upgrade your compiler.")
61-
endif()
62-
6352
set(LXGUI_COMPILER_GCC TRUE)
6453
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
65-
if(MSVC_VERSION VERSION_LESS 1910)
66-
message(ERROR ": lxgui requires advanced features from the C++17 norm that are only available with MSVC 2017 or higher (version 1910, your version: ${MSVC_VERSION}). Please upgrade your compiler.")
67-
endif()
68-
6954
set(LXGUI_COMPILER_MSVC TRUE)
7055
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
71-
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
72-
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
73-
message(ERROR ": lxgui requires advanced features from the C++17 norm that are only available with Xcode 11 or higher (your version: ${CMAKE_CXX_COMPILER_VERSION}). Please upgrade your compiler.")
74-
endif()
75-
else()
76-
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)
77-
message(ERROR ": lxgui requires advanced features from the C++17 norm that are only available with clang 7 or higher (your version: ${CMAKE_CXX_COMPILER_VERSION}). Please upgrade your compiler.")
78-
endif()
79-
endif()
80-
8156
set(LXGUI_COMPILER_CLANG TRUE)
8257
else()
8358
message(WARNING "Warning: your compiler has not been setup by the CMake script, do not expect it to work")
@@ -165,11 +140,22 @@ endif()
165140
##############################################################################
166141

167142
# find dependencies
168-
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
169-
170143
find_package(Lua REQUIRED)
144+
find_package(sol2 REQUIRED)
145+
find_package(utf8cpp REQUIRED)
146+
find_package(oup REQUIRED)
147+
find_package(fmt REQUIRED)
148+
find_package(magic_enum REQUIRED)
149+
171150
find_package(Freetype)
172151

152+
if(LXGUI_ENABLE_XML_PARSER)
153+
find_package(pugixml REQUIRED)
154+
endif()
155+
if(LXGUI_ENABLE_YAML_PARSER)
156+
find_package(ryml REQUIRED)
157+
endif()
158+
173159
if(NOT LXGUI_COMPILER_EMSCRIPTEN)
174160
find_package(PNG)
175161
find_package(ZLIB)
@@ -181,58 +167,13 @@ if(NOT LXGUI_COMPILER_EMSCRIPTEN)
181167
find_package(SDL2_ttf)
182168
endif()
183169

170+
# configure
184171
if (LUA_VERSION_STRING VERSION_GREATER_EQUAL 5.1 AND LUA_VERSION_STRING VERSION_LESS 5.2)
185172
set(LXGUI_LUA51 TRUE)
186173
endif()
187174

188-
# add the subdirectories for dependencies
189-
add_subdirectory(extern/utfcpp)
190-
191-
add_subdirectory(extern/observable_unique_ptr)
192-
193-
set(MAGIC_ENUM_OPT_INSTALL 1)
194-
add_subdirectory(extern/magic_enum)
195-
196-
if(LXGUI_BUILD_FMT)
197-
set(FMT_INSTALL TRUE)
198-
add_subdirectory(extern/fmt)
199-
else()
200-
find_package(fmt REQUIRED)
201-
endif()
202-
203-
if(LXGUI_ENABLE_XML_PARSER)
204-
if(LXGUI_BUILD_PUGIXML)
205-
add_subdirectory(extern/pugixml)
206-
else()
207-
find_package(pugixml)
208-
if(NOT TARGET pugixml::pugixml)
209-
message(ERROR ": the XML parser requires pugixml, which is missing. XML parsing will be disabled.")
210-
set(LXGUI_ENABLE_XML_PARSER FALSE)
211-
endif()
212-
endif()
213-
endif()
214-
215-
if(LXGUI_ENABLE_YAML_PARSER)
216-
if(LXGUI_BUILD_RAPIDYAML)
217-
add_subdirectory(extern/rapidyaml)
218-
else()
219-
find_package(ryml)
220-
if(NOT TARGET ryml::ryml)
221-
message(ERROR ": the YAML parser requires rapidyaml, which is missing. YAML parsing will be disabled.")
222-
set(LXGUI_ENABLE_YAML_PARSER FALSE)
223-
endif()
224-
endif()
225-
endif()
226-
227175
set(SOL_ALL_SAFETIES_ON TRUE)
228176
set(SOL_PRINT_ERRORS FALSE)
229-
if(LXGUI_BUILD_SOL2)
230-
set(SOL2_BUILD_LUA FALSE CACHE BOOL "")
231-
set(SOL2_ENABLE_INSTALL TRUE)
232-
add_subdirectory(extern/sol2)
233-
else()
234-
find_package(sol2 REQUIRED)
235-
endif()
236177

237178
##############################################################################
238179
# Main library
@@ -320,13 +261,14 @@ add_library(lxgui::lxgui ALIAS lxgui)
320261
target_compile_features(lxgui PUBLIC cxx_std_17)
321262

322263
# compilation options
323-
lxgui_set_warning_level(lxgui)
264+
if(LXGUI_DEV)
265+
lxgui_set_warning_level(lxgui)
266+
endif()
324267
target_include_directories(lxgui PUBLIC
325268
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
326269
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
327270

328271
# needed dependencies
329-
target_link_libraries(lxgui PUBLIC Lua::Lua)
330272
target_link_libraries(lxgui PUBLIC sol2::sol2)
331273
target_link_libraries(lxgui PUBLIC fmt::fmt)
332274
target_link_libraries(lxgui PUBLIC oup::oup)
@@ -361,7 +303,7 @@ file(GLOB files ${PROJECT_SOURCE_DIR}/include/lxgui/*.hpp)
361303
install(FILES ${files} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/lxgui)
362304
install(FILES "${PROJECT_BINARY_DIR}/lxgui/lxgui.hpp" DESTINATION ${CMAKE_INSTALL_PREFIX}/include/lxgui)
363305

364-
set(LXGUI_INSTALL_TARGETS lxgui utf8cpp)
306+
set(LXGUI_INSTALL_TARGETS lxgui)
365307

366308
##############################################################################
367309
# Back-ends
@@ -371,46 +313,39 @@ if(LXGUI_BUILD_GUI_GL_IMPL)
371313
if((OPENGL_FOUND AND GLEW_FOUND AND FREETYPE_FOUND AND PNG_FOUND AND ZLIB_FOUND) OR LXGUI_COMPILER_EMSCRIPTEN)
372314
add_subdirectory(impl/gui/gl)
373315
else()
374-
message(ERROR ": the OpenGL implementation of the GUI requires OpenGL, GLEW, freetype, libpng and zlib")
375-
set(LXGUI_BUILD_GUI_GL_IMPL FALSE)
316+
message(SEND_ERROR ": the OpenGL implementation of the GUI requires OpenGL, GLEW, freetype, libpng and zlib")
376317
endif()
377318
endif()
378319
if(LXGUI_BUILD_GUI_SFML_IMPL)
379320
if(LXGUI_COMPILER_EMSCRIPTEN)
380-
message(ERROR ": the SFML implementation of the GUI is not supported with Emscripten")
381-
set(LXGUI_BUILD_GUI_SFML_IMPL FALSE)
321+
message(SEND_ERROR ": the SFML implementation of the GUI is not supported with Emscripten")
382322
elseif(SFML_FOUND)
383323
add_subdirectory(impl/gui/sfml)
384324
else()
385-
message(ERROR ": the SFML implementation of the GUI requires the SFML library")
386-
set(LXGUI_BUILD_GUI_SFML_IMPL FALSE)
325+
message(SEND_ERROR ": the SFML implementation of the GUI requires the SFML library")
387326
endif()
388327
endif()
389328
if(LXGUI_BUILD_INPUT_SFML_IMPL)
390329
if(LXGUI_COMPILER_EMSCRIPTEN)
391-
message(ERROR ": the SFML implementation of the input is not supported with Emscripten")
392-
set(LXGUI_BUILD_INPUT_SFML_IMPL FALSE)
330+
message(SEND_ERROR ": the SFML implementation of the input is not supported with Emscripten")
393331
elseif(SFML_FOUND)
394332
add_subdirectory(impl/input/sfml)
395333
else()
396-
message(ERROR ": the SFML implementation of the input requires the SFML library")
397-
set(LXGUI_BUILD_INPUT_SFML_IMPL FALSE)
334+
message(SEND_ERROR ": the SFML implementation of the input requires the SFML library")
398335
endif()
399336
endif()
400337
if(LXGUI_BUILD_GUI_SDL_IMPL)
401-
if((SDL2_FOUND AND SDL2_TTF_FOUND AND SDL2_IMAGE_FOUND) OR LXGUI_COMPILER_EMSCRIPTEN)
338+
if((SDL2_FOUND AND SDL2_ttf_FOUND AND SDL2_image_FOUND) OR LXGUI_COMPILER_EMSCRIPTEN)
402339
add_subdirectory(impl/gui/sdl)
403340
else()
404-
message(ERROR ": the SDL implementation of the GUI requires the SDL2, SDL2_ttf, and SDL2_image libraries")
405-
set(LXGUI_BUILD_GUI_SDL_IMPL FALSE)
341+
message(SEND_ERROR ": the SDL implementation of the GUI requires the SDL2, SDL2_ttf, and SDL2_image libraries")
406342
endif()
407343
endif()
408344
if(LXGUI_BUILD_INPUT_SDL_IMPL)
409345
if(SDL2_FOUND OR LXGUI_COMPILER_EMSCRIPTEN)
410346
add_subdirectory(impl/input/sdl)
411347
else()
412-
message(ERROR ": the SDL implementation of the input requires the SDL library")
413-
set(LXGUI_BUILD_INPUT_SDL_IMPL FALSE)
348+
message(SEND_ERROR ": the SDL implementation of the input requires the SDL library")
414349
endif()
415350
endif()
416351

@@ -474,9 +409,6 @@ write_basic_package_version_file(
474409
install(FILES
475410
"${PROJECT_BINARY_DIR}/lxgui-config.cmake"
476411
"${PROJECT_BINARY_DIR}/lxgui-config-version.cmake"
477-
"${PROJECT_SOURCE_DIR}/cmake/FindLua.cmake"
478-
"${PROJECT_SOURCE_DIR}/cmake/FindSDL2_image.cmake"
479-
"${PROJECT_SOURCE_DIR}/cmake/FindSDL2_ttf.cmake"
480412
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lxgui COMPONENT Development)
481413

482414
##############################################################################
@@ -485,34 +417,35 @@ install(FILES
485417

486418
if(LXGUI_BUILD_TEST)
487419
if(LXGUI_COMPILER_EMSCRIPTEN AND NOT (LXGUI_TEST_IMPLEMENTATION STREQUAL "SDL" OR LXGUI_TEST_IMPLEMENTATION STREQUAL "OPENGL_SDL"))
488-
message(WARNING "Warning: the test program only supports SDL or OPENGL_SDL when compiled with Emscripten")
420+
message(WARNING ": the test program only supports SDL or OPENGL_SDL when compiled with Emscripten")
489421
set(LXGUI_TEST_IMPLEMENTATION "SDL")
490422
endif()
423+
491424
if(LXGUI_TEST_IMPLEMENTATION STREQUAL "OPENGL_SFML")
492425
if(OPENGL_FOUND AND GLEW_FOUND AND FREETYPE_FOUND AND PNG_FOUND AND ZLIB_FOUND AND SFML_FOUND)
493426
add_subdirectory(test)
494427
else()
495-
message(ERROR ": the test program requires OpenGL, GLEW, freetype, libpng, zlib and SFML.")
428+
message(SEND_ERROR ": the test program requires OpenGL, GLEW, freetype, libpng, zlib and SFML.")
496429
endif()
497430
elseif(LXGUI_TEST_IMPLEMENTATION STREQUAL "OPENGL_SDL")
498431
if((OPENGL_FOUND AND GLEW_FOUND AND FREETYPE_FOUND AND PNG_FOUND AND ZLIB_FOUND AND SDL2_FOUND) OR LXGUI_COMPILER_EMSCRIPTEN)
499432
add_subdirectory(test)
500433
else()
501-
message(ERROR ": the test program requires OpenGL, GLEW, freetype, libpng, zlib and SDL.")
434+
message(SEND_ERROR ": the test program requires OpenGL, GLEW, freetype, libpng, zlib and SDL.")
502435
endif()
503436
elseif(LXGUI_TEST_IMPLEMENTATION STREQUAL "SDL")
504437
if((SDL2_FOUND AND SDL2_TTF_FOUND AND SDL2_IMAGE_FOUND) OR LXGUI_COMPILER_EMSCRIPTEN)
505438
add_subdirectory(test)
506439
else()
507-
message(ERROR ": the test program requires SDL2, SDL2_ttf, and SDL2_image.")
440+
message(SEND_ERROR ": the test program requires SDL2, SDL2_ttf, and SDL2_image.")
508441
endif()
509442
elseif(LXGUI_TEST_IMPLEMENTATION STREQUAL "SFML")
510443
if(SFML_FOUND)
511444
add_subdirectory(test)
512445
else()
513-
message(ERROR ": the test program requires SFML.")
446+
message(SEND_ERROR ": the test program requires SFML.")
514447
endif()
515448
else()
516-
message(ERROR ": unknown implementation ${LXGUI_TEST_IMPLEMENTATION}")
449+
message(SEND_ERROR ": unknown implementation ${LXGUI_TEST_IMPLEMENTATION}")
517450
endif()
518451
endif()

0 commit comments

Comments
 (0)