mirror of
https://github.com/CorsixTH/CorsixTH.git
synced 2025-07-23 04:13:01 +02:00
[RDY] Make CMake src files explicit (#1551)
* Name cpp source files explicitly * Use target sources instead of setting file lists for CMake
This commit is contained in:
committed by
Stephen E. Baker
parent
43f80b37bc
commit
326e2fa622
@@ -28,49 +28,8 @@ else()
|
||||
set(CORSIX_TH_INTERPRETER_PATH ${CMAKE_INSTALL_FULL_DATADIR}/corsix-th/CorsixTH.lua)
|
||||
endif()
|
||||
|
||||
# Modify the config.h based upon our selection of options
|
||||
configure_file(${CMAKE_SOURCE_DIR}/CorsixTH/Src/config.h.in ${CMAKE_BINARY_DIR}/CorsixTH/Src/config.h)
|
||||
include_directories(${CMAKE_BINARY_DIR}/CorsixTH/Src/)
|
||||
|
||||
# Generate source files list
|
||||
# Note: Done after generating config.h
|
||||
|
||||
# XXX: We should manually specify the files to include in each directory rather
|
||||
# than glob them all
|
||||
file(GLOB_RECURSE corsixth_source_files
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/SrcUnshared/*.cpp
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/SrcUnshared/*.c
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/SrcUnshared/*.h
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/SrcUnshared/*.hpp
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/*.cpp
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/*.c
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/*.hpp
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/*.h
|
||||
${CMAKE_SOURCE_DIR}/common/rnc.cpp
|
||||
${CMAKE_SOURCE_DIR}/common/rnc.h
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/shaders/*.psh
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Lua/api_version.lua
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/CorsixTH.rc
|
||||
${CMAKE_SOURCE_DIR}/LFS/*.c
|
||||
${CMAKE_SOURCE_DIR}/LPEG/*.c
|
||||
|
||||
${CMAKE_BINARY_DIR}/CorsixTH/Src/config.h
|
||||
)
|
||||
|
||||
set(corsixth_main_files
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/main.cpp
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/SrcUnshared/main.cpp
|
||||
${CMAKE_SOURCE_DIR}/CorsixTH/Src/main.h
|
||||
)
|
||||
|
||||
message(${corsixth_main_files})
|
||||
|
||||
# Remove main.cpp and main.h from the files we compile in to lib
|
||||
list(REMOVE_ITEM corsixth_source_files "${CMAKE_SOURCE_DIR}/CorsixTH/Src/main.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/CorsixTH/SrcUnshared/main.cpp")
|
||||
list(REMOVE_ITEM corsixth_source_files "${CMAKE_SOURCE_DIR}/CorsixTH/Src/main.h")
|
||||
|
||||
add_library(CorsixTH_lib STATIC ${corsixth_source_files})
|
||||
add_library(CorsixTH_lib STATIC "")
|
||||
|
||||
# Declaration of the executable
|
||||
if(APPLE)
|
||||
@@ -82,7 +41,7 @@ if(APPLE)
|
||||
)
|
||||
set(MACOSX_BUNDLE_ICON_FILE Icon.icns)
|
||||
|
||||
add_executable(CorsixTH MACOSX_BUNDLE ${corsixth_main_files} ${corsixth_icon_file})
|
||||
add_executable(CorsixTH MACOSX_BUNDLE ${corsixth_icon_file})
|
||||
|
||||
set_target_properties(CorsixTH PROPERTIES LINK_FLAGS_MINSIZEREL "-dead_strip")
|
||||
set_target_properties(CorsixTH PROPERTIES XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks")
|
||||
@@ -90,7 +49,7 @@ if(APPLE)
|
||||
target_link_libraries(CorsixTH SDL2main)
|
||||
include_directories(${CMAKE_BINARY_DIR}/CorsixTH/SDLMain/)
|
||||
else()
|
||||
add_executable(CorsixTH ${corsixth_main_files})
|
||||
add_executable(CorsixTH "")
|
||||
endif()
|
||||
|
||||
target_link_libraries(CorsixTH CorsixTH_lib)
|
||||
@@ -99,6 +58,23 @@ if(UNIX AND NOT APPLE)
|
||||
set_target_properties(CorsixTH PROPERTIES OUTPUT_NAME corsix-th)
|
||||
endif()
|
||||
|
||||
# Generate source files list
|
||||
# Note: Done after generating targets
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/Src)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/SrcUnshared)
|
||||
|
||||
# Manually add common files - as different targets could include the file
|
||||
# so we can't just do it in in the folder like above
|
||||
target_sources(CorsixTH_lib
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/common/rnc.cpp
|
||||
${CMAKE_SOURCE_DIR}/common/rnc.h
|
||||
)
|
||||
|
||||
# Ensure config.h is picked up by cmake - moving this into subdir cmake files will
|
||||
# prevent it applying to the CorsixTH project
|
||||
target_include_directories(CorsixTH_lib PUBLIC ${CMAKE_BINARY_DIR}/CorsixTH/Src/)
|
||||
|
||||
# Set language standard
|
||||
set_property(TARGET CorsixTH_lib PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET CorsixTH_lib PROPERTY CXX_EXTENSIONS OFF)
|
||||
|
@@ -20,11 +20,6 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
set (TESTING_FILES
|
||||
test_main.cpp
|
||||
example.cpp
|
||||
)
|
||||
|
||||
find_package(Catch2 CONFIG REQUIRED)
|
||||
|
||||
add_custom_target(AllTests)
|
||||
@@ -32,7 +27,7 @@ add_custom_target(AllTests)
|
||||
# Expose the header files from CorsixTH
|
||||
include_directories(${CMAKE_SOURCE_DIR}/CorsixTH/Src/)
|
||||
|
||||
add_executable(UnitTests ${TESTING_FILES} ${TEST_SOURCE_FILES})
|
||||
add_executable(UnitTests "")
|
||||
target_link_libraries(UnitTests Catch2::Catch2)
|
||||
target_link_libraries(UnitTests CorsixTH_lib)
|
||||
|
||||
@@ -46,3 +41,10 @@ set_target_properties(UnitTests PROPERTIES FOLDER UnitTests)
|
||||
|
||||
# Make sure we add it as a dependency to all tests (some day we can add LuaTest here)
|
||||
add_dependencies(AllTests UnitTests)
|
||||
|
||||
# List of all test files
|
||||
target_sources(UnitTests
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/example.cpp
|
||||
)
|
||||
|
69
CorsixTH/Src/CMakeLists.txt
Normal file
69
CorsixTH/Src/CMakeLists.txt
Normal file
@@ -0,0 +1,69 @@
|
||||
# Modify the config.h based upon our selection of options
|
||||
configure_file(${CMAKE_SOURCE_DIR}/CorsixTH/Src/config.h.in ${CMAKE_BINARY_DIR}/CorsixTH/Src/config.h)
|
||||
|
||||
target_sources(CorsixTH_lib
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/random.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bootstrap.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/iso_fs.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lua_rnc.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/persist_lua.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run_length_encoder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sdl_audio.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sdl_core.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sdl_wm.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_gfx.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_gfx_font.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_gfx_sdl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_anims.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_gfx.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_iso.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_lfs_ext.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_map.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_movie.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_sound.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_strings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_ui.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_map.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_map_overlays.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_movie.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_pathfind.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_sound.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xmi2mid.cpp
|
||||
)
|
||||
|
||||
# These are for IDEs such as XCode and MSVC to track headers within their
|
||||
# project files. They are not used by the build system.
|
||||
target_sources(CorsixTH_lib
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bootstrap.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cp437_table.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cp936_table.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/iso_fs.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lua_rnc.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lua_sdl.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/persist_lua.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run_length_encoder.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_gfx.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_gfx_font.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_gfx_sdl.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_lua_internal.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_map.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_map_overlays.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_movie.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_pathfind.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/th_sound.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xmi2mid.h
|
||||
|
||||
${CMAKE_BINARY_DIR}/CorsixTH/Src/config.h
|
||||
)
|
||||
|
||||
target_sources(CorsixTH
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.h
|
||||
)
|
4
CorsixTH/SrcUnshared/CMakeLists.txt
Normal file
4
CorsixTH/SrcUnshared/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
target_sources(CorsixTH
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
)
|
Reference in New Issue
Block a user