Skip to content

Commit 521eff9

Browse files
committed
Add GitHub Action to build with CMake on Windows, Linux and macOS.
1 parent 2c56f50 commit 521eff9

File tree

9 files changed

+250
-12
lines changed

9 files changed

+250
-12
lines changed

.github/workflows/build.cmake

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
2+
execute_process(COMMAND "${CMAKE_COMMAND}" --build "$ENV{GITHUB_WORKSPACE}/cmake-build"
3+
--config $ENV{BUILD_TYPE}
4+
5+
RESULT_VARIABLE result
6+
)
7+
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
8+
execute_process(COMMAND "${CMAKE_COMMAND}" --build "$ENV{GITHUB_WORKSPACE}/cmake-build"
9+
-- -j 3
10+
11+
RESULT_VARIABLE result
12+
)
13+
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
14+
execute_process(COMMAND "${CMAKE_COMMAND}" --build "$ENV{GITHUB_WORKSPACE}/cmake-build"
15+
--config $ENV{BUILD_TYPE}
16+
-- -j 5
17+
18+
RESULT_VARIABLE result
19+
)
20+
endif()
21+
22+
if(NOT result EQUAL 0)
23+
message(FATAL_ERROR "CMake returned bad exit status")
24+
endif()

.github/workflows/build_cmake.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CMake Build
2+
3+
on: [ push, pull_request ]
4+
5+
env:
6+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
7+
BUILD_TYPE: Release
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ windows-latest, ubuntu-latest, macos-latest ]
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Install Prerequisites
22+
run: cmake -P ${{ github.workspace }}/.github/workflows/install_prerequisites.cmake
23+
24+
- name: Configure CMake
25+
run: cmake -P ${{ github.workspace }}/.github/workflows/configure.cmake
26+
27+
- name: Build
28+
run: cmake -P ${{ github.workspace }}/.github/workflows/build.cmake
29+
30+
- name: Package
31+
run: cmake -P ${{ github.workspace }}/.github/workflows/package.cmake
32+
33+
- name: Upload Artifact
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: ${{ matrix.os }}
37+
path: package/projectM-*

.github/workflows/configure.cmake

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
2+
execute_process(COMMAND "${CMAKE_COMMAND}"
3+
-G "Visual Studio 16 2019"
4+
-A "X64"
5+
-S "$ENV{GITHUB_WORKSPACE}"
6+
-B "$ENV{GITHUB_WORKSPACE}/cmake-build"
7+
-DTARGET_TRIPLET=x64-windows
8+
-DCMAKE_VERBOSE_MAKEFILE=YES
9+
"-DCMAKE_INSTALL_PREFIX=$ENV{GITHUB_WORKSPACE}/cmake-install"
10+
"-DCMAKE_TOOLCHAIN_FILE=$ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake"
11+
12+
RESULT_VARIABLE result
13+
)
14+
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
15+
execute_process(COMMAND "${CMAKE_COMMAND}"
16+
-G "Unix Makefiles"
17+
-S "$ENV{GITHUB_WORKSPACE}"
18+
-B "$ENV{GITHUB_WORKSPACE}/cmake-build"
19+
-DCMAKE_VERBOSE_MAKEFILE=YES
20+
-DCMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
21+
"-DCMAKE_INSTALL_PREFIX=$ENV{GITHUB_WORKSPACE}/cmake-install"
22+
23+
RESULT_VARIABLE result
24+
)
25+
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
26+
execute_process(COMMAND "${CMAKE_COMMAND}"
27+
-G "Unix Makefiles"
28+
-S "$ENV{GITHUB_WORKSPACE}"
29+
-B "$ENV{GITHUB_WORKSPACE}/cmake-build"
30+
-DCMAKE_VERBOSE_MAKEFILE=YES
31+
"-DCMAKE_INSTALL_PREFIX=$ENV{GITHUB_WORKSPACE}/cmake-install"
32+
33+
RESULT_VARIABLE result
34+
)
35+
endif()
36+
37+
if(NOT result EQUAL 0)
38+
message(FATAL_ERROR "CMake returned bad exit status")
39+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
message(STATUS "Using host CMake version: ${CMAKE_VERSION}")
2+
3+
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
4+
# On Windows, using vcpkg to install and build is the best practice.
5+
set(VCPKG "$ENV{VCPKG_INSTALLATION_ROOT}/vcpkg.exe")
6+
execute_process(COMMAND "${VCPKG}" --triplet=x64-windows install glew sdl2
7+
8+
RESULT_VARIABLE result
9+
)
10+
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
11+
# On Ubuntu, installing the required dev packages is sufficient
12+
message(STATUS "Updating apt package sources")
13+
execute_process(COMMAND sudo apt-get update
14+
COMMAND sudo apt-get -f install
15+
16+
RESULT_VARIABLE result
17+
)
18+
19+
if(NOT result EQUAL 0)
20+
message(FATAL_ERROR "Could not update apt package lists")
21+
endif()
22+
23+
execute_process(COMMAND sudo apt-get install
24+
libgl1-mesa-dev
25+
mesa-common-dev
26+
libsdl2-dev
27+
libglm-dev
28+
qtbase5-dev
29+
llvm-dev
30+
libvisual-0.4-dev
31+
libjack-jackd2-dev
32+
33+
RESULT_VARIABLE result
34+
)
35+
36+
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
37+
# macOS uses Homebrew to install additional software packages.
38+
execute_process(COMMAND brew update
39+
COMMAND brew install sdl2
40+
41+
RESULT_VARIABLE result
42+
)
43+
endif()
44+
45+
if(NOT result EQUAL 0)
46+
message(FATAL_ERROR "A command returned bad exit status")
47+
endif()

.github/workflows/package.cmake

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
2+
execute_process(COMMAND "${CMAKE_CPACK_COMMAND}"
3+
-G ZIP
4+
--config "$ENV{GITHUB_WORKSPACE}/cmake-build/CPackConfig.cmake"
5+
-B "$ENV{GITHUB_WORKSPACE}/package"
6+
7+
RESULT_VARIABLE result
8+
)
9+
else("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
10+
execute_process(COMMAND "${CMAKE_CPACK_COMMAND}"
11+
-G TGZ
12+
--config "$ENV{GITHUB_WORKSPACE}/cmake-build/CPackConfig.cmake"
13+
-B "$ENV{GITHUB_WORKSPACE}/package"
14+
15+
RESULT_VARIABLE result
16+
)
17+
endif()
18+
19+
if(NOT result EQUAL 0)
20+
message(FATAL_ERROR "CPack returned bad exit status")
21+
endif()

CMakeLists.txt

+7-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,8 @@ endif()
7373
if(ENABLE_SDL)
7474
find_package(SDL2 REQUIRED)
7575

76-
# Temporary fix to deal with wrong include dir set by SDL2's CMake configuration.
77-
get_target_property(_SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
78-
if(_SDL2_INCLUDE_DIR MATCHES "(.+)/SDL2\$")
79-
message(STATUS "SDL2 include dir contains \"SDL2\" subdir (SDL bug #4004) - fixing to \"${CMAKE_MATCH_1}\".")
80-
set_target_properties(SDL2::SDL2 PROPERTIES
81-
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_MATCH_1}"
82-
)
83-
endif()
84-
85-
if(SDL2_VERSION VERSION_LESS "2.0.5")
86-
message(FATAL_ERROR "SDL2 libraries were found, but have version ${SDL2_VERSION}. At least version 2.0.5 is required.")
87-
endif()
76+
# Apply some fixes, as SDL2's CMake support is new and still a WiP.
77+
include(SDL2Target)
8878
endif()
8979

9080
if(ENABLE_GLES)
@@ -197,3 +187,8 @@ message(AUTHOR_WARNING
197187
"fully supported.\n"
198188
"DO NOT base any production work on it yet!\n"
199189
)
190+
191+
# Create CPack configuration
192+
set(CPACK_PACKAGE_NAME "projectM")
193+
set(CPACK_VERBATIM_VARIABLES YES)
194+
include(CPack)

cmake/FindGLES3.cmake

Whitespace-only changes.

cmake/SDL2Target.cmake

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Helper script to add the SDL2 CMake target and version variable as introduced in SDL 2.0.12.
2+
# Also fixes a wrong include path provided by the SDL2 config script.
3+
4+
5+
# Proper CMake target support was added in SDL 2.0.12, create one
6+
# Need to search again to find the full path of libSDL2
7+
if(NOT TARGET SDL2::SDL2)
8+
# Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
9+
# This may require "libdir" being set (from above)
10+
string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS " -lSDL2 ")
11+
string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
12+
string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC " -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lpulse-simple -lpulse -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt ")
13+
string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
14+
15+
find_library(SDL2_LIBRARY SDL2)
16+
if(NOT SDL2_LIBRARY)
17+
message(FATAL_ERROR "Could not determine the location of the SDL2 library.")
18+
endif()
19+
20+
add_library(SDL2::SDL2 SHARED IMPORTED)
21+
set_target_properties(SDL2::SDL2 PROPERTIES
22+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
23+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
24+
IMPORTED_LOCATION "${SDL2_LIBRARY}"
25+
INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
26+
27+
find_library(SDL2MAIN_LIBRARY SDL2main)
28+
if(NOT SDL2MAIN_LIBRARY)
29+
message(FATAL_ERROR "Could not determine the location of the SDL2main library.")
30+
endif()
31+
32+
add_library(SDL2::SDL2main STATIC IMPORTED)
33+
set_target_properties(SDL2::SDL2main PROPERTIES
34+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
35+
IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}")
36+
37+
# Retrieve the version from the SDL2_version.h header
38+
if(SDL2_INCLUDE_DIRS AND EXISTS "${SDL2_INCLUDE_DIRS}/SDL_version.h")
39+
file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
40+
file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
41+
file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
42+
string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}")
43+
string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}")
44+
string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}")
45+
set(SDL2_VERSION ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH})
46+
unset(SDL_VERSION_MAJOR_LINE)
47+
unset(SDL_VERSION_MINOR_LINE)
48+
unset(SDL_VERSION_PATCH_LINE)
49+
unset(SDL_VERSION_MAJOR)
50+
unset(SDL_VERSION_MINOR)
51+
unset(SDL_VERSION_PATCH)
52+
endif()
53+
54+
endif()
55+
56+
# Temporary fix to deal with wrong include dir set by SDL2's CMake configuration.
57+
get_target_property(_SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
58+
if(_SDL2_INCLUDE_DIR MATCHES "(.+)/SDL2\$")
59+
message(STATUS "SDL2 include dir contains \"SDL2\" subdir (SDL bug #4004) - fixing to \"${CMAKE_MATCH_1}\".")
60+
set_target_properties(SDL2::SDL2 PROPERTIES
61+
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_MATCH_1}"
62+
)
63+
endif()
64+
65+
if(SDL2_VERSION AND SDL2_VERSION VERSION_LESS "2.0.5")
66+
message(FATAL_ERROR "SDL2 libraries were found, but have version ${SDL2_VERSION}. At least version 2.0.5 is required.")
67+
endif()
68+

src/libprojectM/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ target_include_directories(projectM_main
9292
"${MSVC_EXTRA_INCLUDE_DIR}"
9393
)
9494

95+
target_link_libraries(projectM_main
96+
PRIVATE
97+
GLM::GLM
98+
PUBLIC
99+
${PROJECTM_OPENGL_LIBRARIES}
100+
)
101+
95102
add_library(projectM_static STATIC
96103
$<TARGET_OBJECTS:projectM_main>
97104
$<TARGET_OBJECTS:MilkdropPresetFactory>

0 commit comments

Comments
 (0)