Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
(#6) Added CMakeLists.txt for all targets
Browse files Browse the repository at this point in the history
Added CMakeLists.txt build rules to `src/common`, `src/capi` and
`src/main`.

Added build rules for creating static library targets for FalloutNV,
Oblivion and Skyrim to folder `src/game/<game>` .

Added a fake intermediate library `src/game` that serves as a quick
referral for adding dependences to the three implemented games
indirectly. For this I required to add a dummy empty `game.cpp`
file as CMake doesn't accept libraries with no source code.

Also adjusted pre-existing CMakeLists.txt for the new folder
structure and static libraries usage.
  • Loading branch information
leandor committed Nov 3, 2016
1 parent 755a406 commit 6aba1e0
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 79 deletions.
93 changes: 15 additions & 78 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
cmake_minimum_required (VERSION 3.0)
project (CBash)

include(CMakeToolsHelpers OPTIONAL)

add_subdirectory (deps/pybind11)
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/deps/cotire/CMake")
include(cotire)

set_property(DIRECTORY . PROPERTY COTIRE_ADD_UNITY_BUILD FALSE)

option(CBash_BUILD_SHARED_LIBS "Build a shared library" ON)
option(CBash_USE_STATIC_RUNTIME "Build with static runtime libs (/MT)" ON)
option(CBash_NO_BOOST_ZLIB "Build with external Zlib" ON)
Expand All @@ -30,60 +34,6 @@ set(CBASH_TESTS ${CMAKE_SOURCE_DIR}/tests)
set(CBASH_SOURCE ${CMAKE_SOURCE_DIR}/src)
set(CBASH_INCLUDE ${CMAKE_SOURCE_DIR}/include/cbash)

file (GLOB_RECURSE CBASH_GEN_HDRS "${CBASH_SOURCE}/*.h" )
file (GLOB_RECURSE CBASH_PUB_HDRS "${CBASH_INCLUDE}/*.h" )

file (GLOB_RECURSE CBASH_FONV "${CBASH_SOURCE}/FalloutNewVegas/*.cpp")
file (GLOB_RECURSE CBASH_OBLIVION "${CBASH_SOURCE}/Oblivion/*.cpp")
file (GLOB_RECURSE CBASH_SKYRIM "${CBASH_SOURCE}/Skyrim/*.cpp")

set (CBASH_SRC "${CBASH_SOURCE}/CBash.cpp"
"${CBASH_SOURCE}/Collection.cpp"
"${CBASH_SOURCE}/Common.cpp"
"${CBASH_SOURCE}/GenericChunks.cpp"
"${CBASH_SOURCE}/GenericRecord.cpp"
"${CBASH_SOURCE}/ModFile.cpp"
"${CBASH_SOURCE}/TES4Record.cpp"
"${CBASH_SOURCE}/TES4RecordAPI.cpp"
"${CBASH_SOURCE}/Visitors.cpp"
"${CBASH_SOURCE}/CBash.rc"
${CBASH_FONV}
${CBASH_OBLIVION}
${CBASH_SKYRIM}
)

file(GLOB_RECURSE TMP_FILES_HDRS
"${CBASH_SOURCE}/*.h"
)

foreach(f ${TMP_FILES_HDRS})
# Get the path of the file relative to ${DIRECTORY},
# then alter it (not compulsory)
file(RELATIVE_PATH SRCGR "${CBASH_SOURCE}/" ${f})
set(SRCGR "Headers/${SRCGR}")

# Extract the folder, ie remove the filename part
string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})

# Source_group expects \\ (double antislash), not / (slash)
string(REPLACE / \\ SRCGR ${SRCGR})
source_group("${SRCGR}" FILES ${f})
endforeach()

file(GLOB_RECURSE TMP_FILES
"${CBASH_SOURCE}/*.cpp"
)
foreach(f ${TMP_FILES})
# Get the path of the file relative to ${DIRECTORY},
# then alter it (not compulsory)
file(RELATIVE_PATH SRCGR "${CBASH_SOURCE}/" ${f})
set(SRCGR "Source Files/${SRCGR}")
# Extract the folder, ie remove the filename part
string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})
# Source_group expects \\ (double antislash), not / (slash)
string(REPLACE / \\ SRCGR ${SRCGR})
source_group("${SRCGR}" FILES ${f})
endforeach()

IF (CBash_NO_BOOST_ZLIB)
add_definitions(-DCBash_NO_BOOST_ZLIB)
Expand All @@ -97,9 +47,13 @@ ELSE ()
ENDIF ()

# Include source and library directories.
include_directories (${CBASH_INCLUDE}
${Boost_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR})
include_directories (
${CBASH_INCLUDE}
${Boost_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
${CBASH_SOURCE}
${CBASH_SOURCE}/game
)


##############################
Expand Down Expand Up @@ -139,26 +93,9 @@ IF (MSVC)
ENDIF ()


##############################
# Actual Building
##############################

# Build CBash.
add_library (CBash ${CBASH_SRC} ${CBASH_PUB_HDRS} ${CBASH_GEN_HDRS})
target_link_libraries (CBash ${Boost_LIBRARIES} ${CBASH_LIBS})

# Always write the output file directly into the 'tests' directory (even on MSVC)
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(CBash PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CBASH_RELEASE})
set_target_properties(CBash PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CBASH_RELEASE})
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
set_target_properties(CBash PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} ${CBASH_RELEASE})
set_target_properties(CBash PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${config} ${CBASH_RELEASE})
endforeach()
endif()

add_subdirectory(src/common)
add_subdirectory(src/game)
add_subdirectory(src/main)
add_subdirectory(src/capi)
add_subdirectory (pyd)

cotire(CBash)

2 changes: 1 addition & 1 deletion pyd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pybind11_enable_warnings(cint)


#set_property(TARGET CBash PROPERTY IMPORTED_LOCATION "/home/sources/lib/libfoo1.so")
target_link_libraries (cint PRIVATE CBash)
target_link_libraries (cint PRIVATE libmain libgame libcommon)

# Always write the output file directly into the 'tests' directory (even on MSVC)
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
Expand Down
49 changes: 49 additions & 0 deletions src/capi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Settings passed on the command line:
#
# CBash_BUILD_SHARED_LIBS
# CBash_USE_STATIC_RUNTIME
# CBash_NO_BOOST_ZLIB

##############################
# General Settings
##############################


file (GLOB_RECURSE CBASH_HEADERS "${CBASH_INCLUDE}/*.h" )

list(APPEND CBASH_HEADERS
"Version.h"
"resource.h"
)

set (CBASH_SOURCES
"CBash.cpp"
"CBash.rc"
)


# Include source and library directories.
include_directories (${CBASH_INCLUDE} ${CBASH_SOURCE} ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})

##############################
# Actual Building
##############################

# Build CBash.
add_library (CBash ${CBASH_SOURCES} ${CBASH_HEADERS} ${CBASH_GEN_HDRS})
target_link_libraries (CBash ${Boost_LIBRARIES} ${CBASH_LIBS} libcommon libgame libmain)


# Always write the output file directly into the 'tests' directory (even on MSVC)
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(CBash PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CBASH_RELEASE})
set_target_properties(CBash PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CBASH_RELEASE})
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
set_target_properties(CBash PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} ${CBASH_RELEASE})
set_target_properties(CBash PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${config} ${CBASH_RELEASE})
endforeach()
endif()

cotire(CBash)

31 changes: 31 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Include source and library directories.
# include_directories (${CBASH_INCLUDE}
# ${Boost_INCLUDE_DIRS}
# ${ZLIB_INCLUDE_DIR})

set (COMMON_HEADERS
"Allocator.h"
"Common.h"
"GenericChunks.h"
"GenericRecord.h"
"MacroDefinitions.h"
"ModFile.h"
"TES4Record.h"
)

set (COMMON_SOURCES

"Common.cpp"
"GenericChunks.cpp"
"GenericRecord.cpp"
"ModFile.cpp"
"TES4Record.cpp"
"TES4RecordAPI.cpp"
)

include_directories (${CBASH_INCLUDE} ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})

add_library(libcommon STATIC ${COMMON_HEADERS} ${COMMON_SOURCES})

cotire(libcommon)
8 changes: 8 additions & 0 deletions src/game/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

add_subdirectory(Oblivion)
add_subdirectory(Skyrim)
add_subdirectory(FalloutNewVegas)


add_library(libgame STATIC game.cpp)
target_link_libraries(libgame libgame_oblivion libgame_skyrim libgame_falloutnv)
31 changes: 31 additions & 0 deletions src/game/FalloutNewVegas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Include source and library directories.
# include_directories (${CBASH_INCLUDE}
# ${Boost_INCLUDE_DIRS}
# ${ZLIB_INCLUDE_DIR})


file (GLOB_RECURSE FALLOUTNV_RECORD_HEADERS "Records/*.h" )
file (GLOB_RECURSE FALLOUTNV_RECORD_SOURCES "Records/*.cpp" )
file (GLOB_RECURSE FALLOUTNV_RECORD_API "Records/API/*.cpp" )

set (FALLOUTNV_HEADERS

"GRUPRecord.h"
"FNVFile.h"
"FNVRecord.h"
${FALLOUTNV_RECORD_HEADERS}
)

set (FALLOUTNV_SOURCES

"FNVFile.cpp"
"FNVRecord.cpp"
${FALLOUTNV_RECORD_SOURCES}
${FALLOUTNV_RECORD_API}
)

add_library(libgame_falloutnv STATIC ${FALLOUTNV_HEADERS} ${FALLOUTNV_SOURCES})
target_link_libraries (libgame_falloutnv ${Boost_LIBRARIES} ${CBASH_LIBS} libcommon)

cotire(libgame_falloutnv)
30 changes: 30 additions & 0 deletions src/game/Oblivion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# Include source and library directories.
# include_directories (${CBASH_INCLUDE}
# ${Boost_INCLUDE_DIRS}
# ${ZLIB_INCLUDE_DIR})


file (GLOB_RECURSE OBLIVION_RECORD_HEADERS "Records/*.h" )
file (GLOB_RECURSE OBLIVION_RECORD_SOURCES "Records/*.cpp" )
file (GLOB_RECURSE OBLIVION_RECORD_API "Records/API/*.cpp" )

set (OBLIVION_HEADERS

"GRUPRecord.h"
"TES4File.h"
${OBLIVION_RECORD_HEADERS}
)

set (OBLIVION_SOURCES

"TES4File.cpp"
${OBLIVION_RECORD_SOURCES}
${OBLIVION_RECORD_API}
)


add_library(libgame_oblivion STATIC ${OBLIVION_HEADERS} ${OBLIVION_SOURCES})
target_link_libraries (libgame_oblivion ${Boost_LIBRARIES} ${CBASH_LIBS} libcommon)

cotire(libgame_oblivion)
44 changes: 44 additions & 0 deletions src/game/Skyrim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Include source and library directories.
# include_directories (${CBASH_INCLUDE}
# ${Boost_INCLUDE_DIRS}
# ${ZLIB_INCLUDE_DIR})


file (GLOB SKYRIM_RECORD_HEADERS "Records/*.h" )
file (GLOB SKYRIM_RECORD_SOURCES "Records/*.cpp" )

file (GLOB_RECURSE SKYRIM_VMAD_HEADERS "VMAD/*.h" )
file (GLOB_RECURSE SKYRIM_VMAD_SOURCES "VMAD/*.cpp" )

file (GLOB SKYRIM_RECORD_API "Records/API/*.cpp" )

set (SKYRIM_HEADERS

"GRUPRecord.h"
"SkyrimCommon.h"
"SkyrimChunks.h"
"TES5ModFile.h"
"TES5Record.h"
"TES5File.h"

${SKYRIM_VMAD_HEADERS}
${SKYRIM_RECORD_HEADERS}
)

set (SKYRIM_SOURCES

"SkyrimChunks.cpp"
"SkyrimCommon.cpp"
"TES5File.cpp"
"TES5Record.cpp"

${SKYRIM_VMAD_SOURCES}
${SKYRIM_RECORD_SOURCES}
${SKYRIM_RECORD_API}
)

add_library(libgame_skyrim STATIC ${SKYRIM_HEADERS} ${SKYRIM_SOURCES})
target_link_libraries (libgame_skyrim ${Boost_LIBRARIES} ${CBASH_LIBS} libcommon)

cotire(libgame_skyrim)
Empty file added src/game/game.cpp
Empty file.
37 changes: 37 additions & 0 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Settings passed on the command line:
#
# CBash_BUILD_SHARED_LIBS
# CBash_USE_STATIC_RUNTIME
# CBash_NO_BOOST_ZLIB

##############################
# General Settings
##############################



set(CBASH_HEADERS
"Collection.h"
"Visitors.h"
)

set (CBASH_SOURCES
"Collection.cpp"
"Visitors.cpp"
)

##############################
# Actual Building
##############################

include_directories (
${CBASH_SOURCE}/game
)

# Build CBash.
add_library (libmain STATIC ${CBASH_HEADERS} ${CBASH_SOURCES})
target_link_libraries (libmain libcommon libgame)


cotire(libmain)

0 comments on commit 6aba1e0

Please sign in to comment.