Skip to content

Commit

Permalink
Clean up and organize CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
iondune committed Nov 24, 2017
1 parent 5c1dc04 commit 1b5f719
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 110 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ script:
- mkdir Build && cd Build
- cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
- make
- ./TestConfig/TestConfig
- ./TestUnits/TestUnits
- ./bin/TestConfig
- ./bin/TestUnits
47 changes: 31 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,35 @@ include(GNUInstallDirs)
# Output Directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(ION_ENGINE_DIRECTORY "${PROJECT_SOURCE_DIR}")

# Build Properties
function(BuildProperties TargetName)

# Compiler Settings
target_compile_options(${TargetName} PUBLIC "-std=c++1y")

target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Include")

# Dependencies
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies/stb")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies/tinyformat")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies/glm")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies/imgui")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies/Catch/include")
target_include_directories(${TargetName} PUBLIC "${ION_ENGINE_DIRECTORY}/Dependencies/glad/include")

# Definitions
target_compile_definitions(${TargetName} PRIVATE -DION_PROJECT_BASE_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/")

endfunction(BuildProperties)

# Executable Properties
function(ExecutableProperties TargetName)

# Compiler Settings
include_directories("${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/Include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")

# Dependencies
include_directories("${PROJECT_SOURCE_DIR}/Dependencies")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/stb")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/tinyformat")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/glm")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/imgui")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/Catch/include")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/glad/include")

function(ExecutableDependencies TargetName)
# OpenGL
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
Expand All @@ -38,7 +51,9 @@ function(ExecutableDependencies TargetName)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(${TargetName} ${GLFW_LIBRARIES})
target_link_libraries(${TargetName} ${GLFW_STATIC_LIBRARIES})
endfunction(ExecutableDependencies)

endfunction(ExecutableProperties)


#########
# Build #
Expand Down
14 changes: 8 additions & 6 deletions Demo01-WindowManager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_executable(Demo01-WindowManager DemoWindowManager.cpp)
set(TARGET_NAME Demo01-WindowManager)
add_executable(${TARGET_NAME} DemoWindowManager.cpp)
BuildProperties(${TARGET_NAME})
ExecutableProperties(${TARGET_NAME})

target_link_libraries(Demo01-WindowManager ionGraphicsGL)
target_link_libraries(Demo01-WindowManager ionGraphics)
target_link_libraries(Demo01-WindowManager ionWindow)
target_link_libraries(Demo01-WindowManager ionCore)
ExecutableDependencies(Demo01-WindowManager)
target_link_libraries(${TARGET_NAME} ionGraphicsGL)
target_link_libraries(${TARGET_NAME} ionGraphics)
target_link_libraries(${TARGET_NAME} ionWindow)
target_link_libraries(${TARGET_NAME} ionCore)
18 changes: 8 additions & 10 deletions Demo02-GL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
add_executable(Demo02-GL DemoGL.cpp)
set(TARGET_NAME Demo02-GL)
add_executable(${TARGET_NAME} DemoGL.cpp)
BuildProperties(${TARGET_NAME})
ExecutableProperties(${TARGET_NAME})

target_link_libraries(Demo02-GL ionGraphicsGL)
target_link_libraries(Demo02-GL ionGraphics)
target_link_libraries(Demo02-GL ionWindow)
target_link_libraries(Demo02-GL ionCore)
ExecutableDependencies(Demo02-GL)
add_custom_command(
TARGET Demo02-GL POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/Image.jpg $<TARGET_FILE_DIR:Demo02-GL>)
target_link_libraries(${TARGET_NAME} ionGraphicsGL)
target_link_libraries(${TARGET_NAME} ionGraphics)
target_link_libraries(${TARGET_NAME} ionWindow)
target_link_libraries(${TARGET_NAME} ionCore)
16 changes: 9 additions & 7 deletions Demo03-GUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
add_executable(Demo03-GUI DemoGUI.cpp)
set(TARGET_NAME Demo03-GUI)
add_executable(${TARGET_NAME} DemoGUI.cpp)
BuildProperties(${TARGET_NAME})
ExecutableProperties(${TARGET_NAME})

target_link_libraries(Demo03-GUI ionGUI)
target_link_libraries(Demo03-GUI ionGraphicsGL)
target_link_libraries(Demo03-GUI ionGraphics)
target_link_libraries(Demo03-GUI ionWindow)
target_link_libraries(Demo03-GUI ionCore)
ExecutableDependencies(Demo03-GUI)
target_link_libraries(${TARGET_NAME} ionGUI)
target_link_libraries(${TARGET_NAME} ionGraphicsGL)
target_link_libraries(${TARGET_NAME} ionGraphics)
target_link_libraries(${TARGET_NAME} ionWindow)
target_link_libraries(${TARGET_NAME} ionCore)
32 changes: 9 additions & 23 deletions Demo04-Scene/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
add_executable(Demo04-Scene DemoScene.cpp)
set(TARGET_NAME Demo04-Scene)
add_executable(${TARGET_NAME} DemoScene.cpp)
BuildProperties(${TARGET_NAME})
ExecutableProperties(${TARGET_NAME})

target_link_libraries(Demo04-Scene ionScene)
target_link_libraries(Demo04-Scene ionGraphicsGL)
target_link_libraries(Demo04-Scene ionGraphics)
target_link_libraries(Demo04-Scene ionWindow)
target_link_libraries(Demo04-Scene ionCore)
ExecutableDependencies(Demo04-Scene)
add_custom_command(
TARGET Demo04-Scene POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/Diffuse.vert $<TARGET_FILE_DIR:Demo04-Scene>)
add_custom_command(
TARGET Demo04-Scene POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/Diffuse.frag $<TARGET_FILE_DIR:Demo04-Scene>)
add_custom_command(
TARGET Demo04-Scene POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/Axis.vert $<TARGET_FILE_DIR:Demo04-Scene>)
add_custom_command(
TARGET Demo04-Scene POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/Axis.frag $<TARGET_FILE_DIR:Demo04-Scene>)
target_link_libraries(${TARGET_NAME} ionScene)
target_link_libraries(${TARGET_NAME} ionGraphicsGL)
target_link_libraries(${TARGET_NAME} ionGraphics)
target_link_libraries(${TARGET_NAME} ionWindow)
target_link_libraries(${TARGET_NAME} ionCore)
22 changes: 10 additions & 12 deletions Demo05-Application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
add_executable(Demo05-Application DemoApplication.cpp)
set(TARGET_NAME Demo05-Application)
add_executable(${TARGET_NAME} DemoApplication.cpp)
BuildProperties(${TARGET_NAME})
ExecutableProperties(${TARGET_NAME})

target_link_libraries(Demo05-Application ionApplication)
target_link_libraries(Demo05-Application ionScene)
target_link_libraries(Demo05-Application ionGraphicsGL)
target_link_libraries(Demo05-Application ionGraphics)
target_link_libraries(Demo05-Application ionWindow)
target_link_libraries(Demo05-Application ionCore)
ExecutableDependencies(Demo05-Application)
add_custom_command(
TARGET Demo05-Application POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/Assets $<TARGET_FILE_DIR:Demo05-Application>/Assets)
target_link_libraries(${TARGET_NAME} ionApplication)
target_link_libraries(${TARGET_NAME} ionScene)
target_link_libraries(${TARGET_NAME} ionGraphicsGL)
target_link_libraries(${TARGET_NAME} ionGraphics)
target_link_libraries(${TARGET_NAME} ionWindow)
target_link_libraries(${TARGET_NAME} ionCore)
4 changes: 3 additions & 1 deletion TestConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
add_executable(TestConfig ConfigTest.cpp)
set(TARGET_NAME TestConfig)
add_executable(${TARGET_NAME} ConfigTest.cpp)
BuildProperties(${TARGET_NAME})
9 changes: 6 additions & 3 deletions TestDeployment/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
add_executable(TestDeployment DeploymentTest.cpp glad.cpp)
target_link_libraries(TestDeployment ionCore)
ExecutableDependencies(TestDeployment)
set(TARGET_NAME TestDeployment)
add_executable(${TARGET_NAME} DeploymentTest.cpp glad.cpp)
BuildProperties(TestDeployment)
ExecutableProperties(TestDeployment)

target_link_libraries(${TARGET_NAME} ionCore)
10 changes: 6 additions & 4 deletions TestUnits/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set(TARGET_NAME TestUnits)
file(GLOB SOURCES *.cpp)
add_executable(TestUnits ${SOURCES})
add_executable(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})

# Libraries
target_link_libraries(TestUnits ionScene)
target_link_libraries(TestUnits ionGraphics)
target_link_libraries(TestUnits ionCore)
target_link_libraries(${TARGET_NAME} ionScene)
target_link_libraries(${TARGET_NAME} ionGraphics)
target_link_libraries(${TARGET_NAME} ionCore)
4 changes: 3 additions & 1 deletion ionAnimation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(TARGET_NAME ionAnimation)
file(GLOB SOURCES *.cpp)
add_library(ionAnimation ${SOURCES})
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
5 changes: 3 additions & 2 deletions ionApplication/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(TARGET_NAME ionApplication)
file(GLOB SOURCES *.cpp)
add_library(ionApplication ${SOURCES})
target_compile_definitions(ionApplication PRIVATE -DION_PROJECT_BASE_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/")
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
18 changes: 3 additions & 15 deletions ionCore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@

# CMake
project(libionCore VERSION ${ION_ENGINE_VERSION} LANGUAGES CXX)

# Sources
set(TARGET_NAME ionCore)
file(GLOB SOURCES *.cpp)
add_library(ionCore ${SOURCES})

# Install
install(TARGETS ionCore EXPORT ionCoreConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

install(EXPORT ionCoreConfig DESTINATION share/ionCore/cmake)
export(TARGETS ionCore FILE ionCoreConfig.cmake)
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
5 changes: 3 additions & 2 deletions ionGUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(TARGET_NAME ionGUI)
file(GLOB SOURCES *.cpp)
add_library(ionGUI ${SOURCES})
target_compile_definitions(ionGUI PRIVATE -DION_PROJECT_BASE_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/")
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
6 changes: 4 additions & 2 deletions ionGraphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
file(GLOB SOURCES *.cpp)
add_library(ionGraphics ${SOURCES})
set(TARGET_NAME ionGraphics)
file(GLOB SOURCES *.cpp)
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
4 changes: 3 additions & 1 deletion ionGraphicsGL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(TARGET_NAME ionGraphicsGL)
file(GLOB SOURCES *.cpp)
add_library(ionGraphicsGL ${SOURCES})
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
4 changes: 3 additions & 1 deletion ionScene/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(TARGET_NAME ionScene)
file(GLOB SOURCES *.cpp)
add_library(ionScene ${SOURCES})
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
4 changes: 3 additions & 1 deletion ionScience/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(TARGET_NAME ionScience)
file(GLOB SOURCES *.cpp)
add_library(ionScience ${SOURCES})
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})
4 changes: 3 additions & 1 deletion ionWindow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(TARGET_NAME ionWindow)
file(GLOB SOURCES *.cpp)
add_library(ionWindow ${SOURCES})
add_library(${TARGET_NAME} ${SOURCES})
BuildProperties(${TARGET_NAME})

0 comments on commit 1b5f719

Please sign in to comment.