Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] cmake 対応の実験 #46

Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.patch
/build
Backup
*.iobj
*.ipdb
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.6.4)

project (SakuraEditor)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_subdirectory(MakefileMake)
add_subdirectory(HeaderMake)
add_subdirectory(sakura_core)
add_subdirectory(sakura_lang_en_US)
13 changes: 13 additions & 0 deletions HeaderMake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.6.4)

# define a variable of project name
set( project_name HeaderMake)

# define a project name
project (${project_name})

# define a variable SOURCE_FILES with file GLOB
file(GLOB SOURCE_FILES *.cpp *.h)

# define sources files of an executable
add_executable(${project_name} ${SOURCE_FILES})
13 changes: 13 additions & 0 deletions MakefileMake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.6.4)

# define a variable of project name
set( project_name MakefileMake)

# define a project name
project (${project_name})

# define a variable SOURCE_FILES with file GLOB
file(GLOB SOURCE_FILES *.cpp *.h)

# define sources files of an executable
add_executable(${project_name} ${SOURCE_FILES})
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ build_script:

echo appveyor_yml

echo call build-by-cmake.bat
call build-by-cmake.bat

artifacts:
- path: sakura\Debug\sakura.exe
- path: sakura\Debug\sakura.pdb
Expand Down
41 changes: 41 additions & 0 deletions build-by-cmake.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
set BUILDDIR=build

cd /d %~dp0
@echo off
for /l %%n in (1,1,10) do (
if exist "%BUILDDIR%" (
rmdir /s /q "%BUILDDIR%"
)
)
@echo on
mkdir "%BUILDDIR%" || exit /b 1
cd "%BUILDDIR%"

set RETCODE=0
if %ERRORLEVEL% equ 0 (
cmake ..
) else (
set RETCODE=1
)

if %ERRORLEVEL% equ 0 (
cmake --build . --config Debug
) else (
set RETCODE=1
)

if %ERRORLEVEL% equ 0 (
cmake --build . --config Release
) else (
set RETCODE=1
)
cd ..

if %ERRORLEVEL% equ 0 (
echo success
set RETCODE=0
) else (
set RETCODE=1
)

exit /b %RETCODE%
55 changes: 55 additions & 0 deletions sakura_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.0.2)

# define a variable of project name
set(project_name sakura)

# define a project name
project (${project_name})

# set the project as the startup project
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${project_name})

# define variables by file GLOB
file(GLOB_RECURSE SOURCE_FILES ./*.cpp)
file(GLOB_RECURSE HEADER_FILES ./*.h)
file(GLOB_RECURSE RESOURCE_FILES ./*.rc)

# define sources files of an executable
add_executable(${project_name} WIN32 ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES})

# configure precompiled header
if(MSVC)
set(PrecompiledSource "StdAfx.cpp")
set(PrecompiledHeader "StdAfx.h")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yu")
set_source_files_properties(${PrecompiledSource} PROPERTIES COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\"")
endif(MSVC)

add_dependencies(${project_name} HeaderMake)

get_target_property(HeaderMake_RUNTIME_OUTPUT_DIRECTORY HeaderMake RUNTIME_OUTPUT_DIRECTORY)
set(update_HeaderMake_BAT ${CMAKE_CURRENT_SOURCE_DIR}/update-HeaderMake.bat)
set(update_HeaderMake_DIR_EXE ${HeaderMake_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(update_HeaderMake_DIR_IN ${CMAKE_CURRENT_SOURCE_DIR})
set(update_HeaderMake_DIR_OUT ${CMAKE_CURRENT_SOURCE_DIR})

# set pre-Build
add_custom_command(
TARGET ${project_name}
PRE_BUILD
COMMAND ${update_HeaderMake_BAT} ${update_HeaderMake_DIR_EXE} ${update_HeaderMake_DIR_IN} ${update_HeaderMake_DIR_OUT}
)

# set pre-Build
add_custom_command(
TARGET ${project_name}
PRE_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/update-gitHash.bat ${CMAKE_CURRENT_SOURCE_DIR}
)

include_directories(./)

# add definition
add_definitions(-DWIN32 -D_WINDOWS -DNOMINMAX -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0501)

target_link_libraries(${project_name} comctl32.lib Imm32.lib mpr.lib imagehlp.lib Shlwapi.lib)
18 changes: 18 additions & 0 deletions sakura_core/update-HeaderMake.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off

set EXEDIR=%1
set INDIR=%2
set OUTDIR=%3

if "%EXEDIR%" == "" (
set EXEDIR=.
)
if "%INDIR%" == "" (
set INDIR=.
)
if "%OUTDIR%" == "" (
set OUTDIR=.
)

%EXEDIR%\HeaderMake -in=%INDIR%\Funccode_x.hsrc -out=%OUTDIR%\Funccode_define.h -mode=define
%EXEDIR%\HeaderMake -in=%INDIR%\Funccode_x.hsrc -out=%OUTDIR%\Funccode_enum.h -mode=enum -enum=EFunctionCode
30 changes: 30 additions & 0 deletions sakura_core/update-gitHash.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@echo off

set OUTDIR=%1

if "%OUTDIR%" == "" (
set OUTDIR=.
)
set GITREV_H=%OUTDIR%\gitrev.h

for /f "usebackq" %%s in (`git show -s --format^=%%H`) do (
set COMMITID=%%s
)
for /f "usebackq" %%s in (`git show -s --format^=%%h`) do (
set SHORT_COMMITID=%%s
)

type nul > %GITREV_H%
if "%COMMITID%" == "" (
type nul >> %GITREV_H%
) else (
echo #define GIT_COMMIT_HASH "%COMMITID%" >> %GITREV_H%
)
if "%SHORT_COMMITID%" == "" (
type nul >> %GITREV_H%
) else (
echo #define GIT_SHORT_COMMIT_HASH "%SHORT_COMMITID%" >> %GITREV_H%
)

ENDLOCAL
rem exit 0
42 changes: 42 additions & 0 deletions sakura_lang_en_US/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 2.6.4)

# define a variable of project name
set(project_name sakura_lang_en_US)

# define a project name
project (${project_name})

include_directories(./)

# define variables by file GLOB
file(GLOB_RECURSE SOURCE_FILES ./*.cpp)
file(GLOB_RECURSE HEADER_FILES ./*.h)
file(GLOB_RECURSE RESOURCE_FILES ./*.rc)

#foreach( srcTemp ${SOURCE_FILES})
# message("SOURCE_FILES = " ${srcTemp})
#endforeach( srcTemp ${SOURCE_FILES})

# define sources files of an executable
add_library(${project_name} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES})

add_dependencies(${project_name} HeaderMake)

get_target_property(HeaderMake_RUNTIME_OUTPUT_DIRECTORY HeaderMake RUNTIME_OUTPUT_DIRECTORY)
set(update_HeaderMake_BAT ${sakura_SOURCE_DIR}/update-HeaderMake.bat)
set(update_HeaderMake_DIR_EXE ${HeaderMake_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(update_HeaderMake_DIR_IN ${sakura_SOURCE_DIR})
set(update_HeaderMake_DIR_OUT ${sakura_SOURCE_DIR})

# set pre-Build
add_custom_command(
TARGET ${project_name}
PRE_BUILD
COMMAND ${update_HeaderMake_BAT} ${update_HeaderMake_DIR_EXE} ${update_HeaderMake_DIR_IN} ${update_HeaderMake_DIR_OUT}
)

# add definition
add_definitions(-DWIN32 -D_WINDOWS -DNOMINMAX -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0501)

# avoid error LNK2001 for "__DllMainCRTStartup@12"
set_target_properties(${project_name} PROPERTIES LINK_FLAGS "/NOENTRY")