CMake: Dont cache variables when building with LIBMGBA_ONLY
Bonta-kun 40473493+Bonta0@users.noreply.github.com
Sat, 06 Mar 2021 06:07:08 +0100
1 files changed,
29 insertions(+),
14 deletions(-)
jump to
M
CMakeLists.txt
→
CMakeLists.txt
@@ -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)@@ -30,10 +42,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS /wd4003 /wd4244 /wd4146 /wd4267") 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)@@ -111,8 +119,13 @@ set(CMAKE_INSTALL_DOCDIR ".")
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 @@ elseif(UNIX AND NOT APPLE AND TARGET OpenGL::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(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
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)