CMake: Dont cache variables when building with LIBMGBA_ONLY

This commit is contained in:
Bonta-kun 2021-03-06 06:07:08 +01:00 committed by Vicki Pfau
parent 71e7acedfe
commit 18d909dd8f
1 changed files with 29 additions and 14 deletions

View File

@ -8,8 +8,20 @@ if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
set(OpenGL_GL_PREFERENCE LEGACY)
endif()
project(mGBA)
set(BINARY_NAME mgba CACHE INTERNAL "Name of output binaries")
if(NOT DEFINED LIBMGBA_ONLY)
get_directory_property(LIBMGBA_ONLY EXCLUDE_FROM_ALL)
endif()
if(NOT DEFINED BINARY_NAME)
set(BINARY_NAME mgba)
endif()
if(NOT LIBMGBA_ONLY)
set(BINARY_NAME ${BINARY_NAME} CACHE INTERNAL "Name of output binaries")
endif()
set(CMAKE_C_STANDARD 99)
if(NOT MSVC)
set(CMAKE_C_STANDARD_REQUIRED ON)
@ -32,10 +44,6 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS /wd4003 /wd4244 /wd4146 /wd4267")
endif()
if(NOT DEFINED LIBMGBA_ONLY)
get_directory_property(LIBMGBA_ONLY EXCLUDE_FROM_ALL)
endif()
if(NOT LIBMGBA_ONLY)
set(USE_DEBUGGERS ON CACHE BOOL "Whether or not to enable the debugging infrastructure")
if (NOT WIN32)
@ -111,8 +119,13 @@ else()
set(CMAKE_INSTALL_INCLUDEDIR "include")
endif()
set(LIBDIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installed library directory")
mark_as_advanced(LIBDIR)
if(NOT DEFINED LIBDIR)
set(LIBDIR "${CMAKE_INSTALL_LIBDIR}")
endif()
if(NOT LIBMGBA_ONLY)
set(LIBDIR "${LIBDIR}" CACHE PATH "Installed library directory")
mark_as_advanced(LIBDIR)
endif()
if (BUILD_LIBRETRO)
set(LIBRETRO_LIBDIR "${LIBDIR}" CACHE PATH "Installed library directory (Libretro)")
@ -159,11 +172,13 @@ else()
set(DEFAULT_LTO OFF)
endif()
set(BUILD_LTO ${DEFAULT_LTO} CACHE BOOL "Build with link-time optimization")
set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
if(NOT LIBMGBA_ONLY)
set(BUILD_LTO ${DEFAULT_LTO} CACHE BOOL "Build with link-time optimization")
set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
endif()
set(PGO_PRE_FLAGS "-fprofile-generate=${PGO_DIR} -fprofile-arcs")
set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
@ -442,7 +457,7 @@ if(BUILD_GL)
set(OPENGL_LIBRARY OpenGL::GL)
endif()
endif()
if(NOT BUILD_GL)
if(NOT BUILD_GL AND NOT LIBMGBA_ONLY)
set(OPENGL_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(BUILD_GLES2 AND NOT BUILD_RASPI AND NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|Darwin|Linux|.*BSD|DragonFly|Haiku)$")
@ -452,7 +467,7 @@ if(BUILD_GLES2 AND NOT BUILD_RASPI AND NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|
set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
endif()
endif()
if(NOT BUILD_GLES2)
if(NOT BUILD_GLES2 AND NOT LIBMGBA_ONLY)
set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(BUILD_GL)