2011-05-16 13:12:07 +00:00
|
|
|
|
2011-09-27 21:21:59 +00:00
|
|
|
# Show a note about ccache build
|
2014-02-12 18:36:46 +00:00
|
|
|
if(ENABLE_CCACHE)
|
2011-09-27 21:21:59 +00:00
|
|
|
message("-- Enabling ccache build - done")
|
2015-02-21 14:40:14 +00:00
|
|
|
set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
|
|
|
|
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
|
2011-09-27 21:21:59 +00:00
|
|
|
endif()
|
|
|
|
|
2012-02-25 23:50:38 +00:00
|
|
|
# PDB style debug info
|
|
|
|
if(NOT DEFINED SEPARATE_DBG)
|
|
|
|
set(SEPARATE_DBG FALSE)
|
|
|
|
endif()
|
|
|
|
|
2014-10-03 09:56:36 +00:00
|
|
|
# Dwarf based builds (no rsym)
|
2015-06-15 16:43:11 +00:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
set(NO_ROSSYM TRUE)
|
|
|
|
elseif(NOT DEFINED NO_ROSSYM)
|
2014-10-03 09:56:36 +00:00
|
|
|
set(NO_ROSSYM FALSE)
|
|
|
|
endif()
|
|
|
|
|
2013-09-17 22:31:33 +00:00
|
|
|
if(NOT DEFINED USE_PSEH3)
|
2013-11-02 20:42:13 +00:00
|
|
|
set(USE_PSEH3 1)
|
2013-09-17 22:31:33 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(USE_PSEH3)
|
|
|
|
add_definitions(-D_USE_PSEH3=1)
|
|
|
|
endif()
|
|
|
|
|
2013-11-01 11:58:31 +00:00
|
|
|
if(NOT DEFINED USE_DUMMY_PSEH)
|
|
|
|
set(USE_DUMMY_PSEH 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(USE_DUMMY_PSEH)
|
|
|
|
add_definitions(-D_USE_DUMMY_PSEH=1)
|
|
|
|
endif()
|
|
|
|
|
2014-10-04 20:26:14 +00:00
|
|
|
if(STACK_PROTECTOR)
|
2020-12-31 16:56:39 +00:00
|
|
|
add_compile_options(-fstack-protector-strong)
|
2014-10-04 20:26:14 +00:00
|
|
|
endif()
|
|
|
|
|
2011-05-16 13:12:07 +00:00
|
|
|
# Compiler Core
|
2022-04-26 00:15:46 +00:00
|
|
|
# note: -fno-common is default since GCC 10
|
|
|
|
add_compile_options(-pipe -fms-extensions -fno-strict-aliasing -fno-common)
|
2015-03-14 15:47:04 +00:00
|
|
|
|
2020-09-18 07:34:18 +00:00
|
|
|
# Prevent GCC from searching any of the default directories.
|
|
|
|
# The case for C++ is handled through the reactos_c++ INTERFACE library
|
|
|
|
add_compile_options("$<$<NOT:$<COMPILE_LANGUAGE:CXX>>:-nostdinc>")
|
2015-03-14 15:47:04 +00:00
|
|
|
|
2021-04-09 00:51:32 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
2020-09-10 21:23:14 +00:00
|
|
|
add_compile_options(-fno-aggressive-loop-optimizations)
|
|
|
|
if (DBG)
|
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wold-style-declaration>")
|
|
|
|
endif()
|
2021-04-09 00:51:32 +00:00
|
|
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
2020-12-05 10:14:28 +00:00
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wno-microsoft>")
|
2020-09-10 21:23:14 +00:00
|
|
|
add_compile_options(-Wno-pragma-pack)
|
|
|
|
add_compile_options(-fno-associative-math)
|
2021-04-09 00:51:32 +00:00
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
|
|
|
|
# disable "libcall optimization"
|
|
|
|
# see https://mudongliang.github.io/2020/12/02/undefined-reference-to-stpcpy.html
|
|
|
|
add_compile_options(-fno-builtin-stpcpy)
|
|
|
|
endif()
|
|
|
|
|
2014-09-07 12:36:26 +00:00
|
|
|
set(CMAKE_LINK_DEF_FILE_FLAG "")
|
2014-09-07 17:19:14 +00:00
|
|
|
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
|
|
|
|
set(CMAKE_LINK_LIBRARY_SUFFIX "")
|
2014-09-10 15:34:05 +00:00
|
|
|
set(CMAKE_CREATE_WIN32_EXE "")
|
2014-09-10 19:00:53 +00:00
|
|
|
set(CMAKE_C_COMPILE_OPTIONS_PIC "")
|
|
|
|
set(CMAKE_CXX_COMPILE_OPTIONS_PIC "")
|
|
|
|
set(CMAKE_C_COMPILE_OPTIONS_PIE "")
|
|
|
|
set(CMAKE_CXX_COMPILE_OPTIONS_PIE "")
|
2014-09-20 17:36:37 +00:00
|
|
|
set(CMAKE_ASM_FLAGS_DEBUG "")
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG "")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "")
|
2014-03-02 20:27:39 +00:00
|
|
|
endif()
|
|
|
|
|
2012-02-25 23:50:38 +00:00
|
|
|
# Debugging
|
2015-06-15 17:26:04 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
if(SEPARATE_DBG)
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-gdwarf-2 -ggdb)
|
2015-06-15 17:26:04 +00:00
|
|
|
else()
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-gdwarf-2 -gstrict-dwarf)
|
|
|
|
if(NOT CMAKE_C_COMPILER_ID STREQUAL Clang)
|
|
|
|
add_compile_options(-femit-struct-debug-detailed=none -feliminate-unused-debug-symbols)
|
2015-06-15 17:26:04 +00:00
|
|
|
endif()
|
2014-03-02 20:08:07 +00:00
|
|
|
endif()
|
2012-02-25 23:50:38 +00:00
|
|
|
endif()
|
|
|
|
|
2011-05-16 13:12:07 +00:00
|
|
|
# Tuning
|
2021-04-13 18:08:04 +00:00
|
|
|
add_compile_options(-march=${OARCH} -mtune=${TUNE})
|
2011-05-16 13:12:07 +00:00
|
|
|
|
2013-11-02 14:33:18 +00:00
|
|
|
# Warnings, errors
|
2020-09-21 10:16:02 +00:00
|
|
|
if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT CMAKE_C_COMPILER_ID STREQUAL Clang))
|
|
|
|
add_compile_options(-Werror)
|
2014-03-02 22:11:49 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Wall -Wpointer-arith)
|
|
|
|
add_compile_options(-Wno-char-subscripts -Wno-multichar -Wno-unused-value)
|
|
|
|
add_compile_options(-Wno-unused-const-variable)
|
|
|
|
add_compile_options(-Wno-unused-local-typedefs)
|
|
|
|
add_compile_options(-Wno-deprecated)
|
2021-06-17 12:48:52 +00:00
|
|
|
add_compile_options(-Wno-unused-result) # FIXME To be removed when CORE-17637 is resolved
|
2014-03-02 20:08:07 +00:00
|
|
|
|
|
|
|
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Wno-maybe-uninitialized)
|
2014-03-02 20:08:07 +00:00
|
|
|
endif()
|
|
|
|
|
2012-08-27 18:58:27 +00:00
|
|
|
if(ARCH STREQUAL "amd64")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Wno-format)
|
2012-08-27 18:58:27 +00:00
|
|
|
elseif(ARCH STREQUAL "arm")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Wno-attributes)
|
2011-05-16 13:12:07 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Optimizations
|
2015-06-15 18:59:46 +00:00
|
|
|
# FIXME: Revisit this to see if we even need these levels
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-O2 -DNDEBUG)
|
2015-06-15 18:59:46 +00:00
|
|
|
else()
|
|
|
|
if(OPTIMIZE STREQUAL "1")
|
2021-04-09 08:09:55 +00:00
|
|
|
add_compile_options(-Os)
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
add_compile_options(-ftracer)
|
|
|
|
endif()
|
2015-06-15 18:59:46 +00:00
|
|
|
elseif(OPTIMIZE STREQUAL "2")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Os)
|
2015-06-15 18:59:46 +00:00
|
|
|
elseif(OPTIMIZE STREQUAL "3")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Og)
|
2015-06-15 18:59:46 +00:00
|
|
|
elseif(OPTIMIZE STREQUAL "4")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-O1)
|
2015-06-15 18:59:46 +00:00
|
|
|
elseif(OPTIMIZE STREQUAL "5")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-O2)
|
2015-06-15 18:59:46 +00:00
|
|
|
elseif(OPTIMIZE STREQUAL "6")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-O3)
|
2015-06-15 18:59:46 +00:00
|
|
|
elseif(OPTIMIZE STREQUAL "7")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-Ofast)
|
2015-06-15 18:59:46 +00:00
|
|
|
endif()
|
2011-05-16 13:12:07 +00:00
|
|
|
endif()
|
|
|
|
|
2012-03-10 23:38:37 +00:00
|
|
|
# Link-time code generation
|
|
|
|
if(LTCG)
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-flto -fno-fat-lto-objects)
|
2012-03-10 23:38:37 +00:00
|
|
|
endif()
|
|
|
|
|
2012-08-27 18:58:27 +00:00
|
|
|
if(ARCH STREQUAL "i386")
|
2021-10-16 08:58:08 +00:00
|
|
|
add_compile_options(-fno-optimize-sibling-calls -fno-omit-frame-pointer -mstackrealign)
|
2014-03-02 20:08:07 +00:00
|
|
|
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-mpreferred-stack-boundary=3 -fno-set-stack-executable)
|
2014-03-02 20:08:07 +00:00
|
|
|
endif()
|
2013-11-17 22:11:04 +00:00
|
|
|
# FIXME: this doesn't work. CMAKE_BUILD_TYPE is always "Debug"
|
2013-01-22 22:38:40 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2020-09-21 10:16:02 +00:00
|
|
|
add_compile_options(-momit-leaf-frame-pointer)
|
2011-05-16 13:12:07 +00:00
|
|
|
endif()
|
2012-08-27 18:58:27 +00:00
|
|
|
elseif(ARCH STREQUAL "amd64")
|
2021-04-09 08:09:55 +00:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
add_compile_options(-mpreferred-stack-boundary=4)
|
|
|
|
endif()
|
2020-12-29 17:14:30 +00:00
|
|
|
add_compile_options(-Wno-error)
|
2011-05-16 13:12:07 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Other
|
2012-08-27 18:58:27 +00:00
|
|
|
if(ARCH STREQUAL "amd64")
|
2022-08-31 18:52:09 +00:00
|
|
|
add_compile_options(-mcx16) # Generate CMPXCHG16
|
2011-05-16 13:12:07 +00:00
|
|
|
add_definitions(-U_X86_ -UWIN32)
|
2012-08-27 18:58:27 +00:00
|
|
|
elseif(ARCH STREQUAL "arm")
|
2011-05-16 13:12:07 +00:00
|
|
|
add_definitions(-U_UNICODE -UUNICODE)
|
|
|
|
add_definitions(-D__MSVCRT__) # DUBIOUS
|
|
|
|
endif()
|
|
|
|
|
2019-04-29 08:02:13 +00:00
|
|
|
# Fix build with GLIBCXX + our c++ headers
|
|
|
|
add_definitions(-D_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
|
|
|
|
|
2014-03-24 20:54:01 +00:00
|
|
|
# Alternative arch name
|
2012-08-27 18:58:27 +00:00
|
|
|
if(ARCH STREQUAL "amd64")
|
2011-05-16 13:12:07 +00:00
|
|
|
set(ARCH2 x86_64)
|
|
|
|
else()
|
|
|
|
set(ARCH2 ${ARCH})
|
|
|
|
endif()
|
|
|
|
|
2012-02-25 23:50:38 +00:00
|
|
|
if(SEPARATE_DBG)
|
|
|
|
# PDB style debug puts all dwarf debug info in a separate dbg file
|
2012-07-17 14:08:18 +00:00
|
|
|
message(STATUS "Building separate debug symbols")
|
|
|
|
file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/symbols)
|
2012-08-27 18:58:27 +00:00
|
|
|
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
2020-04-19 10:59:54 +00:00
|
|
|
# Those variables seems to be set but empty in newer CMake versions
|
|
|
|
# and Ninja generator relies on them to generate PDB name, so unset them.
|
|
|
|
unset(MSVC_C_ARCHITECTURE_ID)
|
|
|
|
unset(MSVC_CXX_ARCHITECTURE_ID)
|
2018-10-30 16:23:42 +00:00
|
|
|
set(CMAKE_DEBUG_SYMBOL_SUFFIX "")
|
2012-07-17 14:08:18 +00:00
|
|
|
set(SYMBOL_FILE <TARGET_PDB>)
|
|
|
|
else()
|
2018-10-30 16:23:42 +00:00
|
|
|
set(SYMBOL_FILE <TARGET>)
|
2012-07-17 14:08:18 +00:00
|
|
|
endif()
|
2021-06-22 13:31:18 +00:00
|
|
|
|
|
|
|
if (NOT NO_ROSSYM)
|
|
|
|
get_target_property(RSYM native-rsym IMPORTED_LOCATION)
|
|
|
|
set(strip_debug "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
|
|
|
|
else()
|
|
|
|
set(strip_debug "${CMAKE_STRIP} --strip-debug <TARGET>")
|
|
|
|
endif()
|
|
|
|
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_C_LINK_EXECUTABLE
|
|
|
|
"<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
2021-06-22 13:31:18 +00:00
|
|
|
"${CMAKE_STRIP} --only-keep-debug <TARGET> -o ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
|
|
|
|
${strip_debug})
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_CXX_LINK_EXECUTABLE
|
|
|
|
"<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
2021-06-22 13:31:18 +00:00
|
|
|
"${CMAKE_STRIP} --only-keep-debug <TARGET> -o ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
|
|
|
|
${strip_debug})
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_C_CREATE_SHARED_LIBRARY
|
|
|
|
"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
|
2021-06-22 13:31:18 +00:00
|
|
|
"${CMAKE_STRIP} --only-keep-debug <TARGET> -o ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
|
|
|
|
${strip_debug})
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
|
|
|
|
"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
|
2021-06-22 13:31:18 +00:00
|
|
|
"${CMAKE_STRIP} --only-keep-debug <TARGET> -o ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
|
|
|
|
${strip_debug})
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_RC_CREATE_SHARED_LIBRARY
|
|
|
|
"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
|
2021-06-22 13:31:18 +00:00
|
|
|
"${CMAKE_STRIP} --only-keep-debug <TARGET> -o ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
|
|
|
|
${strip_debug})
|
2014-10-03 09:56:36 +00:00
|
|
|
elseif(NO_ROSSYM)
|
|
|
|
# Dwarf-based build
|
|
|
|
message(STATUS "Generating a dwarf-based build (no rsym)")
|
|
|
|
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
|
|
|
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
|
|
|
set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
|
|
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
|
|
|
set(CMAKE_RC_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
2012-02-25 23:50:38 +00:00
|
|
|
else()
|
|
|
|
# Normal rsym build
|
2020-10-22 06:47:06 +00:00
|
|
|
get_target_property(RSYM native-rsym IMPORTED_LOCATION)
|
2020-04-16 12:59:38 +00:00
|
|
|
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_C_LINK_EXECUTABLE
|
2012-03-10 23:38:37 +00:00
|
|
|
"<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
2013-08-18 20:05:32 +00:00
|
|
|
"${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_CXX_LINK_EXECUTABLE
|
2012-03-10 23:38:37 +00:00
|
|
|
"<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
2013-08-18 20:05:32 +00:00
|
|
|
"${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_C_CREATE_SHARED_LIBRARY
|
2012-03-10 23:38:37 +00:00
|
|
|
"<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
|
2013-08-18 20:05:32 +00:00
|
|
|
"${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
|
2012-03-10 23:38:37 +00:00
|
|
|
"<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
|
2013-08-18 20:05:32 +00:00
|
|
|
"${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
|
2012-02-25 23:50:38 +00:00
|
|
|
set(CMAKE_RC_CREATE_SHARED_LIBRARY
|
2013-07-18 21:03:01 +00:00
|
|
|
"<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
2012-02-25 23:50:38 +00:00
|
|
|
endif()
|
2011-06-13 10:36:40 +00:00
|
|
|
|
2019-03-20 13:19:48 +00:00
|
|
|
set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
|
|
|
|
set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
|
|
|
|
set(CMAKE_RC_CREATE_SHARED_MODULE ${CMAKE_RC_CREATE_SHARED_LIBRARY})
|
|
|
|
|
2021-04-06 17:23:31 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup,--gc-sections")
|
2011-06-13 10:36:40 +00:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
|
2019-03-20 13:19:48 +00:00
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
|
2011-06-13 10:36:40 +00:00
|
|
|
|
2020-11-09 09:06:44 +00:00
|
|
|
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
2020-06-07 07:26:23 +00:00
|
|
|
# FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
|
2020-11-09 09:06:44 +00:00
|
|
|
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
2020-06-07 07:26:23 +00:00
|
|
|
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> ${_compress_debug_sections_flag} -x assembler-with-cpp -o <OBJECT> -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm <INCLUDES> <FLAGS> <DEFINES> -D__ASM__ -c <SOURCE>")
|
2011-06-13 10:36:40 +00:00
|
|
|
|
2020-06-07 07:26:23 +00:00
|
|
|
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <INCLUDES> <FLAGS> -DRC_INVOKED -D__WIN32__=1 -D__FLAT__=1 ${I18N_DEFS} <DEFINES> <SOURCE> <OBJECT>")
|
2021-04-27 09:11:41 +00:00
|
|
|
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
|
|
|
set(RC_PREPROCESSOR_TARGET "--preprocessor-arg=--target=${CMAKE_C_COMPILER_TARGET}")
|
2020-09-10 21:23:14 +00:00
|
|
|
else()
|
2021-04-27 09:11:41 +00:00
|
|
|
set(RC_PREPROCESSOR_TARGET "")
|
2020-09-10 21:23:14 +00:00
|
|
|
endif()
|
|
|
|
|
2021-04-27 09:11:41 +00:00
|
|
|
# We have to pass args to windres. one... by... one...
|
|
|
|
set(CMAKE_DEPFILE_FLAGS_RC "--preprocessor=\"${CMAKE_C_COMPILER}\" ${RC_PREPROCESSOR_TARGET} --preprocessor-arg=-E --preprocessor-arg=-nostdinc --preprocessor-arg=-xc-header --preprocessor-arg=-MMD --preprocessor-arg=-MF --preprocessor-arg=<DEPFILE> --preprocessor-arg=-MT --preprocessor-arg=<OBJECT>")
|
2011-05-16 13:12:07 +00:00
|
|
|
|
|
|
|
# Optional 3rd parameter: stdcall stack bytes
|
2011-08-08 11:45:34 +00:00
|
|
|
function(set_entrypoint MODULE ENTRYPOINT)
|
2011-05-16 13:12:07 +00:00
|
|
|
if(${ENTRYPOINT} STREQUAL "0")
|
2021-09-13 16:51:08 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE "-Wl,-entry,0")
|
2012-08-27 18:58:27 +00:00
|
|
|
elseif(ARCH STREQUAL "i386")
|
2011-05-16 13:12:07 +00:00
|
|
|
set(_entrysymbol _${ENTRYPOINT})
|
2011-10-02 18:59:33 +00:00
|
|
|
if(${ARGC} GREATER 2)
|
2011-05-16 13:12:07 +00:00
|
|
|
set(_entrysymbol ${_entrysymbol}@${ARGV2})
|
|
|
|
endif()
|
2021-09-13 16:51:08 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE "-Wl,-entry,${_entrysymbol}")
|
2011-05-16 13:12:07 +00:00
|
|
|
else()
|
2021-09-13 16:51:08 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE "-Wl,-entry,${ENTRYPOINT}")
|
2011-05-16 13:12:07 +00:00
|
|
|
endif()
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-05-16 13:12:07 +00:00
|
|
|
|
2011-08-08 11:45:34 +00:00
|
|
|
function(set_subsystem MODULE SUBSYSTEM)
|
2021-09-13 16:51:08 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE "-Wl,--subsystem,${SUBSYSTEM}:5.01")
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-05-16 13:12:07 +00:00
|
|
|
|
2011-08-08 11:45:34 +00:00
|
|
|
function(set_image_base MODULE IMAGE_BASE)
|
2021-09-13 16:51:08 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE "-Wl,--image-base,${IMAGE_BASE}")
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-05-16 13:12:07 +00:00
|
|
|
|
2011-09-03 17:48:57 +00:00
|
|
|
function(set_module_type_toolchain MODULE TYPE)
|
2021-03-23 08:54:46 +00:00
|
|
|
# Set the PE image version numbers from the NT OS version ReactOS is based on
|
|
|
|
target_link_options(${MODULE} PRIVATE
|
|
|
|
-Wl,--major-image-version,5 -Wl,--minor-image-version,01 -Wl,--major-os-version,5 -Wl,--minor-os-version,01)
|
|
|
|
|
|
|
|
if(TYPE IN_LIST KERNEL_MODULE_TYPES)
|
2021-02-24 09:20:18 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE -Wl,--exclude-all-symbols,-file-alignment=0x1000,-section-alignment=0x1000)
|
2021-03-23 08:54:46 +00:00
|
|
|
|
2013-04-02 08:08:36 +00:00
|
|
|
if(${TYPE} STREQUAL "wdmdriver")
|
2021-02-24 09:20:18 +00:00
|
|
|
target_link_options(${MODULE} PRIVATE "-Wl,--wdmdriver")
|
2013-04-02 08:08:36 +00:00
|
|
|
endif()
|
2021-03-23 08:54:46 +00:00
|
|
|
|
2021-02-24 10:46:53 +00:00
|
|
|
# Place INIT &.rsrc section at the tail of the module, before .reloc
|
2021-02-23 17:29:13 +00:00
|
|
|
add_linker_script(${MODULE} ${REACTOS_SOURCE_DIR}/sdk/cmake/init-section.lds)
|
2021-03-23 08:54:46 +00:00
|
|
|
|
2021-02-24 10:46:53 +00:00
|
|
|
# Fixup section characteristics
|
|
|
|
# - Remove flags that LD overzealously puts (alignment flag, Initialized flags for code sections)
|
|
|
|
# - INIT section is made discardable
|
2021-04-08 14:50:51 +00:00
|
|
|
# - .rsrc is made read-only and discardable
|
2021-02-24 10:46:53 +00:00
|
|
|
# - PAGE & .edata sections are made pageable.
|
2021-02-24 09:20:18 +00:00
|
|
|
add_custom_command(TARGET ${MODULE} POST_BUILD
|
2021-02-24 10:46:53 +00:00
|
|
|
COMMAND native-pefixup --${TYPE} $<TARGET_FILE:${MODULE}>)
|
2021-03-23 08:54:46 +00:00
|
|
|
|
2021-02-24 09:20:18 +00:00
|
|
|
# Believe it or not, cmake doesn't do that
|
|
|
|
set_property(TARGET ${MODULE} APPEND PROPERTY LINK_DEPENDS $<TARGET_PROPERTY:native-pefixup,IMPORTED_LOCATION>)
|
2011-05-16 13:12:07 +00:00
|
|
|
endif()
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-05-16 13:12:07 +00:00
|
|
|
|
2013-07-14 11:44:21 +00:00
|
|
|
function(add_delay_importlibs _module)
|
|
|
|
get_target_property(_module_type ${_module} TYPE)
|
|
|
|
if(_module_type STREQUAL "STATIC_LIBRARY")
|
|
|
|
message(FATAL_ERROR "Cannot add delay imports to a static library")
|
|
|
|
endif()
|
2013-07-14 21:00:42 +00:00
|
|
|
foreach(_lib ${ARGN})
|
2017-12-31 12:08:39 +00:00
|
|
|
get_filename_component(_basename "${_lib}" NAME_WE)
|
|
|
|
target_link_libraries(${_module} lib${_basename}_delayed)
|
2011-06-10 20:44:47 +00:00
|
|
|
endforeach()
|
2013-07-14 11:44:21 +00:00
|
|
|
target_link_libraries(${_module} delayimp)
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-06-10 20:44:47 +00:00
|
|
|
|
2012-08-27 18:58:27 +00:00
|
|
|
if(NOT ARCH STREQUAL "i386")
|
2011-05-16 13:12:07 +00:00
|
|
|
set(DECO_OPTION "-@")
|
|
|
|
endif()
|
|
|
|
|
2020-04-13 10:20:47 +00:00
|
|
|
function(fixup_load_config _target)
|
2020-04-25 00:10:27 +00:00
|
|
|
add_custom_command(TARGET ${_target} POST_BUILD
|
2021-02-24 09:14:40 +00:00
|
|
|
COMMAND native-pefixup --loadconfig "$<TARGET_FILE:${_target}>"
|
2020-10-22 06:47:06 +00:00
|
|
|
COMMENT "Patching in LOAD_CONFIG"
|
|
|
|
DEPENDS native-pefixup)
|
2020-04-13 10:20:47 +00:00
|
|
|
endfunction()
|
|
|
|
|
2012-04-29 19:04:02 +00:00
|
|
|
function(generate_import_lib _libname _dllname _spec_file)
|
2014-03-24 20:54:01 +00:00
|
|
|
# Generate the def for the import lib
|
2012-04-29 19:04:02 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
|
2015-02-07 23:54:15 +00:00
|
|
|
COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
|
2012-04-29 19:04:02 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
|
|
|
|
|
2020-11-02 09:51:08 +00:00
|
|
|
# With this, we let DLLTOOL create an import library
|
|
|
|
set(LIBRARY_PRIVATE_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_libname}.dir)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${LIBRARY_PRIVATE_DIR}/${_libname}.a
|
|
|
|
# ar just puts stuff into the archive, without looking twice. Just delete the lib, we're going to rebuild it anyway
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E rm -f $<TARGET_FILE:${_libname}>
|
|
|
|
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def --kill-at --output-lib=${_libname}.a -t ${_libname}
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
|
|
|
|
WORKING_DIRECTORY ${LIBRARY_PRIVATE_DIR})
|
|
|
|
|
|
|
|
# We create a static library with the importlib thus created as object. AR will extract the obj files and archive it again as a thin lib
|
|
|
|
set_source_files_properties(
|
|
|
|
${LIBRARY_PRIVATE_DIR}/${_libname}.a
|
|
|
|
PROPERTIES
|
|
|
|
EXTERNAL_OBJECT TRUE)
|
|
|
|
_add_library(${_libname} STATIC EXCLUDE_FROM_ALL
|
|
|
|
${LIBRARY_PRIVATE_DIR}/${_libname}.a)
|
|
|
|
set_target_properties(${_libname}
|
|
|
|
PROPERTIES
|
|
|
|
LINKER_LANGUAGE "C"
|
|
|
|
PREFIX "")
|
|
|
|
|
|
|
|
# Do the same with delay-import libs
|
|
|
|
set(LIBRARY_PRIVATE_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_libname}_delayed.dir)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a
|
|
|
|
# ar just puts stuff into the archive, without looking twice. Just delete the lib, we're going to rebuild it anyway
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E rm -f $<TARGET_FILE:${_libname}_delayed>
|
|
|
|
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def --kill-at --output-delaylib=${_libname}_delayed.a -t ${_libname}_delayed
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
|
|
|
|
WORKING_DIRECTORY ${LIBRARY_PRIVATE_DIR})
|
|
|
|
|
|
|
|
# We create a static library with the importlib thus created. AR will extract the obj files and archive it again as a thin lib
|
|
|
|
set_source_files_properties(
|
|
|
|
${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a
|
|
|
|
PROPERTIES
|
|
|
|
EXTERNAL_OBJECT TRUE)
|
|
|
|
_add_library(${_libname}_delayed STATIC EXCLUDE_FROM_ALL
|
|
|
|
${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a)
|
|
|
|
set_target_properties(${_libname}_delayed
|
|
|
|
PROPERTIES
|
|
|
|
LINKER_LANGUAGE "C"
|
|
|
|
PREFIX "")
|
2012-04-29 19:04:02 +00:00
|
|
|
endfunction()
|
|
|
|
|
2011-08-08 11:45:34 +00:00
|
|
|
function(spec2def _dllname _spec_file)
|
2020-04-16 12:59:38 +00:00
|
|
|
|
2018-09-05 19:59:16 +00:00
|
|
|
cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
|
2012-04-20 12:39:00 +00:00
|
|
|
|
2014-03-24 20:54:01 +00:00
|
|
|
# Get library basename
|
2012-03-07 21:21:27 +00:00
|
|
|
get_filename_component(_file ${_dllname} NAME_WE)
|
2012-04-20 12:39:00 +00:00
|
|
|
|
2014-03-24 20:54:01 +00:00
|
|
|
# Error out on anything else than spec
|
2012-03-07 21:21:27 +00:00
|
|
|
if(NOT ${_spec_file} MATCHES ".*\\.spec")
|
|
|
|
message(FATAL_ERROR "spec2def only takes spec files as input.")
|
2011-08-15 15:36:25 +00:00
|
|
|
endif()
|
|
|
|
|
2020-05-26 18:24:02 +00:00
|
|
|
if(__spec2def_WITH_RELAY)
|
2014-09-25 18:25:02 +00:00
|
|
|
set(__with_relay_arg "--with-tracing")
|
|
|
|
endif()
|
|
|
|
|
2018-09-05 19:59:16 +00:00
|
|
|
if(__spec2def_VERSION)
|
|
|
|
set(__version_arg "--version=0x${__spec2def_VERSION}")
|
|
|
|
endif()
|
|
|
|
|
2014-03-24 20:54:01 +00:00
|
|
|
# Generate exports def and C stubs file for the DLL
|
2011-05-16 13:12:07 +00:00
|
|
|
add_custom_command(
|
2011-06-26 21:29:55 +00:00
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
|
2018-09-05 19:59:16 +00:00
|
|
|
COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
|
2011-08-05 20:40:40 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
|
2012-04-02 15:27:35 +00:00
|
|
|
|
2014-09-25 18:25:02 +00:00
|
|
|
if(__spec2def_ADD_IMPORTLIB)
|
2015-02-07 23:54:15 +00:00
|
|
|
set(_extraflags)
|
|
|
|
if(__spec2def_NO_PRIVATE_WARNINGS)
|
|
|
|
set(_extraflags --no-private-warnings)
|
|
|
|
endif()
|
2020-04-16 12:59:38 +00:00
|
|
|
|
2015-02-07 23:54:15 +00:00
|
|
|
generate_import_lib(lib${_file} ${_dllname} ${_spec_file} ${_extraflags})
|
2012-03-07 21:21:27 +00:00
|
|
|
endif()
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-05-16 13:12:07 +00:00
|
|
|
|
2011-10-03 19:09:26 +00:00
|
|
|
macro(macro_mc FLAG FILE)
|
2016-09-28 23:20:20 +00:00
|
|
|
set(COMMAND_MC ${CMAKE_MC_COMPILER} -u ${FLAG} -b -h ${CMAKE_CURRENT_BINARY_DIR}/ -r ${CMAKE_CURRENT_BINARY_DIR}/ ${FILE})
|
2011-05-16 13:12:07 +00:00
|
|
|
endmacro()
|
|
|
|
|
2014-03-24 20:54:01 +00:00
|
|
|
# PSEH lib, needed with mingw
|
2011-05-16 13:12:07 +00:00
|
|
|
set(PSEH_LIB "pseh")
|
2011-06-02 12:18:22 +00:00
|
|
|
|
2012-04-20 12:39:00 +00:00
|
|
|
function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_address)
|
2011-06-09 13:56:44 +00:00
|
|
|
set(_object_file ${_binary_file}.o)
|
|
|
|
|
2020-03-06 21:55:12 +00:00
|
|
|
get_defines(_defines)
|
|
|
|
get_includes(_includes)
|
|
|
|
|
2011-06-09 13:56:44 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_object_file}
|
2020-03-06 21:55:12 +00:00
|
|
|
COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm ${_includes} ${_defines} -D__ASM__ -c ${_asm_file}
|
2011-06-09 13:56:44 +00:00
|
|
|
DEPENDS ${_asm_file})
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_binary_file}
|
|
|
|
COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
|
|
|
|
# COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
|
2011-08-05 20:40:40 +00:00
|
|
|
DEPENDS ${_object_file} native-obj2bin)
|
2011-06-09 13:56:44 +00:00
|
|
|
|
|
|
|
set_source_files_properties(${_object_file} ${_binary_file} PROPERTIES GENERATED TRUE)
|
|
|
|
|
|
|
|
add_custom_target(${_target_name} ALL DEPENDS ${_binary_file})
|
2011-08-08 11:45:34 +00:00
|
|
|
endfunction()
|
2011-09-04 17:32:30 +00:00
|
|
|
|
|
|
|
function(allow_warnings __module)
|
2015-04-19 08:39:58 +00:00
|
|
|
# We don't allow warnings in trunk, this needs to be reworked. See CORE-6959.
|
2020-04-16 12:59:38 +00:00
|
|
|
#target_compile_options(${__module} PRIVATE "-Wno-error")
|
2011-09-04 17:32:30 +00:00
|
|
|
endfunction()
|
2013-01-08 20:33:08 +00:00
|
|
|
|
2022-06-20 15:29:01 +00:00
|
|
|
function(convert_asm_file _source_file _target_file)
|
|
|
|
get_filename_component(_source_file_base_name ${_source_file} NAME_WE)
|
|
|
|
get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
|
|
|
|
set(_preprocessed_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target_file})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_preprocessed_asm_file}
|
|
|
|
COMMAND native-asmpp ${_source_file_full_path} > ${_preprocessed_asm_file}
|
|
|
|
DEPENDS native-asmpp ${_source_file_full_path})
|
|
|
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(convert_asm_files)
|
|
|
|
foreach(_source_file ${ARGN})
|
|
|
|
convert_asm_file(${_source_file} ${_source_file}.s)
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2013-01-08 20:33:08 +00:00
|
|
|
macro(add_asm_files _target)
|
2022-06-20 15:29:01 +00:00
|
|
|
foreach(_source_file ${ARGN})
|
|
|
|
get_filename_component(_extension ${_source_file} EXT)
|
|
|
|
get_filename_component(_source_file_base_name ${_source_file} NAME_WE)
|
|
|
|
if (${_extension} STREQUAL ".asm")
|
|
|
|
convert_asm_file(${_source_file} ${_source_file}.s)
|
|
|
|
list(APPEND ${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_source_file}.s)
|
|
|
|
elseif (${_extension} STREQUAL ".inc")
|
|
|
|
convert_asm_file(${_source_file} ${_source_file}.h)
|
|
|
|
list(APPEND ${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_source_file}.h)
|
|
|
|
else()
|
|
|
|
list(APPEND ${_target} ${_source_file})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2013-01-08 20:33:08 +00:00
|
|
|
endmacro()
|
2019-02-09 23:43:31 +00:00
|
|
|
|
|
|
|
function(add_linker_script _target _linker_script_file)
|
|
|
|
get_filename_component(_file_full_path ${_linker_script_file} ABSOLUTE)
|
2021-09-13 16:51:08 +00:00
|
|
|
target_link_options(${_target} PRIVATE "-Wl,-T,${_file_full_path}")
|
|
|
|
set_property(TARGET ${_target} APPEND PROPERTY LINK_DEPENDS ${_file_full_path})
|
2019-02-09 23:43:31 +00:00
|
|
|
endfunction()
|
2020-09-18 07:34:18 +00:00
|
|
|
|
|
|
|
# Manage our C++ options
|
|
|
|
# we disable standard includes if we don't use the STL
|
|
|
|
add_compile_options("$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<IN_LIST:cppstl,$<TARGET_PROPERTY:LINK_LIBRARIES>>>>:-nostdinc>")
|
|
|
|
# we disable RTTI, unless said so
|
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<IF:$<BOOL:$<TARGET_PROPERTY:WITH_CXX_RTTI>>,-frtti,-fno-rtti>>")
|
|
|
|
# We disable exceptions, unless said so
|
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<IF:$<BOOL:$<TARGET_PROPERTY:WITH_CXX_EXCEPTIONS>>,-fexceptions,-fno-exceptions>>")
|
|
|
|
|
2021-04-28 21:52:45 +00:00
|
|
|
# G++ shipped with ROSBE uses sjlj exceptions on i386. Tell Clang it is so
|
2022-05-25 22:37:23 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND ARCH STREQUAL "i386")
|
2020-09-10 21:23:14 +00:00
|
|
|
add_compile_options("$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:$<TARGET_PROPERTY:WITH_CXX_EXCEPTIONS>>>:-fsjlj-exceptions>")
|
|
|
|
endif()
|
|
|
|
|
2020-09-18 07:34:18 +00:00
|
|
|
# Find default G++ libraries
|
2022-05-25 22:37:23 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
2020-09-10 21:23:14 +00:00
|
|
|
set(GXX_EXECUTABLE ${CMAKE_CXX_COMPILER_TARGET}-g++)
|
|
|
|
else()
|
|
|
|
set(GXX_EXECUTABLE ${CMAKE_CXX_COMPILER})
|
|
|
|
endif()
|
|
|
|
|
2020-09-18 07:34:18 +00:00
|
|
|
add_library(libgcc STATIC IMPORTED)
|
2020-09-10 21:23:14 +00:00
|
|
|
execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libgcc.a OUTPUT_VARIABLE LIBGCC_LOCATION)
|
2020-09-18 07:34:18 +00:00
|
|
|
string(STRIP ${LIBGCC_LOCATION} LIBGCC_LOCATION)
|
|
|
|
set_target_properties(libgcc PROPERTIES IMPORTED_LOCATION ${LIBGCC_LOCATION})
|
|
|
|
# libgcc needs kernel32 imports, a CRT and msvcrtex
|
|
|
|
target_link_libraries(libgcc INTERFACE libkernel32 libmsvcrt msvcrtex)
|
|
|
|
|
|
|
|
add_library(libsupc++ STATIC IMPORTED GLOBAL)
|
2020-09-10 21:23:14 +00:00
|
|
|
execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libsupc++.a OUTPUT_VARIABLE LIBSUPCXX_LOCATION)
|
2020-09-18 07:34:18 +00:00
|
|
|
string(STRIP ${LIBSUPCXX_LOCATION} LIBSUPCXX_LOCATION)
|
|
|
|
set_target_properties(libsupc++ PROPERTIES IMPORTED_LOCATION ${LIBSUPCXX_LOCATION})
|
|
|
|
# libsupc++ requires libgcc
|
|
|
|
target_link_libraries(libsupc++ INTERFACE libgcc)
|
|
|
|
|
|
|
|
add_library(libmingwex STATIC IMPORTED)
|
2020-09-10 21:23:14 +00:00
|
|
|
execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libmingwex.a OUTPUT_VARIABLE LIBMINGWEX_LOCATION)
|
2020-09-18 07:34:18 +00:00
|
|
|
string(STRIP ${LIBMINGWEX_LOCATION} LIBMINGWEX_LOCATION)
|
|
|
|
set_target_properties(libmingwex PROPERTIES IMPORTED_LOCATION ${LIBMINGWEX_LOCATION})
|
|
|
|
# libmingwex requires a CRT and imports from kernel32
|
|
|
|
target_link_libraries(libmingwex INTERFACE libmsvcrt libkernel32)
|
|
|
|
|
|
|
|
add_library(libstdc++ STATIC IMPORTED GLOBAL)
|
2020-09-10 21:23:14 +00:00
|
|
|
execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCCXX_LOCATION)
|
2020-09-18 07:34:18 +00:00
|
|
|
string(STRIP ${LIBSTDCCXX_LOCATION} LIBSTDCCXX_LOCATION)
|
|
|
|
set_target_properties(libstdc++ PROPERTIES IMPORTED_LOCATION ${LIBSTDCCXX_LOCATION})
|
|
|
|
# libstdc++ requires libsupc++ and mingwex provided by GCC
|
|
|
|
target_link_libraries(libstdc++ INTERFACE libsupc++ libmingwex)
|
|
|
|
# this is for our SAL annotations
|
|
|
|
target_compile_definitions(libstdc++ INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:PAL_STDCPP_COMPAT>")
|
|
|
|
|
|
|
|
# Create our alias libraries
|
|
|
|
add_library(cppstl ALIAS libstdc++)
|
|
|
|
add_library(cpprt ALIAS libsupc++)
|
|
|
|
|