Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CMake support for Visual Studio/Xcode/Android generator #1594

Merged
merged 27 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
12d5624
Merged with upstream
Oct 1, 2016
f3aceb0
Updated boost submodule to latest version
Oct 1, 2016
eac042c
Updated boost submodule to latest version
Oct 1, 2016
b55ac1c
Added cmake support for Visual Studio generator
Oct 1, 2016
db1ee14
Combined adding of FreeType defines
Oct 1, 2016
7b0fc60
Added toolchain configuration CMake files for Android
Oct 2, 2016
0344c7a
Added architectural flags and include paths for Android
Oct 2, 2016
e4b5aa1
Updated for building Android on Linux
Oct 2, 2016
9f70b28
Added some clarification comments
Oct 2, 2016
ecea23f
Merge branch 'android_linux' of github.com:chaoticbob/Cinder into and…
Oct 2, 2016
e2f161b
Updated library output location for Windows
Oct 3, 2016
57336d4
Tweaked for Xcode project generation
Oct 3, 2016
ead79ef
Added host definition for Android building on macOS host
Oct 3, 2016
76f8781
Moved platform specific libs for Windows to more explicit location
Oct 4, 2016
7963612
Merge branch 'android_linux' of github.com:chaoticbob/Cinder into and…
Oct 4, 2016
c47e1de
Moved msw platform libraries to be dependencies on libcinder
Oct 4, 2016
edcb00e
Merge remote-tracking branch 'upstream/android_linux' into android_linux
Oct 4, 2016
e8d2c32
Cleaned up msw depends
Oct 4, 2016
4e25321
Removed unnecessary public definition for library
Oct 5, 2016
29dc378
Added x64 target
Oct 9, 2016
af3496f
Added STB source and target files
Oct 9, 2016
092bb44
Added static lib deps and flags to allow cross usage of CMake and han…
Oct 9, 2016
d7a539f
Removed references to WIC sources. Added STB files.
Oct 9, 2016
fb32789
Updated to allow cross builds between CMake and Xcode
Oct 9, 2016
b9d24d7
Updated to support cross builds with make and Ninja
Oct 9, 2016
9f99062
Added x64 targets
Oct 9, 2016
81d948f
Updated for cross building with NMake and Ninja
Oct 9, 2016
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
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
cmake_minimum_required( VERSION 3.0 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

# Configure the Android toolchain before the project start
if( CINDER_TARGET )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a part of configure.cmake, which sets up the CINDER_TARGET along with other important variables used on all platforms.

But perhaps the cinderAndreoidToolchain.cmake must be included before the call to project( cinder )? If that is the case, I think that the project() call can be moved to after the include( configure.cmake ).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler checks seem to happen when you project() is called. I think on most platform this is fine, but on Android since we have to do a manual toolchain setup, it needs to happen before project(). Certainly not married to this solution, so if we can move stuff around to make it more sane, would be great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seems that the proper ( in terms of CMake ) way to do this would be using CMake's toolchain functionality. See here and here. This functionality would also be interesting to explore in the case of Linux / RPi .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, forgot about the toolchain feature. I'll move this to a toolchain file approach over the weekend.

string( TOLOWER "${CINDER_TARGET}" CINDER_TARGET_LOWER )
if( "android" STREQUAL "${CINDER_TARGET_LOWER}" )
include( "${CMAKE_CURRENT_SOURCE_DIR}/proj/cmake/modules/cinderAndroidToolchain.cmake" )
endif()
endif()

# Project start
project( cinder )

option( CINDER_BUILD_SAMPLES "Build all samples." OFF )
Expand Down
15 changes: 9 additions & 6 deletions proj/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ if( CINDER_LINUX )
elseif( CINDER_MAC )
set( CINDER_TARGET_SUBFOLDER "macosx" )
elseif( CINDER_ANDROID )
set( CINDER_ANDROID_NDK_PLATFORM 21 CACHE STRING "Android NDK Platform version number." )
set( CINDER_ANDROID_NDK_ARCH "armeabi-v7a" CACHE STRING "Android NDK target architecture." )

set( CINDER_TARGET_SUBFOLDER "android-${CINDER_ANDROID_NDK_PLATFORM/CINDER_ANDROID_NDK_ARCH" )
#set( CINDER_ANDROID_NDK_PLATFORM 21 CACHE STRING "Android NDK Platform version number." )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to expose these variables to the cmake cache somehow?

Also, I do like that they are in configure.cmake as this file is shared by both libcinder and app builds.

#set( CINDER_ANDROID_NDK_ARCH "armeabi-v7a" CACHE STRING "Android NDK target architecture." )
set( CINDER_TARGET_SUBFOLDER "android/android-${CINDER_ANDROID_NDK_PLATFORM}/${CINDER_ANDROID_NDK_ARCH}" )
elseif( CINDER_MSW )
set( CINDER_TARGET_SUBFOLDER "msw" ) # TODO: place in msw/arch folder (x64 or x86)
set( CINDER_ARCH "x86" )
if( CMAKE_CL_64 )
set( CINDER_ARCH "x64" )
endif()
set( CINDER_TARGET_SUBFOLDER "msw/${CINDER_ARCH}" ) # TODO: place in msw/arch folder (x64 or x86)
endif()

# CINDER_LIB_DIRECTORY is the platform-specific, relative path that will be used to define
# CMAKE_ARCHIVE_OUTPUT_DIRECTORY for libcinder and also specifies where user apps will locate the cinder package
set( CINDER_LIB_DIRECTORY lib/${CINDER_TARGET_SUBFOLDER}/${CMAKE_BUILD_TYPE}/ )
set( CINDER_LIB_DIRECTORY "lib/${CINDER_TARGET_SUBFOLDER}/${CMAKE_BUILD_TYPE}/" )
2 changes: 1 addition & 1 deletion proj/cmake/libcinder_configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else()
list( APPEND CINDER_INCLUDE_SYSTEM_PRIVATE
${CINDER_INC_DIR}/freetype
)
list( APPEND CINDER_DEFINES "-DFT2_BUILD_LIBRARY -DFT_DEBUG_LEVEL_TRACE" )
list( APPEND CINDER_DEFINES "-DFT2_BUILD_LIBRARY;-DFT_DEBUG_LEVEL_TRACE" )
endif()

# declare whether AntTweakBar is available (isn't on mobile devices)
Expand Down
4 changes: 2 additions & 2 deletions proj/cmake/libcinder_source_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ list( APPEND SRC_SET_CINDER
${CINDER_SRC_DIR}/cinder/Xml.cpp
)

if( NOT CINDER_LINUX )
if( ( NOT CINDER_LINUX ) AND ( NOT CINDER_ANDROID ) )
list( APPEND SRC_SET_CINDER
${CINDER_SRC_DIR}/cinder/Capture.cpp
${CINDER_SRC_DIR}/cinder/Serial.cpp
)
endif()

if( NOT CINDER_MSW )
if( ( NOT CINDER_MSW ) AND ( NOT CINDER_ANDROID ) )
list( APPEND SRC_SET_CINDER
${CINDER_SRC_DIR}/cinder/UrlImplCurl.cpp
)
Expand Down
83 changes: 74 additions & 9 deletions proj/cmake/libcinder_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif()
# and when ON as a shared library.
# See https://cmake.org/cmake/help/v3.0/command/add_library.html for more info.
add_library(
cinder
cinder
${CINDER_SRC_FILES}
)

Expand All @@ -24,19 +24,83 @@ target_include_directories( cinder SYSTEM BEFORE INTERFACE ${CINDER_INCLUDE_SYST
target_include_directories( cinder BEFORE PRIVATE ${CINDER_INCLUDE_USER_PRIVATE} )
target_include_directories( cinder SYSTEM BEFORE PRIVATE ${CINDER_INCLUDE_SYSTEM_PRIVATE} )

target_link_libraries( cinder PUBLIC ${CINDER_LIBS_DEPENDS} )
target_link_libraries( cinder PUBLIC ${CINDER_LIBS_DEPENDS} )

target_compile_definitions( cinder PUBLIC ${CINDER_DEFINES} )

# Visual Studio and Xcode generators adds a ${CMAKE_BUILD_TYPE} to the ARCHIVE
# and LIBRARY directories. Override the directories so, ${CMAKE_BUILD_TYPE} doesn't double up.
if( CINDER_MSW )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this live in platform_msw.cmake?

set( PLATFORM_TOOLSET "$(PlatformToolset)" )
if( NOT ( "${CMAKE_GENERATOR}" MATCHES "Visual Studio.+" ) )
# Assume Visual Studio 2015
set( PLATFORM_TOOLSET "v140" )
if( MSVC_VERSION LESS 1900 ) # Visual Studio 2013
set( PLATFORM_TOOLSET "v120" )
elseif( MSVC_VERSION LESS 1800 )
message( FATAL_ERROR "Unsupported MSVC version: ${MSVC_VERSION}" )
endif()
endif()

set( OUTPUT_DIRECTORY_BASE "${CINDER_PATH}/lib/${CINDER_TARGET_SUBFOLDER}" )
set_target_properties( cinder PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY_BASE}/Debug/${PLATFORM_TOOLSET}"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY_BASE}/Release/${PLATFORM_TOOLSET}"
ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL "${OUTPUT_DIRECTORY_BASE}/MinSizeRel/${PLATFORM_TOOLSET}"
ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIRECTORY_BASE}/RelWithDebInfo/${PLATFORM_TOOLSET}"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY_BASE}/Debug/${PLATFORM_TOOLSET}|"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY_BASE}/Release/${PLATFORM_TOOLSET}"
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${OUTPUT_DIRECTORY_BASE}/MinSizeRel/${PLATFORM_TOOLSET}"
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIRECTORY_BASE}/RelWithDebInfo/${PLATFORM_TOOLSET}"
STATIC_LIBRARY_FLAGS_DEBUG "${CINDER_STATIC_LIBS_FLAGS_DEBUG} ${CINDER_STATIC_LIBS_DEPENDS_DEBUG}"
STATIC_LIBRARY_FLAGS_RELEASE "${CINDER_STATIC_LIBS_FLAGS_RELEASE} ${CINDER_STATIC_LIBS_DEPENDS_RELEASE}"
STATIC_LIBRARY_FLAGS_MINSIZEREL "${CINDER_STATIC_LIBS_FLAGS_RELEASE} ${CINDER_STATIC_LIBS_DEPENDS_RELEASE}"
STATIC_LIBRARY_FLAGS_RELWITHDEBINFO "${CINDER_STATIC_LIBS_FLAGS_RELEASE} ${CINDER_STATIC_LIBS_DEPENDS_RELEASE}"
)
elseif( CINDER_MAC )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this live in platform_macosx.cmake?

set( OUTPUT_DIRECTORY_BASE "${CINDER_PATH}/lib/${CINDER_TARGET_SUBFOLDER}" )
set_target_properties( cinder PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY_BASE}/Debug"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY_BASE}/Release"
ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL "${OUTPUT_DIRECTORY_BASE}/MinSizeRel"
ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIRECTORY_BASE}/RelWithDebInfo"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY_BASE}/Debug"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY_BASE}/Release"
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${OUTPUT_DIRECTORY_BASE}/MinSizeRel"
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIRECTORY_BASE}/RelWithDebInfo"
STATIC_LIBRARY_FLAGS "${CINDER_STATIC_LIBS_DEPENDS}"
)
elseif( CINDER_COCOA_TOUCH )
endif()

# Check compiler support for enabling c++11 or c++14.
include( CheckCXXCompilerFlag )
CHECK_CXX_COMPILER_FLAG( "-std=c++14" COMPILER_SUPPORTS_CXX14 )
CHECK_CXX_COMPILER_FLAG( "-std=c++11" COMPILER_SUPPORTS_CXX11 )
if( CINDER_MSW AND MSVC )
if( MSVC_VERSION LESS 1800 ) # Older version of Visual Studio
message( FATAL_ERROR "Unsupported MSVC version: ${MSVC_VERSION}" )
elseif( MSVC_VERSION LESS 1900 ) # Visual Studio 2013
set( COMPILER_SUPPORTS_CXX11 true )
else() # Visual Studio 2015
set( COMPILER_SUPPORTS_CXX14 true )
set( COMPILER_SUPPORTS_CXX11 true )
endif()
elseif( CINDER_ANDROID )
# Assume true for Android since compiler is Clang 3.8 at minimum
set( COMPILER_SUPPORTS_CXX14 true )
set( COMPILER_SUPPORTS_CXX11 true )
else()
include( CheckCXXCompilerFlag )
CHECK_CXX_COMPILER_FLAG( "-std=c++14" COMPILER_SUPPORTS_CXX14 )
CHECK_CXX_COMPILER_FLAG( "-std=c++11" COMPILER_SUPPORTS_CXX11 )
endif()

if( COMPILER_SUPPORTS_CXX14 )
set( CINDER_CXX_FLAGS "-std=c++14" )
if( NOT MSVC )
set( CINDER_CXX_FLAGS "-std=c++14" )
endif()
elseif( COMPILER_SUPPORTS_CXX11 )
set( CINDER_CXX_FLAGS "-std=c++11" )
if( NOT MSVC )
set( CINDER_CXX_FLAGS "-std=c++11" )
endif()
else()
message( FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has neither C++11 or C++14 support. Please use a different C++ compiler." )
endif()
Expand All @@ -51,7 +115,8 @@ export( TARGETS cinder FILE ${PROJECT_BINARY_DIR}/${CINDER_LIB_DIRECTORY}/cinder

# And this command will generate a file on the ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
# that applications have to pull in order to link successfully with Cinder and its dependencies.
# This specific cinderConfig.cmake file will just hold a path to the above mention cinderTargets.cmake file which holds the actual info.
# This specific cinderConfig.cmake file will just hold a path to the above mention
# cinderTargets.cmake file which holds the actual info.
configure_file( ${CMAKE_CURRENT_LIST_DIR}/modules/cinderConfig.buildtree.cmake.in
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/cinderConfig.cmake
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/cinderConfig.cmake"
)
159 changes: 159 additions & 0 deletions proj/cmake/modules/cinderAndroidToolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
message( STATUS "Configuring Android toolcahin for Cinder" )

# Force some known options
set( CINDER_GL_ES true )

# NDK path
if( NOT CINDER_ANDROID_NDK_DIR )
# Look at environment variable NDK_DIR
if( $ENV{NDK_DIR} )
set( CINDER_ANDROID_NDK_DIR "$ENV{NDK_DIR}" )
endif()
endif()
# Make sure there's an NDK dir specified
if( NOT CINDER_ANDROID_NDK_DIR )
message( FATAL_ERROR "NDK directory not found, use -DCINDER_ANDROID_NDK_DIR=<path> or environment variable NDK_DIR to specify" )
endif()
# Make sure the specified NDK dir exists
if( NOT EXISTS "${CINDER_ANDROID_NDK_DIR}" )
message( FATAL_ERROR "Specified NDK directory does not exist: ${CINDER_ANDROID_NDK_DIR}" )
endif()

# NDK platform - defaults to platform 24
if( NOT CINDER_ANDROID_NDK_PLATFORM )
set( CINDER_ANDROID_NDK_PLATFORM 24 )
endif()
# Check for minimum platform
if( ${CINDER_ANDROID_NDK_PLATFORM} LESS 24 )
message( FATAL_ERROR "Cinder requires platform 24 or later" )
endif()

# NDK architecture - defaults to ARMV8
if( NOT CINDER_ANDROID_NDK_ARCH )
set( CINDER_ANDROID_NDK_ARCH "arm64-v8a" )
endif()
# Validate architecture
string( TOLOWER "${CINDER_ANDROID_NDK_ARCH}" CINDER_ANDROID_NDK_ARCH_LOWER )
if( NOT "${CINDER_ANDROID_NDK_ARCH_LOWER}" MATCHES "^(armeabi|armeabi-v7a|arm64-v8a|x86|x86_64|mips|mips64)$" )
message( FATAL_ERROR "Unknown NDK architecture: ${CINDER_ANDROID_NDK_ARCH}, supported architectures: armeabi,armeabi-v7a,arm64-v8a,x86,x86_64,mips,mips64" )
endif()

# NDK host
if( APPLE )
set( CINDER_ANDROID_NDK_HOST "darwin-x86_64" )
elseif( UNIX )
set( CINDER_ANDROID_NDK_HOST "linux-x86_64" )
elseif( WIN32 )
set( CINDER_ANDROID_NDK_HOST "windows-x86_64" )
set( EXE_SUFFIX ".exe" )
else()
message( FATAL_ERROR "Unkonwn NDK host system" )
endif()

# Print relevant information
message( STATUS "Using NDK at ${CINDER_ANDROID_NDK_DIR}" )
message( STATUS "Using NDK platform ${CINDER_ANDROID_NDK_PLATFORM}" )
message( STATUS "Using NDK architecture ${CINDER_ANDROID_NDK_ARCH_LOWER}" )
message( STATUS "Using NDK host ${CINDER_ANDROID_NDK_HOST}" )

# Setup platform and toolchain dirs
set( CINDER_ANDROID_NDK_PLATFORM_DIR "${CINDER_ANDROID_NDK_DIR}/platforms/android-${CINDER_ANDROID_NDK_PLATFORM}" )
set( CINDER_ANDROID_NDK_TOOLCHAIN_DIR "${CINDER_ANDROID_NDK_DIR}/toolchains" )
set( CINDER_ANDROID_NDK_COMPILER_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/llvm/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
if( ( "armeabi" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" ) OR ( "armeabi-v7a" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" ) )
set( CINDER_ANDROID_NDK_BINUTIL_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/arm-linux-androideabi-4.9/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
set( CINDER_ANDROID_NDK_BINUTIL_PREFIX "arm-linux-androideabi" )
elseif( "arm64-v8a" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_BINUTIL_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/aarch64-linux-android-4.9/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
set( CINDER_ANDROID_NDK_BINUTIL_PREFIX "aarch64-linux-android" )
elseif( "x86" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_BINUTIL_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/x86-4.9/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
set( CINDER_ANDROID_NDK_BINUTIL_PREFIX "i686-linux-android" )
elseif( "x86_64" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_BINUTIL_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/x86_64-4.9/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
set( CINDER_ANDROID_NDK_BINUTIL_PREFIX "x86_64-linux-android" )
elseif( "mips" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_BINUTIL_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/mipsel-linux-android-4.9/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
set( CINDER_ANDROID_NDK_BINUTIL_PREFIX "mipsel-linux-android" )
elseif( "mips64" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_BINUTIL_DIR "${CINDER_ANDROID_NDK_TOOLCHAIN_DIR}/mips64el-linux-android-4.9/prebuilt/${CINDER_ANDROID_NDK_HOST}" )
set( CINDER_ANDROID_NDK_BINUTIL_PREFIX "mips64el-linux-android" )
endif()

# Print tool chain dirs
message( STATUS "Using NDK compilers at ${CINDER_ANDROID_NDK_COMPILER_DIR}" )
message( STATUS "Using NDK binutils at ${CINDER_ANDROID_NDK_BINUTIL_DIR}" )

# Setup toolchain
set( CMAKE_C_COMPILER ${CINDER_ANDROID_NDK_COMPILER_DIR}/bin/clang${EXE_SUFFIX} CACHE FILEPATH "" FORCE )
set( CMAKE_CXX_COMPILER ${CINDER_ANDROID_NDK_COMPILER_DIR}/bin/clang++${EXE_SUFFIX} CACHE FILEPATH "" FORCE )
set( CMAKE_AR ${CINDER_ANDROID_NDK_BINUTIL_DIR}/bin/${CINDER_ANDROID_NDK_BINUTIL_PREFIX}-ar${EXE_SUFFIX} CACHE FILEPATH "" FORCE )
set( CMAKE_LINKER ${CINDER_ANDROID_NDK_BINUTIL_DIR}/bin/${CINDER_ANDROID_NDK_BINUTIL_PREFIX}-ld${EXE_SUFFIX} CACHE FILEPATH "" FORCE )
set( CMAKE_NM ${CINDER_ANDROID_NDK_BINUTIL_DIR}/bin/${CINDER_ANDROID_NDK_BINUTIL_PREFIX}-nm${EXE_SUFFIX} CACHE FILEPATH "" FORCE )
set( CMAKE_RANLIB ${CINDER_ANDROID_NDK_BINUTIL_DIR}/bin/${CINDER_ANDROID_NDK_BINUTIL_PREFIX}-ranlib${EXE_SUFFIX} CACHE FILEPATH "" FORCE )
set( CMAKE_STRIP ${CINDER_ANDROID_NDK_BINUTIL_DIR}/bin/${CINDER_ANDROID_NDK_BINUTIL_PREFIX}-strip${EXE_SUFFIX} CACHE FILEPATH "" FORCE )

# Suppress compiler checks for Android since building happens on a host system
set( CMAKE_C_COMPILER_WORKS 1 )
set( CMAKE_CXX_COMPILER_WORKS 1 )

# Configure system root
if( ( "armeabi" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" ) OR ( "armeabi-v7a" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" ) )
set( CINDER_ANDROID_NDK_SYSROOT "${CINDER_ANDROID_NDK_PLATFORM_DIR}/arch-arm" )
elseif( "arm64-v8a" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_SYSROOT "${CINDER_ANDROID_NDK_PLATFORM_DIR}/arch-arm64" )
elseif( "x86" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_SYSROOT "${CINDER_ANDROID_NDK_PLATFORM_DIR}/arch-x86" )
elseif( "x86_64" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_SYSROOT "${CINDER_ANDROID_NDK_PLATFORM_DIR}/arch-x86_64" )
elseif( "mips" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_SYSROOT "${CINDER_ANDROID_NDK_PLATFORM_DIR}/arch-mips" )
elseif( "mips64" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( CINDER_ANDROID_NDK_SYSROOT "${CINDER_ANDROID_NDK_PLATFORM_DIR}/arch-mips64" )
endif()
set( CMAKE_SYSROOT ${CINDER_ANDROID_NDK_SYSROOT} CACHE FILEPATH "" FORCE )

# Print system root dir
message( STATUS "Using NDK system root at ${CMAKE_SYSROOT}" )

# Suppress this on macOS host
if( APPLE )
set( CMAKE_OSX_SYSROOT "" CACHE FILEPATH "" FORCE )
endif()

# STL include directories
include_directories(
"${CINDER_ANDROID_NDK_DIR}/sources/cxx-stl/gnu-libstdc++/4.9/include"
"${CINDER_ANDROID_NDK_DIR}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${CINDER_ANDROID_NDK_ARCH_LOWER}/include"
)

# Architecture flags
if( "armeabi" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( ARCH_FLAGS "-target armv5te-none-linux-androideabi -march=armv5te -mtune=xscale -msoft-float -fpic -fstack-protector-strong" )
elseif( "armeabi-v7a" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
# Force hard float, Vulkan requires the use the hard float calling convention or the build will break.
set( ARCH_FLAGS "-target armv7-none-linux-androideabi -march=armv7-a -mfpu=neon -mhard-float -D_NDK_MATH_NO_SOFTFP=1 -fstack-protector -fpic" )
elseif( "arm64-v8a" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( ARCH_FLAGS "-target aarch64-none-linux-android -fstack-protector-strong -fpic" )
elseif( "x86" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( ARCH_FLAGS "-target i686-none-linux-android -fstack-protector-strong -fPIC" )
elseif( "x86_64" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( ARCH_FLAGS "-target x86_64-none-linux-android -fstack-protector-strong -fPIC" )
elseif( "mips" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( ARCH_FLAGS "-target mipsel-none-linux-android -fpic -fno-strict-aliasing -finline-functions -fmessage-length=0" )
elseif( "mips64" STREQUAL "${CINDER_ANDROID_NDK_ARCH_LOWER}" )
set( ARCH_FLAGS "-target mips64el-none-linux-android -fpic -fno-strict-aliasing -finline-functions -fmessage-length=0" )
endif()

# C_FLAGS
set( C_FLAGS "-DANDROID ${ARCH_FLAGS} -fvisibility=default" )
# CMAKE_FLAGS
set( CMAKE_C_FLAGS_DEBUG "-DCINDER_DEBUG ${C_FLAGS} -fPIC -g" CACHE STRING "" FORCE )
set( CMAKE_C_FLAGS_RELEASE "${C_FLAGS} -fPIC -Os -ffast-math ${C_FLAGS}" CACHE STRING "" FORCE )

# CXX_FLAGS
set( CXX_FLAGS "-gcc-toolchain ${CINDER_ANDROID_NDK_BINUTIL_DIR} ${ARCH_FLAGS} -fvisibility=default -stdlib=libstdc++ -D_GLIBCXX_HAS_GTHREADS -ffunction-sections -funwind-tables -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fomit-frame-pointer -DANDROID" )
# CMAKE_CXX_FLAGS
set( CMAKE_CXX_FLAGS_DEBUG "-DCINDER_DEBUG ${CXX_FLAGS} -fPIC -g -rdynamic -fexceptions -frtti" CACHE STRING "" FORCE )
set( CMAKE_CXX_FLAGS_RELEASE "${CXX_FLAGS} -fPIC -Os -rdynamic -fexceptions -frtti -ffast-math" CACHE STRING "" FORCE )

36 changes: 34 additions & 2 deletions proj/cmake/modules/cinderMakeApp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ function( ci_make_app )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE} )
# message( WARNING "CLion detected, set CMAKE_RUNTIME_OUTPUT_DIRECTORY to: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
else()
# Append the build type to the output dir
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} )
if( ( "${CMAKE_GENERATOR}" MATCHES "Visual Studio.+" ) OR ( "Xcode" STREQUAL "${CMAKE_GENERATOR}" ) )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
else()
# Append the build type to the output dir
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} )
endif()
message( STATUS "set CMAKE_RUNTIME_OUTPUT_DIRECTORY to: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
endif()
endif()
Expand Down Expand Up @@ -61,13 +65,41 @@ function( ci_make_app )
set_source_files_properties( ${ARG_RESOURCES} PROPERTIES HEADER_FILE_ONLY ON MACOSX_PACKAGE_LOCATION Resources )
elseif( CINDER_LINUX )
unset( ARG_RESOURCES ) # Don't allow resources to be added to the executable on linux
elseif( CINDER_MSW )
if( MSVC )
# Override the default /MD with /MT
foreach(
flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if( ${flag_var} MATCHES "/MD" )
string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
set( "${flag_var}" "${${flag_var}}" PARENT_SCOPE )
endif()
endforeach()
# Force synchronous PDB writes
add_compile_options( /FS )
# Force multiprocess compilation
add_compile_options( /MP )
# Add lib dirs
cmake_policy( PUSH )
cmake_policy( SET CMP0015 OLD )
link_directories( "${CINDER_PATH}/lib/${CINDER_TARGET_SUBFOLDER}" )
cmake_policy( POP )
endif()
endif()

add_executable( ${ARG_APP_NAME} MACOSX_BUNDLE WIN32 ${ARG_SOURCES} ${ICON_PATH} ${ARG_RESOURCES} )

target_include_directories( ${ARG_APP_NAME} PUBLIC ${ARG_INCLUDES} )
target_link_libraries( ${ARG_APP_NAME} cinder ${ARG_LIBRARIES} )

# Ignore Specific Default Libraries
if( MSVC )
set_target_properties( ${ARG_APP_NAME} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCPMT" )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set this on the cinder target, won't they get picked up as the app depends on that package? That way we can keep them grouped together.

endif()

# Blocks are first searched relative to the sample's CMakeLists.txt file, then within cinder's blocks folder
foreach( block ${ARG_BLOCKS} )
get_filename_component( blockModuleDir "${CMAKE_CURRENT_SOURCE_DIR}/${block}/proj/cmake" ABSOLUTE )
Expand Down
Loading