I have a game I develop in Arch Linux. I use CMake to generate the build files for the game level code and the other libraries. I use ExternalProject_Add to generate the build files for the libraries.
For the longest time this worked fine. I can also build my game on the Raspberry PI. Haven’t work on the game for a few years. On my current Arch Linux I discovered it no longer works. The same CMakelists.txt files work on my old PI 4.
From the game folder within the build folder I call
cmake -DCMAKE_BUILD_TYPE=Debug …
This generates the build files in the game folder and empty build folders in the library folders. Then when I call “cmake --build .” it would generate the build files in the build folders of each of the libraries and start building the libraries. This is how it used to work.
In the current version (3.31.0) “cmake --build .” does not generate the build files so the libraries can’t be compiled. From a console, I can manually generate the build files in the libraries and then compile them all from the game folder. My PI 4 has CMake 3.16.3 and works as expected. If I call the command cmake --build . --parallel -j, it will build the files.
Something has changed or I’ve been lucky with an error in my CMakelists.txt files. I’ve been trying to solve this problem for a while now and decide to finally post the issue. Thanks for your help in advance.
This is the CMakelists.txt in the game folder. This gets called first.
cmake_minimum_required(VERSION 3.10)
include(ExternalProject)
project(gametemplate VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -std=c++17 -Wall -pthread")
# Use the normal means to find the other packages
find_package(Vulkan REQUIRED)
# Add the game level executable files
add_executable(
${PROJECT_NAME}
source/game/game.cpp
source/game/main.cpp
source/state/commonstate.cpp
source/state/startupstate.cpp
source/state/titlescreenstate.cpp
source/state/loadstate.cpp
source/state/level1state.cpp
)
# Create library specific path variables
get_filename_component(PARENT_SOURCE_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
set(bulletPhysics_SOURCE_DIR ${PARENT_SOURCE_DIR}/bulletPhysics)
set(Box2D_SOURCE_DIR ${PARENT_SOURCE_DIR}/Box2D)
set(angelscript_SOURCE_DIR ${PARENT_SOURCE_DIR}/angelscript)
set(library_SOURCE_DIR ${PARENT_SOURCE_DIR}/library)
# ExternalProject_Add cmake files are generated during the build command
# Add the external project library.
ExternalProject_Add(
library
SOURCE_DIR ${library_SOURCE_DIR}
BINARY_DIR ${library_SOURCE_DIR}/build
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
BUILD_ALWAYS 1
)
# Add the external project Bullet Physics.
ExternalProject_Add(
bulletPhysics
SOURCE_DIR ${bulletPhysics_SOURCE_DIR}
BINARY_DIR ${bulletPhysics_SOURCE_DIR}/build
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
# Add the external project Box2D.
ExternalProject_Add(
Box2D
SOURCE_DIR ${Box2D_SOURCE_DIR}
BINARY_DIR ${Box2D_SOURCE_DIR}/build
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
# Add the external project angelscript.
ExternalProject_Add(
angelscript
SOURCE_DIR ${angelscript_SOURCE_DIR}
BINARY_DIR ${angelscript_SOURCE_DIR}/build
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch64")
set(SDL_LIB_DIR /usr/lib/aarch64-linux-gnu/)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
set(SDL_LIB_DIR /usr/lib/arm-linux-gnueabihf/)
else()
set(SDL_LIB_DIR /usr/lib/)
endif()
# Append external libraries and includes. Libs need to be listed in order of dependency for some reason
list(APPEND EXTRA_LIBS ${library_SOURCE_DIR}/build/${CMAKE_STATIC_LIBRARY_PREFIX}library${CMAKE_STATIC_LIBRARY_SUFFIX})
list(APPEND EXTRA_LIBS ${bulletPhysics_SOURCE_DIR}/build/${CMAKE_STATIC_LIBRARY_PREFIX}bulletPhysics${CMAKE_STATIC_LIBRARY_SUFFIX})
list(APPEND EXTRA_LIBS ${Box2D_SOURCE_DIR}/build/${CMAKE_STATIC_LIBRARY_PREFIX}Box2D${CMAKE_STATIC_LIBRARY_SUFFIX})
list(APPEND EXTRA_LIBS ${angelscript_SOURCE_DIR}/build/${CMAKE_STATIC_LIBRARY_PREFIX}angelscript${CMAKE_STATIC_LIBRARY_SUFFIX})
list(APPEND EXTRA_LIBS ${Vulkan_LIBRARY})
list(APPEND EXTRA_LIBS ${SDL_LIB_DIR}${CMAKE_SHARED_LIBRARY_PREFIX}SDL2${CMAKE_SHARED_LIBRARY_SUFFIX})
list(APPEND EXTRA_LIBS ${SDL_LIB_DIR}${CMAKE_SHARED_LIBRARY_PREFIX}SDL2_mixer${CMAKE_SHARED_LIBRARY_SUFFIX})
list(APPEND EXTRA_INCLUDES /usr/include/SDL2)
list(APPEND EXTRA_INCLUDES ${PARENT_SOURCE_DIR})
list(APPEND EXTRA_INCLUDES ${Boost_INCLUDE_DIRS})
list(APPEND EXTRA_INCLUDES ${library_SOURCE_DIR})
list(APPEND EXTRA_INCLUDES ${angelscript_SOURCE_DIR}/include)
list(APPEND EXTRA_INCLUDES ${angelscript_SOURCE_DIR}/add_on)
list(APPEND EXTRA_INCLUDES ${bulletPhysics_SOURCE_DIR}/src)
# Target all the libraries
target_link_libraries(
${PROJECT_NAME} PRIVATE
${EXTRA_LIBS}
)
# Target all then includes
target_include_directories(
${PROJECT_NAME} PRIVATE
${EXTRA_INCLUDES}
)
message(STATUS "Extra Libs ${EXTRA_LIBS}")
message(STATUS "Extra Inc ${EXTRA_INCLUDES}")
Here’s one of the CMakelists.txt files from one of the libraries. Each library CMakelists.txt is mostly the same.
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Box2D VERSION 2.84)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -std=c++17 -Wall -pthread")
add_library(
${PROJECT_NAME} STATIC
Dynamics/Joints/b2DistanceJoint.cpp
Dynamics/Joints/b2FrictionJoint.cpp
Dynamics/Joints/b2GearJoint.cpp
Dynamics/Joints/b2Joint.cpp
Dynamics/Joints/b2MotorJoint.cpp
Dynamics/Joints/b2MouseJoint.cpp
Dynamics/Joints/b2PrismaticJoint.cpp
Dynamics/Joints/b2PulleyJoint.cpp
Dynamics/Joints/b2RevoluteJoint.cpp
Dynamics/Joints/b2RopeJoint.cpp
Dynamics/Joints/b2WeldJoint.cpp
Dynamics/Joints/b2WheelJoint.cpp
Dynamics/Contacts/b2CircleContact.cpp
Dynamics/Contacts/b2Contact.cpp
Dynamics/Contacts/b2ContactSolver.cpp
Dynamics/Contacts/b2PolygonAndCircleContact.cpp
Dynamics/Contacts/b2EdgeAndCircleContact.cpp
Dynamics/Contacts/b2EdgeAndPolygonContact.cpp
Dynamics/Contacts/b2ChainAndCircleContact.cpp
Dynamics/Contacts/b2ChainAndPolygonContact.cpp
Dynamics/Contacts/b2PolygonContact.cpp
Dynamics/b2Body.cpp
Dynamics/b2ContactManager.cpp
Dynamics/b2Fixture.cpp
Dynamics/b2Island.cpp
Dynamics/b2World.cpp
Dynamics/b2WorldCallbacks.cpp
Common/b2BlockAllocator.cpp
Common/b2Draw.cpp
Common/b2Math.cpp
Common/b2Settings.cpp
Common/b2StackAllocator.cpp
Common/b2Timer.cpp
Collision/Shapes/b2CircleShape.cpp
Collision/Shapes/b2EdgeShape.cpp
Collision/Shapes/b2ChainShape.cpp
Collision/Shapes/b2PolygonShape.cpp
Collision/b2BroadPhase.cpp
Collision/b2CollideCircle.cpp
Collision/b2CollideEdge.cpp
Collision/b2CollidePolygon.cpp
Collision/b2Collision.cpp
Collision/b2Distance.cpp
Collision/b2DynamicTree.cpp
Collision/b2TimeOfImpact.cpp
Rope/b2Rope.cpp
)
target_include_directories(
${PROJECT_NAME} PUBLIC
../
)