Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Fix building on macOS #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/functional/gl_basic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,34 @@ CREATE_TESTSUITE(WAFFLE_PLATFORM_WGL, wgl)
#undef test_XX_rgba
#undef test_XX_rgb

#ifdef __APPLE__

static void
removeArg(int index, int *argc, char **argv)
{
--*argc;
for (; index < *argc; ++index)
argv[index] = argv[index + 1];
}

static void
removeXcodeArgs(int *argc, char **argv)
{
// Xcode sometimes adds additional arguments.
for (int i = 1; i < *argc; )
{
if (strcmp(argv[i], "-NSDocumentRevisionsDebugMode") == 0 ||
strcmp(argv[i], "-ApplePersistenceIgnoreState" ) == 0)
{
removeArg(i, argc, argv);
removeArg(i, argc, argv);
} else
++i;
}
}

#endif // __APPLE__

static const char *usage_message =
"Usage:\n"
" gl_basic_test <Required Parameter> [Options]\n"
Expand Down
1 change: 1 addition & 0 deletions third_party/cmocka/.clang_complete
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-Iinclude
-Iobj
4 changes: 3 additions & 1 deletion third_party/cmocka/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.swp
*~$
build
tags
cscope.*
.ycm_extra_conf.pyc
/build
/obj*
109 changes: 109 additions & 0 deletions third_party/cmocka/.ycm_extra_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import os
import ycm_core

flags = [
'-Wall',
'-Wextra',
'-Werror',
'-x', 'c',
'-Iinclude',
]

# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = 'obj'

if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None

SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]

def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )


def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag

if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )

for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break

if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break

if new_flag:
new_flags.append( new_flag )
return new_flags


def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]


def GetCompilationInfoForFile( filename ):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
compilation_info = database.GetCompilationInfoForFile(
replacement_file )
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )


def FlagsForFile( filename, **kwargs ):
if database:
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None

final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )

# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
try:
final_flags.remove( '-stdlib=libc++' )
except ValueError:
pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )

return {
'flags': final_flags,
'do_cache': True
}
10 changes: 8 additions & 2 deletions third_party/cmocka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6.0)
set(APPLICATION_NAME ${PROJECT_NAME})

set(APPLICATION_VERSION_MAJOR "1")
set(APPLICATION_VERSION_MINOR "0")
set(APPLICATION_VERSION_MINOR "1")
set(APPLICATION_VERSION_PATCH "1")

set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
Expand All @@ -19,7 +19,7 @@ set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
# Increment AGE. Set REVISION to 0
# If the source code was changed, but there were no interface changes:
# Increment REVISION.
set(LIBRARY_VERSION "0.3.1")
set(LIBRARY_VERSION "0.4.1")
set(LIBRARY_SOVERSION "0")

# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
Expand All @@ -34,6 +34,7 @@ include(DefineCompilerFlags)
include(DefineInstallationPaths)
include(DefineOptions.cmake)
include(CPackConfig.cmake)
include(CheckSymbolExists)

# disallow in-source build
include(MacroEnsureOutOfSourceBuild)
Expand All @@ -43,6 +44,11 @@ macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source buil
include(ConfigureChecks.cmake)
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

# MinGW DLL Naming Workaround
if (MINGW)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif (MINGW)

# check subdirectories
add_subdirectory(doc)
add_subdirectory(include)
Expand Down
2 changes: 1 addition & 1 deletion third_party/cmocka/CPackConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSIO

### source generator
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;obj*;tags;cscope.*;.ycm_extra_conf.pyc")
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/obj*;tags;cscope.*;.ycm_extra_conf.pyc")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")

if (WIN32)
Expand Down
18 changes: 18 additions & 0 deletions third_party/cmocka/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Fri Apr 07 2016 Andreas Schneider <[email protected]>
* cmocka: version 1.1.1
* Fixed TAP output
* Fixed cmocka on Windows x64
* Fixed xUnit output durations

Wed Sep 21 2016 Andreas Schneider <[email protected]>
* cmocka: version 1.1.0
* Added support to catch multiple exceptions
* Added support to verify call ordering
* Added support to pass initial data to test cases
* Added will_return_maybe() for ignoring mock returns
* Added subtests for groups using TAP output
* Added support to write multiple XML files for groups
* Improved documentation
* Fixed XML output generataion
* Fixed Windows builds with VS2015

Thu Mar 12 2015 Andreas Schneider <[email protected]>
* cmocka: version 1.0.1
* Added a macro for assert_ptr_equal().
Expand Down
26 changes: 16 additions & 10 deletions third_party/cmocka/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,33 @@ check_function_exists(exit HAVE_EXIT)
check_function_exists(fprintf HAVE_FPRINTF)
check_function_exists(free HAVE_FREE)
check_function_exists(longjmp HAVE_LONGJMP)
check_function_exists(siglongjmp HAVE_SIGLONGJMP)
check_function_exists(malloc HAVE_MALLOC)
check_function_exists(memcpy HAVE_MEMCPY)
check_function_exists(memset HAVE_MEMSET)
check_function_exists(printf HAVE_PRINTF)
check_function_exists(setjmp HAVE_SETJMP)
check_function_exists(signal HAVE_SIGNAL)
check_function_exists(strsignal HAVE_STRSIGNAL)
check_function_exists(sprintf HAVE_SNPRINTF)
check_function_exists(strcmp HAVE_STRCMP)
check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)

if (WIN32)
check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
check_function_exists(_vsnprintf HAVE__VSNPRINTF)
check_function_exists(_snprintf HAVE__SNPRINTF)
check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF)
else (WIN32)
check_function_exists(sprintf HAVE_SNPRINTF)
check_function_exists(vsnprintf HAVE_VSNPRINTF)
endif (WIN32)

find_library(RT_LIBRARY rt)
if (RT_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
endif (RT_LIBRARY)

set(CMOCKA_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "cmocka required system libraries")
if (RT_LIBRARY AND NOT LINUX)
set(CMOCKA_REQUIRED_LIBRARIES ${RT_LIBRARY} CACHE INTERNAL "cmocka required system libraries")
endif ()

# OPTIONS
check_c_source_compiles("
Expand All @@ -120,9 +122,10 @@ int main(void) {
endif(WIN32)

if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME)
set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
if (RT_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
endif()

message(STATUS "CMAKE_REQUIRED_INCLUDES=${CMAKE_REQUIRED_INCLUDES} CMAKE_REQUIRED_LIBRARIES=${CMAKE_REQUIRED_LIBRARIES}")
check_c_source_compiles("
#include <time.h>

Expand All @@ -132,8 +135,11 @@ int main(void) {
clock_gettime(CLOCK_REALTIME, &ts);

return 0;
}" HAVE_CLOCK_GETTIME_REALTIME)
}" HAVE_CLOCK_REALTIME)

# reset cmake requirements
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)
endif ()

# ENDIAN
Expand Down
29 changes: 28 additions & 1 deletion third_party/cmocka/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ GNU/Linux, MacOS X, MSYS/MinGW:
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make

On Windows you should choose a makefile gernerator with -G.
On Windows you should choose a makefile gernerator with -G, for example:

cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Debug /path/to/source

You can also use the CMake GUI which is shipped with CMake. It will list all
available generators for MSVC on Windows.

### CMake standard options
Here is a list of the most interesting options provided out of the box by
Expand Down Expand Up @@ -66,6 +71,28 @@ The cmocka library can be found in the `build/src` directory.
You can run the binaries in `build/examples/*` which is a
are exsample tests.

## Testing

As mention above you can turn on the unit tests and make it possible to easily
execute them:

`cmake -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..`

After that you can simply call `make test` in the build directory or if you
want more output simply call `ctest -V`.

If you want to enable the generation of coverage files you can do this by
using the following options:

`cmake -DCMAKE_BUILD_TYPE=Profiling -DUNIT_TESTING=ON ..`

After building it you will see that you have several coverage options in

`make help`

You should have `make ExperimentalCoverage` and running it will create
coverage files. The result is stored in Testing directory.

## About this document

This document is written using [Markdown][] syntax, making it possible to
Expand Down
2 changes: 1 addition & 1 deletion third_party/cmocka/cmake/Modules/DefineCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (UNIX AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute -Wundef")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute -Wundef -Wstrict-prototypes")

# with -fPIC
check_c_compiler_flag("-fPIC" WITH_FPIC)
Expand Down
5 changes: 4 additions & 1 deletion third_party/cmocka/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
/* Define to 1 if you have the `longjmp' function. */
#cmakedefine HAVE_LONGJMP 1

/* Define to 1 if you have the `siglongjmp' function. */
#cmakedefine HAVE_SIGLONGJMP 1

/* Define to 1 if you have the `malloc' function. */
#cmakedefine HAVE_MALLOC 1

Expand Down Expand Up @@ -155,7 +158,7 @@
#cmakedefine HAVE_MSVC_THREAD_LOCAL_STORAGE 1

/* Check if we have CLOCK_REALTIME for clock_gettime() */
#cmakedefine HAVE_CLOCK_GETTIME_REALTIME 1
#cmakedefine HAVE_CLOCK_REALTIME 1

/*************************** ENDIAN *****************************/

Expand Down
Loading