Skip to content

Commit

Permalink
better cmake usage (#41)
Browse files Browse the repository at this point in the history
* better cmake usage

* update CMakeLists.txt

* update lgtm.yml

* update lgtm.yml

* update lgtm.yml

* update lgtm.yml

* update travis and cmakelists.txt
  • Loading branch information
Milerius committed Apr 9, 2019
1 parent 8831cc4 commit 74bb3a7
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 60 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
bin
*.d
*.vscode
cmake-build-debug
cmake-build-release
cmake-build-*
deploy_linux/
tools/
build

# Compiled Object files
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ script:
if [[ "${CODE_COVERAGE}" = "ON" ]]; then
${DEPS_DIR}/cmake/bin/cmake -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_C_COMPILER=gcc-8 -DNEPHTYS_COVERAGE=ON ../
else
${DEPS_DIR}/cmake/bin/cmake -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_C_COMPILER=gcc-8 ../
${DEPS_DIR}/cmake/bin/cmake -DCMAKE_CXX_COMPILER=g++-8 -DAUTO_BUILD_APPIMAGE=ON -DCMAKE_C_COMPILER=gcc-8 ../
fi
make VERBOSE=1 -j2
fi
Expand Down
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
project(nepthys)

##! CMake extras
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(nephtys)
init_nephtys()

##! Conan
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
##! Project

if (UNIX AND NOT APPLE)
set(LINUX TRUE)
##! CMake Options
option(USE_ASAN "Use address sanitizer" OFF)
if (LINUX)
option(AUTO_BUILD_APPIMAGE "Enable it to autobuild appimage" OFF)
endif ()

##! Sub-Projects
Expand Down
105 changes: 54 additions & 51 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,73 +1,76 @@
add_executable(nephtys_client)
################################### nephtys_client_shared_deps
add_library(nephtys_client_shared_deps INTERFACE)

set(nephtys_client_sources
target_link_libraries(nephtys_client_shared_deps INTERFACE
CONAN_PKG::sfml CONAN_PKG::entt CONAN_PKG::jsonformoderncpp CONAN_PKG::doom_strong_types
$<$<CXX_COMPILER_ID:GNU>:-static-libstdc++>
$<$<CXX_COMPILER_ID:GNU>:stdc++fs>
$<$<CXX_COMPILER_ID:Clang>:>)
target_sources(nephtys_client_shared_deps INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/src/config/config.cpp
$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/src/resources/details/linux/app_image_real_path.cpp>
)
$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/src/resources/details/linux/app_image_real_path.cpp>)

target_sources(nephtys_client PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ${nephtys_client_sources})
target_compile_options(nephtys_client PUBLIC
target_compile_options(nephtys_client_shared_deps INTERFACE
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:Clang>>:-O2 -march=native -Wall -Wextra -Wfatal-errors>
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:GNU>>:-O2 -march=native -Wall -Wextra -Wfatal-errors>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU>>:-O0 -g -Wall -Wextra -Wfatal-errors>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:Clang>>:-O0 -g -Wall -Wextra -Wfatal-errors>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Zi /FS /DEBUG /Od /MP /MDd /Oy- /W4 /permissive- /std:c++latest>
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2 -DNDEBUG /MP /W4 /permissive- /std:c++latest>)
target_link_libraries(nephtys_client PRIVATE CONAN_PKG::sfml CONAN_PKG::entt CONAN_PKG::jsonformoderncpp CONAN_PKG::doom_strong_types
$<$<CXX_COMPILER_ID:GNU>:-static>
$<$<CXX_COMPILER_ID:GNU>:stdc++fs>
$<$<CXX_COMPILER_ID:Clang>:>)
target_include_directories(nephtys_client PRIVATE

target_include_directories(nephtys_client_shared_deps INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/common/include)

##Properties
get_target_property(nephtys_client_libraries nephtys_client LINK_LIBRARIES)
get_target_property(nephtys_client_output_directory nephtys_client RUNTIME_OUTPUT_DIRECTORY)
get_target_property(nephtys_client_include_directories nephtys_client INCLUDE_DIRECTORIES)
if (USE_ASAN)
message("-- ASAN Enabled, Configuring...")
target_compile_options(nephtys_client_shared_deps INTERFACE
$<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fsanitize=address -fno-omit-frame-pointer>)
target_link_options(nephtys_client_shared_deps INTERFACE
$<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fsanitize=address -fno-omit-frame-pointer>)
endif ()

################################### nephtys_client
add_executable(nephtys_client)
target_sources(nephtys_client PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
target_link_libraries(nephtys_client PRIVATE nephtys_client_shared_deps)
if (LINUX)
get_target_property(nephtys_client_runtime_directory nephtys_client RUNTIME_OUTPUT_DIRECTORY)
set_target_properties(nephtys_client PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${nephtys_client_runtime_directory}/AppDir/usr/bin
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${nephtys_client_runtime_directory}/AppDir/usr/bin
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${nephtys_client_runtime_directory}/AppDir/usr/bin)
message("runtime_directory nephtys_client: ${nephtys_client_runtime_directory}")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/assets/config/game_config.json
${nephtys_client_runtime_directory}/AppDir/usr/share/assets/config/game_config.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/linux/org.nephtys.client.desktop
${nephtys_client_runtime_directory}/AppDir/usr/share/applications/org.nephtys.client.desktop COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/linux/org.nephtys.client.appdata.xml
${nephtys_client_runtime_directory}/AppDir/usr/share/metainfo/org.nephtys.client.appdata.xml COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/linux/nephtys_icon.png
${nephtys_client_runtime_directory}/AppDir/usr/share/icons/hicolor/128x128/nephtys_icon.png COPYONLY)
if (AUTO_BUILD_APPIMAGE)
add_custom_command(TARGET nephtys_client
POST_BUILD COMMAND
bash -c
"${PROJECT_SOURCE_DIR}/tools/linux/linuxdeploy-x86_64.AppImage --appdir ${nephtys_client_runtime_directory}/AppDir --output appimage"
$<TARGET_FILE:nephtys_client>
WORKING_DIRECTORY ${nephtys_client_runtime_directory})
endif ()
endif ()
########################################################################

##! Test
add_executable(nephtys-client-test)
target_sources(nephtys-client-test PUBLIC
${nephtys_client_sources}
${CMAKE_CURRENT_SOURCE_DIR}/test/test_client.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/config/config.test.cpp
$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/src/resources/details/linux/app_image_real_path.test.cpp>)
target_link_libraries(nephtys-client-test PRIVATE CONAN_PKG::doctest ${nephtys_client_libraries})
target_include_directories(nephtys-client-test PRIVATE ${nephtys_client_include_directories})
$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/src/resources/details/linux/app_image_real_path.test.cpp>
)
target_link_libraries(nephtys-client-test PRIVATE CONAN_PKG::doctest PRIVATE nephtys_client_shared_deps)

if (NEPHTYS_COVERAGE)
target_compile_options(nephtys-client-test PUBLIC --coverage -fprofile-arcs -ftest-coverage)
target_link_options(nephtys-client-test PUBLIC --coverage -fprofile-arcs -ftest-coverage)
endif ()

##! Config file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/assets/config/game_config.json
${nephtys_client_output_directory}/share/assets/config/game_config.json COPYONLY)

if (LINUX)
##! Install
install(TARGETS
nephtys_client
DESTINATION bin
)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/org.nephtys.client.desktop
DESTINATION share/applications/
)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/org.nephtys.client.appdata.xml
DESTINATION share/metainfo/
)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/config/game_config.json
DESTINATION share/assets/config/
)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/nephtys_icon.png
DESTINATION share/icons/hicolor/128x128/apps
)
endif ()
File renamed without changes
File renamed without changes.
46 changes: 46 additions & 0 deletions cmake/nephtys.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
macro(download_app_image)
if (LINUX)
## We need appimage
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/tools/linux/linuxdeploy-x86_64.AppImage)
file(DOWNLOAD
https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
${PROJECT_SOURCE_DIR}/tools/linuxdeploy-x86_64.AppImage
SHOW_PROGRESS
)
endif ()
if (EXISTS ${PROJECT_SOURCE_DIR}/tools/linuxdeploy-x86_64.AppImage)
file(COPY
${PROJECT_SOURCE_DIR}/tools/linuxdeploy-x86_64.AppImage DESTINATION
${PROJECT_SOURCE_DIR}/tools/linux/
FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
endif ()
if (EXISTS ${PROJECT_SOURCE_DIR}/tools/linuxdeploy-x86_64.AppImage)
file(REMOVE ${PROJECT_SOURCE_DIR}/tools/linuxdeploy-x86_64.AppImage)
endif ()
endif ()
endmacro()

macro(init_env)
if (UNIX AND NOT APPLE)
set(LINUX TRUE)
endif ()
endmacro()

macro(exec_conan)
if (NOT EXISTS conanbuildinfo.cmake)
message("Conan need to be executed")
execute_process(COMMAND conan install ../
RESULT_VARIABLE CMD_ERROR
OUTPUT_FILE CMD_OUTPUT)
MESSAGE( STATUS "CMD_ERROR:" ${CMD_ERROR})
MESSAGE( STATUS "CMD_OUTPUT:" ${CMD_OUTPUT})
else ()
message("Conan doesn't need to be executed")
endif ()
endmacro()

macro(init_nephtys)
init_env()
exec_conan()
download_app_image()
endmacro()
3 changes: 3 additions & 0 deletions scripts/clean_build_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

rm -rf tools cmake-build-* appimage_build deploy_linux
4 changes: 1 addition & 3 deletions scripts/deploy_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function init() {
function deploy_client() {
cd client
make nephtys_client -j2
make install DESTDIR=AppDir
linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage
cp ./*.AppImage ${root_dir}/deploy_linux/nephtys_client.AppImage
cp ./bin/*.AppImage ${root_dir}/deploy_linux/nephtys_client.AppImage
cd ../
}

Expand Down

0 comments on commit 74bb3a7

Please sign in to comment.