Small SDL CMake Example type thing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required (VERSION 2.8) | |
# Boolean Options | |
option(BUILD_EXAMPLES "Builds the examples" ON) | |
option(BUILD_STATIC "Builds a static lib" OFF) | |
option(BUILD_TESTS "Builds the tests" ON) | |
# Configuration Options | |
if (MSVC) | |
option(USE_MSVC_CL "Indicates building from the command line with MSBuild" OFF) | |
endif () | |
option(USE_CLANG "Use clang as the compiler" OFF) | |
# Set the build types to be visible, helps newbies :) | |
set(CMAKE_CONFIGURATION_TYPES | |
"Debug;ReleaseRelWithDebInfo;MinSizeRel" | |
CACHE STRING "" FORCE) | |
project (SDL) | |
if (${USE_CLANG}) | |
find_program(CLANG clang ENV PATH) | |
if (${CLANG_NOTFOUND}) | |
message(FATAL_ERROR "Clang could not be found on the system path") | |
endif () | |
set(CMAKE_C_COMPILER ${CLANG} CACHE STRING "" FORCE) | |
endif () | |
if (${USE_MSVC_CL}) | |
set(SDL_DEFINITIONS "/WL") | |
else () | |
set(SDL_DEFINITIONS ) | |
endif () | |
# Set the Glob Expression for getting "all dem files" into an array later | |
# It is better than writing every. single. one. out. :| | |
# Too busy to write this all out (i.e., I'm too lazy :v). | |
# Also, I'm unfamiliar with the current build system so oh well :v | |
if (WIN32) | |
set(SDL_GLOB_EXPRESSION ${CMAKE_CURRENT_SOURCE_DIR}/src/*/windows/*.c) | |
#else () | |
# set(SDL_GLOB_EXPRESSION ) | |
endif () | |
# Obviously this is a naive expression :) | |
set(SDL_GLOB_EXPRESSION ${SDL_GLOB_EXPRESSION} | |
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c) | |
# Find dependencies here, etc. | |
# find_library() | |
# set (SDL_LIBRARIES ) | |
# Grabs all files that meet the previous match | |
file(GLOB_RECURSE SDL_SOURCE ${SDL_GLOB_EXPRESSION}) | |
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | |
# This is where you would add any #define stuff :) | |
add_definitions(${SDL_DEFINITIONS}) | |
target_link_libraries(${PROJECT_NAME} ${SDL_LIBRARIES}) | |
if (${BUILD_EXAMPLES}) | |
# Do what we did above, just use add_executable now. We can also use the | |
# SDL project name without having to know its output directory. CMake | |
# Takes care of that for us. | |
add_executable(${BLAH} ${BLAH_SOURCE}) | |
target_link_libraries(${BLAH} ${PROJECT_NAME}) | |
endif () | |
if (${BUILD_TESTS}) | |
enable_testing() | |
foreach (TEST_NAME ${SDL_TESTS}) | |
add_executable(${TEST_NAME} ${TEST_SOURCE}) | |
target_link_libraries(${TEST_NAME} ${PROJECT_NAME}) | |
add_test(${TEST} ${EXECUTABLE_OUTPUT_PATH}/${TEST_NAME}) | |
endforeach () | |
endif () | |
# Install Information | |
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include | |
DESTINATION include/SDL | |
FILES_MATCHING PATTERN "*.h"( | |
# Libraries | |
install(TARGETS ${PROJECT_NAME} | |
LIBRARY DESTINATION lib | |
ARCHIVE DESTINATION lib) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment