project root
+ build_osx
+ source
+ core CMakeLists.txt main.cpp This is the layout I have picked for the moment. The root give a place for the different builds, only source is under source control (git). core is currently empty, but will provide a location for core files, and there will be other folders to hold the display driver, sprites, audio.
Ok, so what did I build:
#include
int main(int /*argc*/, char * /*argv*/[])
{
printf("Defender\n");
return 0;
}
not a lot, but its a start, really just to make sure that the CMakeLists.txt file was correct, and that was:
cmake_minimum_required(VERSION 3.9)
project(defender)
###############################################################################
# increase warnings
###############################################################################
# Bump up warning levels appropriately for clang, gcc & msvc
# Also set debug/optimization flags depending on the build type. IDE users choose this when
# selecting the build mode in their IDE
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
endif()
###############################################################################
# Platform Details
###############################################################################
###############################################################################
# OSX 10.12 - current dev platform
###############################################################################
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# remove the warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-nested-anon-types")
find_library(SDL2 NAMES SDL2)
message(${SDL2})
find_library(OPENGL NAMES OpenGL)
message(${OPENGL})
set(PLATFORM_LIBS
${SDL2}
${OPENGL}
)
###############################################################################
# OSX 10.12 - current dev platform
###############################################################################
else()
message("Bad platform")
endif()
###############################################################################
# Handle includes
###############################################################################
include_directories(
${SDL2_INCLUDE_DIR}
)
###############################################################################
# Source files
###############################################################################
file(GLOB MAIN_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)
###############################################################################
# executable
###############################################################################
add_executable(defender
${MAIN_FILES}
)
target_link_libraries(defender ${PLATFORM_LIBS})
Its a lot, but it handles linking the SDL2 and openGL libraries into the final executable.so to build, move into build_osx folder and:
cmake -G "Unix Makefiles" ../sourceonce its finished:
makeand you should build the executable for your mac.
>defender
Defender
>
and its working. Not bad for half a days work :)
No comments:
Post a Comment