mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 15:05:53 +00:00
Fix CMake ordering to find correct compiler:
* `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` must be defined before `project`. However, it will clear `CMAKE_BUILD_TYPE`. Use `CACHE` variables and reorder some code to work around these constraints. * Also correct a couple of copy paste errors.
This commit is contained in:
@@ -33,16 +33,16 @@ macro(parse_target)
|
|||||||
if (${cur_component} STREQUAL gcc)
|
if (${cur_component} STREQUAL gcc)
|
||||||
if (DEFINED ENV{GNU_CC})
|
if (DEFINED ENV{GNU_CC})
|
||||||
set(CMAKE_C_COMPILER $ENV{GNU_CC})
|
set(CMAKE_C_COMPILER $ENV{GNU_CC})
|
||||||
elseif ($ENV{CXX} MATCHES .*gcc.*)
|
elseif ($ENV{CC} MATCHES .*gcc.*)
|
||||||
set(CMAKE_CXX_COMPILER $ENV{CC})
|
set(CMAKE_C_COMPILER $ENV{CC})
|
||||||
else()
|
else()
|
||||||
find_program(CMAKE_C_COMPILER gcc)
|
find_program(CMAKE_C_COMPILER gcc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (DEFINED ENV{GNU_CXX})
|
if (DEFINED ENV{GNU_CXX})
|
||||||
set(CMAKE_C_COMPILER $ENV{GNU_CXX})
|
set(CMAKE_CXX_COMPILER $ENV{GNU_CXX})
|
||||||
elseif ($ENV{CXX} MATCHES .*g\\+\\+.*)
|
elseif ($ENV{CXX} MATCHES .*g\\+\\+.*)
|
||||||
set(CMAKE_C_COMPILER $ENV{CC})
|
set(CMAKE_CXX_COMPILER $ENV{CXX})
|
||||||
else()
|
else()
|
||||||
find_program(CMAKE_CXX_COMPILER g++)
|
find_program(CMAKE_CXX_COMPILER g++)
|
||||||
endif()
|
endif()
|
||||||
@@ -51,16 +51,16 @@ macro(parse_target)
|
|||||||
if (${cur_component} STREQUAL clang)
|
if (${cur_component} STREQUAL clang)
|
||||||
if (DEFINED ENV{CLANG_CC})
|
if (DEFINED ENV{CLANG_CC})
|
||||||
set(CMAKE_C_COMPILER $ENV{CLANG_CC})
|
set(CMAKE_C_COMPILER $ENV{CLANG_CC})
|
||||||
elseif ($ENV{CXX} MATCHES .*clang.*)
|
elseif ($ENV{CC} MATCHES .*clang.*)
|
||||||
set(CMAKE_CXX_COMPILER $ENV{CC})
|
set(CMAKE_C_COMPILER $ENV{CC})
|
||||||
else()
|
else()
|
||||||
find_program(CMAKE_C_COMPILER clang)
|
find_program(CMAKE_C_COMPILER clang)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (DEFINED ENV{CLANG_CXX})
|
if (DEFINED ENV{CLANG_CXX})
|
||||||
set(CMAKE_C_COMPILER $ENV{CLANG_CXX})
|
set(CMAKE_CXX_COMPILER $ENV{CLANG_CXX})
|
||||||
elseif ($ENV{CXX} MATCHES .*clang.*)
|
elseif ($ENV{CXX} MATCHES .*clang.*)
|
||||||
set(CMAKE_C_COMPILER $ENV{CC})
|
set(CMAKE_CXX_COMPILER $ENV{CXX})
|
||||||
else()
|
else()
|
||||||
find_program(CMAKE_CXX_COMPILER clang++)
|
find_program(CMAKE_CXX_COMPILER clang++)
|
||||||
endif()
|
endif()
|
||||||
@@ -105,6 +105,14 @@ macro(parse_target)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
endwhile()
|
endwhile()
|
||||||
|
# Promote these values to the CACHE, then unset the locals
|
||||||
|
# to prevent shadowing.
|
||||||
|
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE FILEPATH
|
||||||
|
"Path to a program" FORCE)
|
||||||
|
unset(CMAKE_C_COMPILER)
|
||||||
|
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE FILEPATH
|
||||||
|
"Path to a program" FORCE)
|
||||||
|
unset(CMAKE_CXX_COMPILER)
|
||||||
|
|
||||||
if (release)
|
if (release)
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
@@ -112,9 +120,25 @@ macro(parse_target)
|
|||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ensure that the unity flags are set and exclusive
|
||||||
|
if (NOT DEFINED unity OR unity)
|
||||||
|
# Default to unity builds
|
||||||
|
set(unity true)
|
||||||
|
set(nonunity false)
|
||||||
|
else()
|
||||||
|
set(unity false)
|
||||||
|
set(nonunity true)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NOT unity)
|
if (NOT unity)
|
||||||
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}Classic)
|
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}Classic)
|
||||||
endif()
|
endif()
|
||||||
|
# Promote this value to the CACHE, then unset the local
|
||||||
|
# to prevent shadowing.
|
||||||
|
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE INTERNAL
|
||||||
|
"Choose the type of build, options are in CMAKE_CONFIGURATION_TYPES"
|
||||||
|
FORCE)
|
||||||
|
unset(CMAKE_BUILD_TYPE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endmacro()
|
endmacro()
|
||||||
@@ -149,8 +173,11 @@ macro(setup_build_cache)
|
|||||||
ReleaseClassic)
|
ReleaseClassic)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Promote this value to the CACHE, then unset the local
|
||||||
|
# to prevent shadowing.
|
||||||
set(CMAKE_CONFIGURATION_TYPES
|
set(CMAKE_CONFIGURATION_TYPES
|
||||||
${CMAKE_CONFIGURATION_TYPES} CACHE STRING "" FORCE)
|
${CMAKE_CONFIGURATION_TYPES} CACHE STRING "" FORCE)
|
||||||
|
unset(CMAKE_CONFIGURATION_TYPES)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|||||||
@@ -52,11 +52,22 @@
|
|||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
|
#########################################################
|
||||||
|
# CMAKE_C_COMPILER and CMAKE_CXX_COMPILER must be defined
|
||||||
|
# before the project statement; However, the project
|
||||||
|
# statement will clear CMAKE_BUILD_TYPE. CACHE variables,
|
||||||
|
# along with the order of this code, are used to work
|
||||||
|
# around these constraints.
|
||||||
|
#
|
||||||
|
# Don't put any code above or in this block, unless it
|
||||||
|
# has similar constraints.
|
||||||
cmake_minimum_required(VERSION 3.1.0)
|
cmake_minimum_required(VERSION 3.1.0)
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Builds/CMake")
|
||||||
# The project command can override some computed values.
|
include(CMakeFuncs)
|
||||||
# Don't put any code above this line.
|
set(openssl_min 1.0.2)
|
||||||
|
parse_target()
|
||||||
project(rippled)
|
project(rippled)
|
||||||
|
#########################################################
|
||||||
|
|
||||||
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
||||||
set(dir "build")
|
set(dir "build")
|
||||||
@@ -86,18 +97,6 @@ if("${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND
|
|||||||
-G\"${CMAKE_GENERATOR} Win64\"")
|
-G\"${CMAKE_GENERATOR} Win64\"")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Builds/CMake")
|
|
||||||
include(CMakeFuncs)
|
|
||||||
|
|
||||||
set(openssl_min 1.0.2)
|
|
||||||
|
|
||||||
parse_target()
|
|
||||||
|
|
||||||
if (NOT DEFINED unity)
|
|
||||||
set(unity true)
|
|
||||||
set(nonunity false)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
setup_build_cache()
|
setup_build_cache()
|
||||||
|
|
||||||
if(nonunity)
|
if(nonunity)
|
||||||
|
|||||||
Reference in New Issue
Block a user