Skip to content

Commit ee22b2e

Browse files
authored
Upgrade CMake minimum version and improve CMake code (#5446)
Only show in developer changelog
1 parent 007d56e commit ee22b2e

File tree

25 files changed

+525
-449
lines changed

25 files changed

+525
-449
lines changed

CMakeLists.txt

+61-62
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,99 @@
1-
#This is the CMake file used to build GDevelop.
2-
#For more information, see the README.md file.
1+
# This is the CMake file used to build GDevelop.
2+
# For more information, see the README.md file.
33

4-
cmake_minimum_required(VERSION 2.6)
5-
cmake_policy(SET CMP0011 NEW)
4+
cmake_minimum_required(VERSION 3.5)
65

76
# Add utility functions
87
include(scripts/CMakeClangUtils.txt) # To add clang-format and clang-tidy support to a target
98

109
# Macro for defining an option
1110
macro(gd_set_option var default type docstring)
12-
if(NOT DEFINED ${var})
13-
set(${var} ${default})
14-
endif()
15-
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
11+
if(NOT DEFINED ${var})
12+
set(${var} ${default})
13+
endif()
14+
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
1615
endmacro()
16+
17+
# Set options
1718
gd_set_option(BUILD_CORE TRUE BOOL "TRUE to build GDevelop Core library")
1819
gd_set_option(BUILD_GDJS TRUE BOOL "TRUE to build GDevelop JS Platform")
1920
gd_set_option(BUILD_EXTENSIONS TRUE BOOL "TRUE to build the extensions")
2021
gd_set_option(BUILD_TESTS TRUE BOOL "TRUE to build the tests")
2122

2223
# Disable deprecated code
23-
set(NO_GUI TRUE CACHE BOOL "" FORCE) #Force disable old GUI related code.
24+
set(NO_GUI TRUE CACHE BOOL "" FORCE) # Force disable old GUI related code.
2425

25-
#Setting up installation directory, for Linux (has to be done before "project" command).
26-
IF(NOT WIN32)
27-
if (NOT APPLE)
28-
gd_set_option(GD_INSTALL_PREFIX "/opt/gdevelop/" STRING "The directory where GDevelop should be installed")
29-
ELSE()
30-
gd_set_option(GD_INSTALL_PREFIX "." STRING "The directory where GDevelop should be installed")
31-
ENDIF()
26+
# Setting up installation directory, for Linux (has to be done before "project" command).
27+
if(NOT WIN32)
28+
if(NOT APPLE)
29+
gd_set_option(GD_INSTALL_PREFIX "/opt/gdevelop/" STRING "The directory where GDevelop should be installed")
30+
else()
31+
gd_set_option(GD_INSTALL_PREFIX "." STRING "The directory where GDevelop should be installed")
32+
endif()
3233

33-
#As we embed SFML, prevent it to be installed system-wide
34+
# As we embed SFML, prevent it to be installed system-wide
3435
set(CMAKE_INSTALL_PREFIX "${GD_INSTALL_PREFIX}/useless")
35-
ENDIF()
36+
endif()
3637

3738
project(GDevelop)
3839
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
39-
IF(NOT WIN32 AND NOT APPLE AND NOT BUILD_TESTS)
40-
SET(CMAKE_SKIP_BUILD_RPATH TRUE) #Avoid errors when packaging for linux.
41-
ENDIF()
42-
IF(APPLE)
40+
if(NOT WIN32 AND NOT APPLE AND NOT BUILD_TESTS)
41+
set(CMAKE_SKIP_BUILD_RPATH TRUE) # Avoid errors when packaging for linux.
42+
endif()
43+
if(APPLE)
4344
set(CMAKE_MACOSX_RPATH 1)
4445
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
4546
set(CMAKE_INSTALL_RPATH ".")
4647
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
47-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_")
48-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-potentially-evaluated-expression")
49-
ENDIF()
50-
#Sanity checks
51-
IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
52-
message( "CMAKE_BUILD_TYPE is empty, assuming build type is Release" )
48+
add_compile_options(
49+
-D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_
50+
-Wno-potentially-evaluated-expression)
51+
endif()
52+
# Sanity checks
53+
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
54+
message(STATUS "CMAKE_BUILD_TYPE is empty, assuming build type is Release")
5355
set(CMAKE_BUILD_TYPE Release)
54-
ENDIF()
56+
endif()
5557

56-
IF("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
57-
SET(CMAKE_SHARED_LINKER_FLAGS "-s") #Force stripping to avoid errors when packaging for linux.
58-
ENDIF()
58+
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
59+
set(CMAKE_SHARED_LINKER_FLAGS "-s") # Force stripping to avoid errors when packaging for linux.
60+
endif()
5961

6062
#Activate C++11
61-
include(CheckCXXCompilerFlag)
62-
CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
63-
CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_CXX0X)
64-
if(COMPILER_SUPPORTS_CXX11)
65-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
66-
elseif(COMPILER_SUPPORTS_CXX0X)
67-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
68-
else()
69-
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support (with GNU extensions). Please use a different C++ compiler.")
70-
endif()
63+
set(CMAKE_CXX_STANDARD 11)
64+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7165

7266
# Mark some warnings as errors
7367
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
7468
# Activate as much warnings as possible to avoid errors like
7569
# uninitialized variables or other hard to debug bugs.
76-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
77-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
78-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder-ctor -Wno-reorder -Wno-pessimizing-move -Wno-unused-variable -Wno-unused-private-field")
70+
add_compile_options(
71+
-Wall
72+
-Wno-unknown-warning-option
73+
-Wno-reorder-ctor
74+
-Wno-reorder
75+
-Wno-pessimizing-move
76+
-Wno-unused-variable
77+
-Wno-unused-private-field
7978

80-
# Make as much warnings considered as errors as possible (only one for now).
81-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-stack-address")
79+
# Make as much warnings considered as errors as possible (only one for now).
80+
-Werror=return-stack-address)
8281
endif()
8382

84-
#Define common directories:
83+
# Define common directories:
8584
set(GD_base_dir ${CMAKE_CURRENT_SOURCE_DIR})
8685

87-
#Add all the CMakeLists:
88-
ADD_SUBDIRECTORY(ExtLibs)
89-
IF(BUILD_CORE)
90-
ADD_SUBDIRECTORY(Core)
91-
ENDIF()
92-
IF(BUILD_GDJS)
93-
ADD_SUBDIRECTORY(GDJS)
94-
ENDIF()
95-
IF(EMSCRIPTEN)
96-
ADD_SUBDIRECTORY(GDevelop.js)
97-
ENDIF()
98-
IF(BUILD_EXTENSIONS)
99-
ADD_SUBDIRECTORY(Extensions)
100-
ENDIF()
86+
# Add all the CMakeLists:
87+
add_subdirectory(ExtLibs)
88+
if(BUILD_CORE)
89+
add_subdirectory(Core)
90+
endif()
91+
if(BUILD_GDJS)
92+
add_subdirectory(GDJS)
93+
endif()
94+
if(EMSCRIPTEN)
95+
add_subdirectory(GDevelop.js)
96+
endif()
97+
if(BUILD_EXTENSIONS)
98+
add_subdirectory(Extensions)
99+
endif()

Core/CMakeLists.txt

+67-52
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,98 @@
1-
cmake_minimum_required(VERSION 2.6)
2-
cmake_policy(SET CMP0015 NEW)
1+
cmake_minimum_required(VERSION 3.5)
32

43
project(GDCore)
54

6-
SET(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) #Force use response file: useful for Ninja build system on Windows.
7-
SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
8-
SET(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1)
9-
SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1)
5+
set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) # Force use response file: useful for Ninja build system on Windows.
6+
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
7+
set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1)
8+
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1)
109

11-
#Define common directories:
10+
# Define common directories:
1211
set(GDCORE_include_dir ${GD_base_dir}/Core PARENT_SCOPE)
1312
set(GDCORE_lib_dir ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME} PARENT_SCOPE)
1413

15-
#Dependencies on external libraries:
16-
###
14+
# Dependencies on external libraries:
15+
#
1716

18-
#Defines
19-
###
20-
add_definitions( -DGD_IDE_ONLY )
21-
IF (EMSCRIPTEN)
22-
add_definitions( -DEMSCRIPTEN )
23-
ENDIF()
24-
IF(CMAKE_BUILD_TYPE MATCHES "Debug")
25-
add_definitions( -DDEBUG )
26-
ELSE()
27-
add_definitions( -DRELEASE )
28-
ENDIF()
17+
# Defines
18+
#
19+
add_definitions(-DGD_IDE_ONLY)
20+
if(EMSCRIPTEN)
21+
add_definitions(-DEMSCRIPTEN)
22+
endif()
23+
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
24+
add_definitions(-DDEBUG)
25+
else()
26+
add_definitions(-DRELEASE)
27+
endif()
2928

30-
IF(WIN32)
31-
add_definitions( -DWINDOWS )
32-
add_definitions( "-DGD_CORE_API=__declspec(dllexport)" )
33-
add_definitions( -D__GNUWIN32__ )
34-
ELSE()
35-
IF(APPLE)
36-
add_definitions( -DMACOS )
37-
ELSE()
38-
add_definitions( -DLINUX )
39-
ENDIF()
40-
add_definitions( -DGD_API= )
41-
add_definitions( -DGD_CORE_API= )
42-
ENDIF(WIN32)
29+
if(WIN32)
30+
add_definitions(-DWINDOWS)
31+
add_definitions("-DGD_CORE_API=__declspec(dllexport)")
32+
add_definitions(-D__GNUWIN32__)
33+
else()
34+
if(APPLE)
35+
add_definitions(-DMACOS)
36+
else()
37+
add_definitions(-DLINUX)
38+
endif()
39+
add_definitions(-DGD_API=)
40+
add_definitions(-DGD_CORE_API=)
41+
endif()
4342

44-
#The target
45-
###
43+
# The target
44+
#
4645
include_directories(.)
47-
file(GLOB_RECURSE source_files GDCore/*)
46+
file(
47+
GLOB_RECURSE
48+
source_files
49+
GDCore/*)
4850

49-
file(GLOB_RECURSE formatted_source_files tests/* GDCore/Events/* GDCore/Extensions/* GDCore/IDE/* GDCore/Project/* GDCore/Serialization/* GDCore/Tools/*)
50-
list(REMOVE_ITEM formatted_source_files "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.h" "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs_dialogs_bitmaps.cpp")
51+
file(
52+
GLOB_RECURSE
53+
formatted_source_files
54+
tests/*
55+
GDCore/Events/*
56+
GDCore/Extensions/*
57+
GDCore/IDE/*
58+
GDCore/Project/*
59+
GDCore/Serialization/*
60+
GDCore/Tools/*)
61+
list(
62+
REMOVE_ITEM
63+
formatted_source_files
64+
"${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.cpp"
65+
"${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.h"
66+
"${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs_dialogs_bitmaps.cpp")
5167
gd_add_clang_utils(GDCore "${formatted_source_files}")
5268

53-
IF(EMSCRIPTEN)
69+
if(EMSCRIPTEN)
5470
# Emscripten treats all libraries as static libraries
5571
add_library(GDCore STATIC ${source_files})
56-
ELSE()
72+
else()
5773
add_library(GDCore SHARED ${source_files})
58-
ENDIF()
59-
IF(EMSCRIPTEN)
74+
endif()
75+
if(EMSCRIPTEN)
6076
set_target_properties(GDCore PROPERTIES SUFFIX ".bc")
61-
ELSEIF(WIN32)
77+
elseif(WIN32)
6278
set_target_properties(GDCore PROPERTIES PREFIX "")
63-
ELSE()
79+
else()
6480
set_target_properties(GDCore PROPERTIES PREFIX "lib")
65-
ENDIF()
81+
endif()
6682
set(LIBRARY_OUTPUT_PATH ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME})
6783
set(ARCHIVE_OUTPUT_PATH ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME})
6884
set(RUNTIME_OUTPUT_PATH ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME})
6985

70-
#Tests
71-
###
86+
# Tests
87+
#
7288
if(BUILD_TESTS)
7389
file(
74-
GLOB_RECURSE
75-
test_source_files
76-
tests/*
77-
)
90+
GLOB_RECURSE
91+
test_source_files
92+
tests/*)
7893

7994
add_executable(GDCore_tests ${test_source_files})
80-
set_target_properties(GDCore_tests PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE) #Allow finding dependencies directly from build path on Mac OS X.
95+
set_target_properties(GDCore_tests PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE) # Allow finding dependencies directly from build path on Mac OS X.
8196
target_link_libraries(GDCore_tests GDCore)
8297
target_link_libraries(GDCore_tests ${CMAKE_DL_LIBS})
8398
endif()

ExtLibs/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+12-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
cmake_minimum_required(VERSION 2.6)
2-
cmake_policy(SET CMP0015 NEW)
1+
cmake_minimum_required(VERSION 3.5)
32

43
project(AnchorBehavior)
54
gd_add_extension_includes()
65

7-
#Defines
8-
###
6+
# Defines
7+
#
98
gd_add_extension_definitions(AnchorBehavior)
109

11-
#The targets
12-
###
10+
# The targets
11+
#
1312
include_directories(.)
14-
file(GLOB source_files *.cpp *.h)
13+
file(
14+
GLOB
15+
source_files
16+
*.cpp
17+
*.h)
1518
gd_add_clang_utils(AnchorBehavior "${source_files}")
1619
gd_add_extension_target(AnchorBehavior "${source_files}")
1720

18-
#Linker files for the IDE extension
19-
###
21+
# Linker files for the IDE extension
22+
#
2023
gd_extension_link_libraries(AnchorBehavior)

0 commit comments

Comments
 (0)